Message history
Chat SDK lets you fetch historical messages from one channel using the getHistory()
method.
Due to current PubNub API limitations, you cannot filter the results by type, so you'll get all messages that happened on a given channel in a given timeframe.
Method signature
This method takes the following parameters:
channel.getHistory(
startTimetoken: Long?,
endTimetoken: Long?,
count: Int = 25
): PNFuture<HistoryResponse<*>>
Input
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
startTimetoken | Long | No | n/a | Timetoken delimiting the start of a time slice (exclusive) to pull messages from. For details, refer to the History section. |
endTimetoken | Long | No | n/a | Timetoken delimiting the end of a time slice (inclusive) to pull messages from. For details, refer to the History section. |
count | Int | No | 25 | Number of historical messages to return for the channel in a single call. Since each call returns all attached message reactions by default this value is '25'. The maximum allowed value is 25 . For more details, refer to the description of the includeMessageActions parameter in the Kotlin SDK docs. |
Output
Type | Description |
---|---|
PNFuture<HistoryResponse<*>> | PNFuture containing a list of messages with pagination information (isMore: Boolean ). |
By default, each call returns all message reactions and metadata attached to the retrieved messages.
Basic usage
From the support
channel, fetch 10
historical messages older than the timetoken 15343325214676133
.
val timetoken: Long = 15343325214676133
val messageCount: Int = 10
chat.getChannel("support").async { supportResult ->
supportResult.onSuccess { supportChannel ->
// handle success
supportChannel.getHistory(endTimetoken = timetoken, count = messageCount).async { historyResult ->
historyResult.onSuccess { history ->
// handle success
}.onFailure {
// handle failure
}
}
}.onFailure {
// handle failure
show all 17 lines