更新时间: 2021-03-08
# 功能描述
聊天消息保存在云端,用户进入聊天室后,可以查看聊天室中以前的消息,历史消息默认保存 2 个月。必须在 IM 商用版
- 增值服务
中开通 聊天室消息云存储 (opens new window)功能。
# 参数说明
输入参数说明
回调参数说明
参数 | 类型 | 说明 |
---|---|---|
list | Array | 获取的历史消息列表,返回 message 列表 |
hasMore | Bool | 是否还有历史消息可以获取 |
message 属性说明
字段名 | 类型 | 说明 |
---|---|---|
type | Number | 会话类型 |
targetId | String | 接收方的 userId |
senderUserId | String | 发送者 id |
content | Object | 消息内容 |
messageType | String | 消息标识 |
messageUId | String | 服务端存储的消息 id |
messageDirection | Number | 消息方向。 发送: 1, 接收: 2 |
isOffLineMessage | Boolean | 是否为离线消息 |
sentTime | Number | 消息在融云服务端的发送时间 |
receivedTime | Number | 消息接收时间. isOffLineMessage 为 true 时, receivedTime 无效 |
isPersited | Boolean | 消息是否存储在服务端 |
isCounted | Boolean | 消息是否计数 |
# 代码示例
var chatRoom = im.ChatRoom.get({ id: 'chatRoom1' }); var option = { timestrap: +new Date(), count: 20 }; chatRoom.getMessages(option).then(function(result){ var list = result.list; // 历史消息列表 var hasMore = result.hasMore; // 是否还有历史消息可以获取 console.log('获取聊天室历史消息成功', list, hasMore); });
已复制
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12