外观
获取消息列表
约 406 字大约 1 分钟
2025-03-25
1. 描述
getMessageList()
获取消息列表,该方法为异步函数
,会返回一个Promise
对象,通过该对象可以获取消息列表。
2. 参数
参数名称 | 是否必选 | 类型 | 说明 |
---|---|---|---|
conversationType | 是 | TYPE | CONVERSATION_TYPE.GROUP 或 CONVERSATION_TYPE.SINGLE |
conversationId | 是 | String | 会话ID |
nextMessageId | 否 | Number | 下一次请求的消息ID,首页的时候传递``,即空字符串 |
3. 返回值
返回Promise
对象,成功时resolve
回调函数的参数为消息列表,失败时reject
回调函数的参数为错误信息。
群聊和单聊公共字段如下:
字段 | 类型 | 说明 |
---|---|---|
list | Array | 消息列表数组,数组元素为消息对象,格式如下 |
nextMessageId | Number | 下一次请求的消息ID,如果没有更多消息,则为NULL |
3.1 群聊list元素
字段 | 类型 | 说明 |
---|---|---|
id | Number | 消息ID |
groupId | String | 群聊ID |
type | String | 消息类型,详见消息类型 |
senderId | String | 发送者ID |
senderName | String | 发送者名称 |
senderAvatar | String | 发送者头像 |
content | String | 加密后的消息对象字符串 |
conversationId | String | 会话ID,即群聊ID |
conversationType | String | 会话类型,固定为group |
3.2 单聊list元素
字段 | 类型 | 说明 |
---|---|---|
id | Number | 消息ID |
senderId | String | 发送者ID |
senderName | String | 发送者名称 |
senderAvatar | String | 发送者头像 |
receiverId | String | 接收者ID |
receiverName | String | 接收者名称 |
receiverAvatar | String | 接收者头像 |
content | String | 消息对象字符串 |
conversationId | String | 会话ID,即群聊ID |
conversationType | String | 会话类型,固定为single |
4. 示例代码
XBCIM.getMessageList({
conversationType: XBCIM.CONVERSATION_TYPE.GROUP,
conversationId: 'group_id',
nextMessageId: null
}).then((list) => {
console.log('消息列表获取成功', list);
}).catch((error) => {
console.error(error);
});