Chat / Flutter
Current version: v3
Chat Flutter v3
Chat Flutter
Chat
Flutter
Home
/
Chat
/
Flutter
/
Message

Load messages by timestamp or message ID

Using the getMessagesByTimestamp() method or the getMessagesById() method, you can retrieve a set number of previous and next messages of a specific timestamp or a message ID in a channel.

The following code shows several types of parameters that you can configure to customize a message query by using MessageListParams. Under the MessageListParams object, you can assign values to properties such as previousResultSize, messageTypeFilter, and customType.

final params = MessageListParams()
    ..isInclusive = true
    ..previousResultSize = 10
    ..nextResultSize = 0;

  var result = await channel.getMessagesByTimestamp(
    ExtendedInteger.max,
    params,
  );

// A list of previous and next messages of a specified timestamp is successfully retrieved.

MessageListParams

This table only contains properties shown in the code above. See the API reference for a complete list of properties.

Property nameTypeDescription

isInclusive

boolean

Determines whether to include messages sent exactly on the specified timestamp or have the matching message ID.

previousResultSize

int

Specifies the number of messages to retrieve, which are sent previously before a specified timestamp. Note that the actual number of results may be larger than the set value when there are multiple messages with the same timestamp as the earliest message.

nextResultSize

int

Specifies the number of messages to retrieve, which are sent later after a specified timestamp. Note that the actual number of results may be larger than the set value when there are multiple messages with the same timestamp as the latest message.


By timestamp

To retrieve messages in a channel, you need to pass the MessageListParams object as an argument to the parameter in the getMessagesByTimestamp() method.

var result = await channel.getMessagesByTimestamp(
    ExtendedInteger.max,
    params,
  );

// A list of previous and next messages of a specified timestamp is successfully retrieved.

List of parameters

Parameter nameTypeDescription

timestamp

int

Specifies the unique ID of the message to be the reference point of a retrieval.

params

MessageListParams

Contains a set of parameters you can use when retrieving messages.


By message ID

To retrieve a set number of previous and next messages of a specific message ID in a channel, use the getMessagesById() method and MessageListParams object.

final result = await channel.getMessagesById(msgId, params);

// A list of previous and next messages of a specified message ID is successfully retrieved.
}

List of parameters

Parameter nameTypeDescription

messageId

int

Specifies the unique ID of the message to be the reference point of a retrieval.

params

MessageListParams

Contains a set of parameters you can use when retrieving messages.