TencentImSDKPlugin.v2TIMManager.getMessageManager()
class.getC2CHistoryMessageList
API (Details) to get historical one-to-one messages.
When the network is normal, the latest cloud data will be pulled; when it is abnormal, the SDK will return the locally stored historical messages.
If you want to pull only local historical messages, see Advanced API.// Pull historical one-to-one messages// Set `lastMsgID` to `null` for the first pull// `lastMsgID` can be the ID of the last message in the returned message list for the second pull.const userID = "userID";const count = 10;const lastMsgID = null;TencentImSDKPlugin.v2TIMManager.getMessageManager().getC2CHistoryMessageList(userID, count, lastMsgID);
getGroupHistoryMessageList
API (Details) to get historical group messages.
When the network is normal, the latest cloud data will be pulled; when it is abnormal, the SDK will return the locally stored historical messages.
If you want to pull only local historical messages, see Advanced API.// Pull historical group messages// Set `lastMsgID` to `null` for the first pull// `lastMsgID` can be the ID of the last message in the returned message list for the second pull.const groupID = "userID";const count = 10;const lastMsgID = null;TencentImSDKPlugin.v2TIMManager.getMessageManager().getGroupHistoryMessageList(groupID, count, lastMsgID);
getHistoryMessageList
(Details).public getHistoryMessageList(count: number,getType = HistoryMsgGetTypeEnum.V2TIM_GET_LOCAL_OLDER_MSG,userID?: string,groupID?: string,lastMsgSeq = -1,lastMsgID?: string,messageTypeList?: number[]): V2TimValueCallback<V2TimMessage[]>
Parameter | Description | Valid for One-to-One Chat | Valid for Group Chat | Required | Remarks |
getType | Source and sequence of the message pull, which can be set to local/cloud and reverse chronological order/chronological order respectively. | YES | YES | YES | When the pull source is set to the cloud, the local message list and cloud message list will be merged and returned. If there is no network connection, the local message list will be returned. |
userID | The specified user ID with which to pull historical one-to-one messages | YES | NO | NO | To pull one-to-one messages, you need to specify only the userID . |
groupID | The specified group ID with which to pull historical group messages | NO | YES | NO | To pull group messages, you need to specify only the groupID . |
count | Number of messages per pull | YES | YES | YES | We recommend you set it to 20 ; otherwise, the pull speed may be affected. |
lastMsgID | ID of the last message, indicating the message starting from which to pull historical messages | YES | YES | NO | 1. It can be used for both one-to-one and group chats. 2. If it is set as the start point for the message pull, the message will not be included in the returned message list. 3. If it is left empty, the latest message in the conversation will be used as the start point for pull. |
lastMsgSeq | seq of the last message, indicating the message starting from which to pull historical messages | NO | YES | NO | 1. It can be used only for group chats. 2. If it is set as the start point for the message pull, the message will be included in the returned message list. 3. If both lastMsg and lastMsgSeq are specified, the SDK will use lastMsg. 4. If neither lastMsg nor lastMsgSeq is specified, the start point for pull will be determined based on whether the getTimeBegin is set. If yes, the set range will be used as the start point; if no, the latest message will be used as the start point. |
lastMsg
and count
.lastMsg
and count
. For the first pull, lastMsg
can be left empty, which indicates that the last message in the returned message list will be used as the lastMsg
to pull data of the next page.lastMsg
is left empty, the SDK will return historical messages starting from the latest message by default.lastMsg
is set, it is not included in the returned message list.count
to 20
for pagination.lastMsgSeq
for the subsequent pull, as the corresponding message will be included in the returned message list.getType
to pull only local messages:getType
is set to V2TIM_GET_LOCAL_OLDER_MSG
, locally stored messages will be pulled in reverse chronological order.getType
is set to V2TIM_GET_LOCAL_NEWER_MSG
, locally stored messages will be pulled in chronological order.const count = 10;const getType = HistoryMsgGetTypeEnum.V2TIM_GET_LOCAL_OLDER_MSG;const userID = "userID";TencentImSDKPlugin.v2TIMManager.getMessageManager().getHistoryMessageList(count, getType, userID);
sequence
as the lastMsgSeq
and use the advanced API to pull messages.// Get the `sequence` of the group @ messageconst atSequence = 1081;// Pull the group @ message and earlier messagesconst count = 20;const getType = HistoryMsgGetTypeEnum.V2TIM_GET_LOCAL_OLDER_MSG;const lastMsgSeq = atSequence;const userID = "";const groupID = "groupID";TencentImSDKPlugin.v2TIMManager.getMessageManager().getHistoryMessageList(count, // Pull 20 messagesgetType, // Pull messages earlier than the group @ messageuserID,groupID // Pull group messageslastMsgSeq,// Start the pull from the group @ message, which is included in the pull list);// Pull messages later than the group @ messageTencentImSDKPlugin.v2TIMManager.getMessageManager().getHistoryMessageList(count, // Pull 20 messagesHistoryMsgGetTypeEnum.V2TIM_GET_CLOUD_NEWER_MSG, // Pull messages later than the group @ messageuserID,groupID // Pull group messageslastMsgSeq,// Start the pull from the group @ message, which is included in the pull list);
getType
is set to pull cloud historical messages and the number of messages to be pulled is set to x
, the SDK will pull x
messages from the cloud.onlineUserOnly
to YES/true
when sending messages.getType
is set to pull cloud historical messages and the number of messages is count
, the SDK will perform the following operations:count
messages from the local database.count
messages from the cloud and filter out invalid messages such as deleted messages. If the number is smaller than count
, the paged pull will be triggered.count
messages from the merged message list.count
). If the issue persists, contact us for assistance.
Was this page helpful?