Problem summary:
1. Sent messages are not showing in the chatbox / message thread page.
2. The receiver is not getting the sent messages until he/she refreshed the page.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

geraldvillorente created an issue. See original summary.

stoickthevast’s picture

Noticed that even in the demo site the message is not showing as well after sending.

kopeboy’s picture

Title: Sent messages are not showing in the chatbox » Sent messages are not showing in the chatbox without a new page request

Yeah, just tested, you need at least a page request.

Hardik Rawal’s picture

Any resolution for this ?

monstrfolk’s picture

FileSize
4.64 KB

Patch for the message list to update after sending a message. This does not work in the mini chat box yet. This patch is for 7.2.x-dev. Might work on the other branches.

monstrfolk’s picture

Title: Sent messages are not showing in the chatbox without a new page request » Sent messages are not appearing in message list after submit
Issue summary: View changes
monstrfolk’s picture

Issue summary: View changes
monstrfolk’s picture

Status: Needs work » Needs review
Oscartt’s picture

I have sort of figured out what the problem is atleast in 7x.1x.dev. For me the messages were not showing up in the minichat while I was on any other than the message thread page.

function privatemsg_nodejs_privatemsg_view_alter(&$content) {
    nodejs_send_content_channel_token('privatemsg_nodejs_thread_' . $content['#thread']['thread_id']);
    nodejs_send_content_channel_token('privatemsg_nodejs_status_' . $content['#thread']['thread_id']);
}

That's where the channels are "opened" in order for the minichat to work. As you can see, that hook is only fired when viewing the thread page. Thus, the channels are never opened on any other page even if the minichat is open and no messages can be received.

A partial fix is to put this after line 28 on privatemsg_nodejs.module:

// Open channels for privatemsg to work on pages other than thread page.
      foreach ($_SESSION['privatemsg_nodejs']['mini_chats'] as $thread => $thread_id) {
        nodejs_send_content_channel_token('privatemsg_nodejs_thread_' . $thread_id['thread_id']);

        // Open channels for statuses.
        if (variable_get('privatemsg_nodejs_message_status', TRUE)) {
          nodejs_send_content_channel_token('privatemsg_nodejs_status_' . $thread_id['thread_id']);
        }
      }

That does the trick, but there's a catch. If you receive a message let's say on the frontpage and click open mini chat on the alert, that code still isn't fired and you won't see the messages you type in. Only after you open the minichat and refresh the page, that code opens the channels and everything works nicely as long as you keep the minichat open while browsing the site.

To work around that catch and make the minichat somewhat usable, I removed the "Open minichat" link from the alert, so it can only be opened from the thread page. This way, if you go to the thread and click open minichat, the channels are already opened by the "privatemsg_nodejs_privatemsg_view_alter" and will continue to stay open due to the added foreach if you navigate elsewhere with the minichat open.

So the real fix to make this work 100% is to somehow send the channel tokens from the javascript when the minichat is opened. I tried for 2 days to get that to work, but I don't really undertand javascript and nodejs enough to make it happen. I think it should be fairly simple if one knew what they were doing.