Retrieve message history
The default Chat UI channel page implements historical message loading and display. For custom pages, use the nexconn message query APIs directly.
Recommended APIs
BaseChannel.createMessagesQuery(MessagesQueryParams): Load historical messages with pagination (automatically fills gaps from remote)BaseChannel.createLocalMessagesByTimeQuery(LocalMessagesByTimeQueryParams): Query local historical messages by time cursorBaseChannel instance.getMessagesAroundTime(GetMessagesAroundTimeParams, ...): Query messages around a specific message timestamp
Example
- Kotlin
- Java
kotlin
val identifier = ChannelIdentifier(ChannelType.DIRECT, "user_001")
val query = BaseChannel.createMessagesQuery(
MessagesQueryParams(identifier).apply {
pageSize = 30
isAscending = false
}
)
query.loadNextPage { page, error ->
if (error == null) {
val messages = page?.data.orEmpty()
// Render historical messages
}
}
Java
ChannelIdentifier identifier = new ChannelIdentifier(ChannelType.DIRECT, "user_001");
MessagesQueryParams params = new MessagesQueryParams(identifier);
params.setPageSize(30);
params.setAscending(false);
MessagesQuery query = BaseChannel.createMessagesQuery(params);
query.loadNextPage((page, error) -> {
if (error == null) {
List<Message> messages = page != null ? page.getData() : Collections.emptyList();
// Render historical messages
}
});