Chat / Android
Chat Android v4
Chat Android
Chat
Android
Home
/
Chat
/
Android
/
Message
This is the new Docs for Chat SDK v4 for Android. To see the previous Docs, click here.

Load messages by timestamp or message ID

Using the getMessagesByTimestamp() method or the getMessagesByMessageId() 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.

val params = MessageListParams().apply {
    inclusive = INCLUSIVE
    previousResultSize = PREVIOUS_RESULT_SIZE
    nextResultSize = NEXT_RESULT_SIZE
    reverse = REVERSE
    messageTypeFilter = MESSAGE_TYPE_FILTER
    customType = CUSTOM_TYPE
    // ...
}
channel.getMessagesByTimestamp(TIMESTAMP, params) { messages, e ->
    if (e != null) {
        // Handle error.
    }

    // A list of previous and next messages of a specified timestamp is successfully retrieved.
    // Through the messages parameter of the callback handler,
    // you can access and display the data of each message from the result list that the Sendbird server has passed to the callback method.
}

MessageListParams

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

Property nameTypeDescription

inclusive

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.

reverse

boolean

Determines whether to sort the retrieved messages in reverse order. If set to true, messages are retunred from the most recent to the oldest. (Default: false)

messageTypeFilter

enum

Specifies the message type to filter the messages with the corresponding type. Acceptable values are MessageTypeFilter.ALL, MessageTypeFilter.USER, MessageTypeFilter.FILE, and MessageTypeFilter.ADMIN.

customType

string

Specifies the custom message type to filter the messages with the corresponding custom type.


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.

groupChannel.getMessagesByTimestamp(TIMESTAMP, params) { messages, e ->
    if (e != null) {
        // Handle error.
    }

    // A list of previous and next messages of a specified timestamp is successfully retrieved.
    // Through the messages parameter of the callback handler,
    // you can access and display the data of each message from the result list
    // that the Sendbird server has passed to the callback method.
}

List of parameters

Parameter nameTypeDescription

ts

long

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 getMessagesByMessageId() method and MessageListParams object.

groupChannel.getMessagesByMessageId(MESSAGE_ID, params) { messages, e ->
    if (e != null) {
        // Handle error.
    }

    // A list of previous and next messages of a specified message ID is successfully retrieved.
    // Through the messages parameter of the callback handler,
    // you can access and display the data of each message from the result list
    // that the Sendbird server has passed to the callback method.
}

List of parameters

Parameter nameTypeDescription

messageId

long

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.