差别
这里会显示出您选择的修订版和当前版本之间的差别。
两侧同时换到之前的修订记录 前一修订版 后一修订版 | 前一修订版 | ||
im:other:integrationcases:snapchat [2021/06/15 06:22] zhangdong [发送阅后即焚消息] |
im:other:integrationcases:snapchat [2023/05/15 09:46] victorli [iOS示例] |
||
---|---|---|---|
行 43: | 行 43: | ||
NSDictionary *ext = @{FIRE_FLAG:@YES}; | NSDictionary *ext = @{FIRE_FLAG:@YES}; | ||
NSString *currentUsername = [EMClient sharedClient].currentUsername; // 当前登录环信id | NSString *currentUsername = [EMClient sharedClient].currentUsername; // 当前登录环信id | ||
- | EMMessage *msg = [[EMMessage alloc] initWithConversationID:toUsername | + | EMChatMessage *msg = [[EMChatMessage alloc] initWithConversationID:toUsername |
from:currentUsername | from:currentUsername | ||
to:toUsername | to:toUsername | ||
行 114: | 行 114: | ||
// 当用户已经读取过消息后,删除消息并发送已读回执 | // 当用户已经读取过消息后,删除消息并发送已读回执 | ||
- | - (void)fireMessageAndSendAck:(EMMessage *)message { | + | - (void)fireMessageAndSendAck:(EMChatMessage *)message { |
// 发送已读回执 | // 发送已读回执 | ||
[EMClient.sharedClient.chatManager sendMessageReadAck:message completion:nil]; | [EMClient.sharedClient.chatManager sendMessageReadAck:message completion:nil]; | ||
行 123: | 行 123: | ||
</code> | </code> | ||
+ | === web/小程序示例 === | ||
+ | <code> | ||
+ | /** | ||
+ | * 新消息回调 | ||
+ | */ | ||
+ | onTextMessage(message){ | ||
+ | // 判断是否为阅后即焚消息 | ||
+ | if(message.ext.fire){ | ||
+ | // update ui | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // 当用户已经读取过消息后,发送已读回执并删除本地消息 | ||
+ | var msgId = message.id; // 需要发送已读回执的消息id | ||
+ | var msg = new WebIM.message('read', conn.getUniqueId()); // 已读回执消息 | ||
+ | msg.set({ | ||
+ | id: msgId, | ||
+ | to: message.from | ||
+ | }); | ||
+ | conn.send(msg.body); | ||
+ | |||
+ | </code> | ||
===== 消息发送方收到回执,判断需要焚毁,删除本地消息 ===== | ===== 消息发送方收到回执,判断需要焚毁,删除本地消息 ===== | ||
行 153: | 行 175: | ||
// 收到已读回执 | // 收到已读回执 | ||
- (void)messagesDidRead:(NSArray *)aMessages { | - (void)messagesDidRead:(NSArray *)aMessages { | ||
- | for (EMMessage *msg in aMessages) { | + | for (EMChatMessage *msg in aMessages) { |
if ([msg.ext[FIRE_FLAG] boolValue]) { | if ([msg.ext[FIRE_FLAG] boolValue]) { | ||
EMConversation *con = [EMClient.sharedClient.chatManager getConversation:msg.from type:EMConversationTypeChat createIfNotExist:YES]; // 消息所在会话 | EMConversation *con = [EMClient.sharedClient.chatManager getConversation:msg.from type:EMConversationTypeChat createIfNotExist:YES]; // 消息所在会话 | ||
行 163: | 行 185: | ||
</code> | </code> | ||
+ | === web/小程序示例 === | ||
+ | |||
+ | <code> | ||
+ | /** | ||
+ | * 收到消息已读回执 | ||
+ | */ | ||
+ | onReadMessage(message){ | ||
+ | // 判断这个已读回执是发送的那条阅后即焚消息的回执 | ||
+ | if(message.id === fireMessage.id){ | ||
+ | // 删除此条消息 | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
---- | ---- | ||
<WRAP group> | <WRAP group> |