When does the 'latestMessage' attribute on the GroupChannel Object update?

Using the sendbird Javascript API I’m struggling to understand how to listen for or expect the GroupChannel objects ‘lastestMessage’ to change as I send messages to the groupChannel chat.

I’ve tried to read through the long list of handlers I can register but it none of them seems to address the LastMessage attribute on the groupChannel object.

Hi Kwonder

I’m sorry to hear you are having a hard time. Please note that with the channel handlers to listen for message please use onMessageRecieved() this will always be triggered when a new message arrives. Including for the last message that was added to a channel. It is not possible to listen specifically for the last message on a channel, however the lastest message that came in via the onMessageRecieved() will be the same as the lastMessage on the channel.

Please explain your use case further if what I mention doesn’t clarify your case. :slight_smile:

1 Like

For the incoming messages, the onMessageRecieved() works well.
The scenario I’m struggling with is when I (the user) is the one sending the message. I.e.

  • User types and send off message M in group channel A
  • myChannelA.sendUserMessage(msg, (userMessage, error) => {…})
  • If successful, at what time does the myChannelA.lastMessage === myMessageM
1 Like

@Supertopoz Any ideas the scenario I describe?

@kwonder myChannelA.lastMessage === myMessageM the moment that the message arrives in sendbird’s servers and has the condition of being the last message, which may be a fleeting moment if there are other messages also coming in.

If you can explain what you are trying to do with the channel’s last message I might be able to suggest a solution.

My list of groupchannels include the text from the latest message, but since the message is still n-1 at the time of the success callback I can’t trigger the update there. And there is no consecutive invocation of any handler that seems to tell me when the lastmessage is updated so short of setInterval() and polling the groupChannelA.lastMessage I don’t understand how Im supposed to solve this.

Right, I see what you need now.

We account for the case you mention automatically. It is mentioned in the sendbird docs.

“When a user is online, all data associated with the group channels they are a member of are automatically updated. However, when a user is disconnected from Sendbird server and reconnects later, you should call the refresh() method to update the user’s group channels with the latest information.”