• Hello,

    How to load a thread only by id ?
    Or how to load the whole bm using javascript (Lets supose I have the html strucure) ?

    I tried to read the code, the only thing I found is jQuery(document).on(“bp-better-messages-init-scrollers”). Which somehow reinit the bm.

    What I want to achive is trough rest api endpoint the user will get a thread_id, that will load the BM.

    Tried to echo the shordcode in the rest_api, but ofc it will echo only html strucute without content, the content is updated by javascript.

    This works, but ofc only in php do_shortcode(‘[better_messages_single_conversation thread_id=”8″]’)

    The code is a whole book, can’t seem to find by watchin in source tabs.

    Thank you.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author wordplus

    (@wordplus)

    Hi there!

    Which html code do you have? So I have understanding

    Thread Starter razvanfrandes

    (@razvanfrandes)

    Hey ??

    Thank you for the quick response.

    In this gist you will find the html.

    https://gist.github.com/razvanFrandes/fcfbf302809101b71ec2cdc828349515

    The html is outputed, by the rest api.

    Plugin Author wordplus

    (@wordplus)

    Did you tried this?

    jQuery(document).trigger(“bp-better-messages-init-scrollers”);

    Thread Starter razvanfrandes

    (@razvanfrandes)

    Dam…

    It was having in my response converted to response.text ??

    This code works

    Thank you for your time, awesome plugin! Waiting for vanila/react version ??
    (I know it;s build with react/redux to bad we can’t hook into many things)

    function updateShortcode(thread_id) {
    
      fetch("/api/update_bm", {
    
        method: "POST",
    
        headers: {
    
          "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    
        },
    
        body: new URLSearchParams({ thread_id: thread_id }),
    
      })
    
        .then((response) => response.json())
    
        .then((html) => {
    
          const container = document.querySelector("#shortcode-container");
    
          container.innerHTML = html;
    
          console.log(html);
    
          jQuery(document).trigger("bp-better-messages-init-scrollers");
    
        })
    
        .catch((error) => {
    
          console.error("Error updating shortcode:", error);
    
        });
    
    }
    
    document.querySelector("#messages").addEventListener("click", function () {
    
      var id = 10;
    
      updateShortcode(id);
    
    });
    • This reply was modified 1 year, 10 months ago by razvanfrandes.
    Plugin Author wordplus

    (@wordplus)

    Hi there!

    Redux is not used here, if you need hooks, feel free to requests them.

    Thread Starter razvanfrandes

    (@razvanfrandes)

    Thank you!

    For example I have 2 situations.

    1. How can I hook into when a new message is read?
    2. How to edit the email template, I need custom templating with php.

    Thank you again.
    Much apreciated!

    Plugin Author wordplus

    (@wordplus)

    Thread Starter razvanfrandes

    (@razvanfrandes)

    Hello ??

    1. For example if I send a message to you. That message status is unread until you view it. When you view the message I need to hook into it, for example when you view my message a email is sent to me that you have read my message.

    Thank you ??

    Plugin Author wordplus

    (@wordplus)

    WebSocket or AJAX?

    Thread Starter razvanfrandes

    (@razvanfrandes)

    Sorry for my late response.
    I am using ajax.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Initialize BM with Javascript’ is closed to new replies.