更新时间: 2020-08-26
# 本地删除
# 通过消息 ID 删除
通过消息 Id 删除本地一条或一组消息
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
messageIds | int[] | 是 | 发送消息的 ID 数组 |
callback | IRongCallback.ResultCallback<Boolean> | 是 | 接口回调 |
代码示例
删除一条消息示例
int[] messageIds = {12} RongIMClient.getInstance().deleteMessages(messageIds, new RongIMClient.ResultCallback<Boolean>() { /** * 删除消息成功回调 */ @Override public void onSuccess(Boolean bool) { } /** * 删除消息失败回调 * @param errorCode 错误码 */ @Override public void onError(RongIMClient.ErrorCode errorCode) { } });
已复制
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
删除一组消息示例
int[] messageIds = {12, 13} RongIMClient.getInstance().deleteMessages(messageIds, new RongIMClient.ResultCallback<Boolean>() { /** * 删除消息成功回调 */ @Override public void onSuccess(Boolean bool) { } /** * 删除消息失败回调 * @param errorCode 错误码 */ @Override public void onError(RongIMClient.ErrorCode errorCode) { } });
已复制
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 通过时间戳删除
通过时间戳删除指定会话的聊天消息
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
conversationType | ConversationType (opens new window) | 是 | 会话类型. 当前为 ConversationType.PRIVATE |
targetId | String | 是 | 接收方的 userId |
recordTime | long | 是 | 时间戳. 1. 传 0 清除所有消息 2. 非 0 则清除小于等于 recordTime 的消息 |
cleanRemote | boolean | 是 | 是否删除服务器端消息. true 删除, false 不删除 |
callback | OperationCallback | 是 | 接口回调 |
代码示例
ConversationType conversationType = ConversationType.PRIVATE; String targetId = "接收方的 userId"; String recordTime = 0; RongIMClient.getInstance().cleanHistoryMessages(conversationType, targetId, recordTime, false, new RongIMClient.OperationCallback() { /** * 删除消息成功回调 */ @Override public void onSuccess() { } /** * 删除消息失败回调 * @param errorCode 错误码 */ @Override public void onError(RongIMClient.ErrorCode errorCode) { } });
已复制
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 通过会话删除
删除指定会话中数据库的所有消息
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
conversationType | ConversationType (opens new window) | 是 | 会话类型. 当前为 ConversationType.PRIVATE |
targetId | String | 是 | 接收方的 userId |
callback | IRongCallback.ResultCallback<Boolean> | 是 | 接口回调 |
代码示例
ConversationType conversationType = ConversationType.PRIVATE; String targetId = "接收方的 userId"; RongIMClient.getInstance().deleteMessages(conversationType, targetId, new RongIMClient.ResultCallback<Boolean>() { /** * 删除消息成功回调 */ @Override public void onSuccess(Boolean bool) { } /** * 删除消息失败回调 * @param errorCode 错误码 */ @Override public void onError(RongIMClient.ErrorCode errorCode) { } });
已复制
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 远端删除
# 通过会话删除
删除指定会话类型的目标 ID 的一条或者一组消息(服务器端),会同时删除本地和远端消息。
参数说明
参数 | 类型 | 必填 | 说明 | 最低版本 |
---|---|---|---|---|
conversationType | ConversationType (opens new window) | 是 | 会话类型. 当前为 ConversationType.PRIVATE | |
targetId | String | 是 | 接收方的 userId | |
messages | Message[] | 是 | 要删除的消息数组 | |
callback | IRongCallback.ResultCallback<Boolean> | 是 | 接口回调 |
代码示例
ConversationType conversationType = ConversationType.PRIVATE String targetId = "接收方的 userId"; Message[] messages = {message1, message2} RongIMClient.getInstance().deleteRemoteMessages(conversationType, targetId, messages, new RongIMClient.OperationCallback() { /** * 删除消息成功回调 */ @Override public void onSuccess() { } /** * 删除消息失败回调 * @param errorCode 错误码 */ @Override public void onError(RongIMClient.ErrorCode errorCode) { } });
已复制
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 通过时间戳删除
通过时间戳删除指定会话,该时间之前的服务端历史消息,如需要同时删除本地消息需要再调用本地消息删除接口。
须先开通历史消息云存储功能
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
conversationType | ConversationType (opens new window) | 是 | 会话类型. 当前为 ConversationType.PRIVATE |
targetId | String | 是 | 接收方的 userId |
recordTime | long | 是 | 时间戳. 1. 传 0 清除所有消息 2. 非 0 则清除小于等于 recordTime 的消息 |
callback | OperationCallback | 是 | 接口回调 |
代码示例
ConversationType conversationType = ConversationType.PRIVATE String targetId = "接收方的 userId"; String recordTime = 0; RongIMClient.getInstance().cleanRemoteHistoryMessages(conversationType, targetId, recordTime, new RongIMClient.OperationCallback() { /** * 删除消息成功回调 */ @Override public void onSuccess() { } /** * 删除消息失败回调 * @param errorCode 错误码 */ @Override public void onError(RongIMClient.ErrorCode errorCode) { } });
已复制
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22