MessageCollection instance allows you to swiftly create a chat view that includes all data. This page explains how to make a view using the collection.
Create a collection
First, create a
MessageCollection instance. Here, you need to set a
MessageListParams instance to determine the message order and the starting point of the message list in the chat view.
The reference point for message retrieval in a chat view is
startingPoint. This should be specified as a timestamp.
startingPoint is set to
double.maxFinite.toInt(), displaying the most recent messages first. However, if the
startingPoint is set to the message last read by the user, it will display messages from where the user last read.
After creating a
MessageCollection instance, initialize the instance through the
loadNext() methods to retrieve messages from the previous page and the next page.
loadPrevious() method is called, the Chat SDK first checks whether there're messages to load from the previous page through
hasPrevious. The same goes for
These methods have to be called during initialization as well.
MessageCollectionHandler to determine how the client app reacts to message-related events.
The following table shows possible cases where each event handler can be called.
- A new message is created as a real-time event.
- A message is updated as a real-time event.
- The channel information that is included in the user's current chat view is updated as a real-time event.
- The current channel is deleted as a real-time event.
- A huge gap is detected through background sync. In this case, you need to dispose of the view and create a new
A gap can be created for many reasons, such as when a user has been offline for days. When the client app comes back online, the Chat SDK checks with the Sendbird server to see if there are any new messages. If it detects that more than 300 messages are missing in the local cache compared to the Sendbird server, the SDK determines that there is a huge gap and
onHugeGapDetected() is called.
Note: To adjust the number of missing messages that result in a call for
onHugeGapDetected(), contact our support team.
In this case, the existing
MessageCollection instance should be cleared through the
dispose() method and a new one must be created for better performance.
Dispose of the collection
dispose() method should be called when you need to clear the current chat view. For example, this can be used when the current user leaves the channel.