1、清除歷史消息凛澎。在清除歷史消息成功的回調(diào)中霹肝,刪除會(huì)話,并且給該會(huì)話發(fā)一條不存儲(chǔ)不計(jì)數(shù)的命令消息塑煎,作用是表示該會(huì)話歷史消息已經(jīng)被清除沫换。
截屏2021-09-07 下午2.34.34.png
//代碼示例:
// 清除歷史消息
[[RCIMClient sharedRCIMClient] clearHistoryMessages:**self**.conversationType targetId:**self**.targetId recordTime:0 clearRemote:**YES** success:^{
NSLog(@"++++ 清除歷史消息成功");
NSLog(@"++++ 刪除會(huì)話");
[[RCIMClient sharedRCIMClient] removeConversation:**self**.conversationType targetId:**self**.targetId];
// 發(fā)送刪除消息和會(huì)話命令,name和data您自己定義
RCCommandMessage *message = [[RCCommandMessage alloc] init];
message.name = @"刪除";
message.data = [NSString stringWithFormat:@"%ld", **self**.conversationType];
**if** (**self**.conversationType == ConversationType_SYSTEM) {
NSLog(@"++++ 系統(tǒng)會(huì)話最铁,刪除命令發(fā)單聊消息");
[[RCIM sharedRCIM] sendMessage:ConversationType_PRIVATE targetId:**self**.targetId content:message pushContent:**nil** pushData:**nil** success:^(**long** messageId) {
NSLog(@"++++ 刪除命令發(fā)送成功");
} error:^(RCErrorCode nErrorCode, **long** messageId) {
NSLog(@"++++ 刪除命令發(fā)送失敗 %ld", nErrorCode);
}];
} **else** {
[**self** sendMessage:message pushContent:**nil**];
}
} error:^(RCErrorCode status) {
NSLog(@"++++ 清除歷史消息失敗 %ld", status);
}];
2讯赏、(可選)該會(huì)話有新消息產(chǎn)生。
3冷尉、卸載重裝應(yīng)用
4漱挎、觸發(fā)“消息補(bǔ)償”機(jī)制,除了收到之前刪除過(guò)的消息雀哨,還會(huì)收到刪除的命令消息和刪除后的新消息磕谅。
5、在消息接收監(jiān)聽(tīng)中實(shí)現(xiàn)下面邏輯雾棺。
截屏2021-09-07 下午2.35.44.png
截屏2021-09-07 下午2.36.56.png
//代碼示例:
-
(void)onRCIMReceiveMessage:(RCMessage )message left:(int*)left {
if ([message.content isKindOfClass:[RCCommandMessage class]]) {
RCCommandMessage *msg = (RCCommandMessage *)message.content; // 判斷是否是自己發(fā)出的刪除命令 if ([msg.name isEqualToString:@"刪除"] && message.messageDirection == MessageDirection_SEND) { RCConversationType type = msg.data.integerValue; // 接收到我發(fā)送的刪除命令 // 獲取該會(huì)話的最新一條消息 NSArray *array = [[RCIMClient sharedRCIMClient] getHistoryMessages:type targetId:message.targetId oldestMessageId:-1 count:1]; **if** (array.count > 0) { // 該會(huì)話有消息 RCMessage *latestMsg = (RCMessage *)array[0]; **if** (latestMsg.sentTime > message.sentTime) { // 最新一條消息的sentTime 大于 刪除命令的sentTime 怜庸,說(shuō)明用戶在清除歷史消息后該會(huì)話又有新消息。 // 此時(shí)只刪除 命令消息 之前的消息垢村,不刪除會(huì)話。 [[RCIMClient sharedRCIMClient] clearHistoryMessages:type targetId:message.targetId recordTime:message.sentTime clearRemote:**NO** success:^{ NSLog(@"++++ 收到刪除命令后清除成功"); } error:^(RCErrorCode status) { NSLog(@"++++ 收到刪除命令后清除失敗%ld", status); }]; // 根據(jù)時(shí)間戳清除之前的未讀數(shù)嚎卫。 [[RCIMClient sharedRCIMClient] clearMessagesUnreadStatus:type targetId:message.targetId time:message.sentTime]; } **else** { // 該用戶清除歷史消息后沒(méi)有新消息 // 刪除命令消息之前的消息嘉栓,并且刪除該會(huì)話 [[RCIMClient sharedRCIMClient] clearHistoryMessages:type targetId:message.targetId recordTime:message.sentTime clearRemote:**NO** success:^{ NSLog(@"++++ 收到刪除命令后清除成功"); } error:^(RCErrorCode status) { NSLog(@"++++ 收到刪除命令后清除失敗%ld", status); }]; [[RCIMClient sharedRCIMClient] removeConversation:type targetId:message.targetId]; } } **else** { // 無(wú)消息、無(wú)會(huì)話拓诸,不需要操作 } }
}
}
2021年5月27日 16:05版本