How do I get messages that were sent to an offline user?

When a user is sent a message while they are offline those messages are not pushed to them when they come back online and join the group channel where the messages were sent.

How do I get the messages that were sent to a user in a group channel while they were offline so that they can be displayed to the user when they come back online?

Hello, @peter,

You need to load the messages initially using the previous message list query to fetch the messages in the channel. After you load the messages, you would then implement the onMessageReceived() event handler to receive messages to the channel while the user is online.

Hi @Ian and thanks for the reply. I have actually just done exactly that, and it seems to be working great! The only question I have, that I might actually know the answer for already, is how do you know how many messages the user missed while they were offline so that you can add that as the limit parameter? What I was about to look into as a solution for this is


but I haven’t tested it yet and wonder if there is something I need to do to mark the messages as read when they are received in order for this to work. Thanks again for your guidance.

To provide some additional context on my question. I am maintaining a local message cache on device so that I don’t have to make a server request every time a user opens a chat window and also so they are able to view their message history when they are offline. I’m loading the message history from this cache initially and then want to update it with missed messages only when the user comes back online.

Hey @peter, you could use the message ID of the last message the user received in the channel to fetch the messages you want using the next limit.

Perfect! Thank you @Ian :ok_hand:

1 Like

No problem, @peter! Always happy to help.