跳到主要内容

消息撤回 - IM即时通讯

消息撤回后不可恢复,消息撤回支持多端自动同步。状态为sending的消息不可以撤回,最长只能撤回4小时内的消息。

前置条件

  • GoEasy版本2.4 +

撤回消息

    im.recallMessage({
messages: [message], //必须为数组格式,要撤回的消息
onSuccess: function () { //撤回成功
console.log("Message recall successful.");
},
onFailed: function (error) { //失败失败
console.log("Message recall failed, code:" + error.code + " content:" + error.content);
}
});

接收撤回通知

该方法用于多端同步,当用户在一个设备上撤回一条消息后,该用户登陆的其他设备会收到被撤回的通知,达到多端消息同步的效果。

      var onMessageRecalled = function (messages) {
//文字消息
//[
// {
// "read": true,
// "receiverId": "08c0a6ec-a42b-47b2-bb1e-15e0f5f9a19a",
// "senderId": "33c3693b-dbb0-4bc9-99c6-fa77b9eb763f",
// "messageId": "f2685e80375811ee8f28db82dee152f9",
// "timestamp": 1691656566267,
// "type": "text",
// "payload": {
// "text": "Hello GoEasy IM"
// },
// "recalled": true,
// "status": "success",
// "recaller": { // 消息撤回者信息,GoEasy版本须 2.7+
// "id": "33c3693b-dbb0-4bc9-99c6-fa77b9eb763f",
// "data": {
// "name": "Juanita",
// "avatar": "/static/images/Avatar-4.png"
// }
// }
// }
//]
console.log("Recalled messages:" + JSON.stringify(messages));
};
//监听和接收被撤回的消息
im.on(GoEasy.IM_EVENT.MESSAGE_RECALLED, onMessageRecalled);