emAboutAck.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* read ack、channel ack、recall ack*/
  2. import { EaseSDK, EMClient } from '../index';
  3. const emSendReadAck = () => {
  4. // 处理未读消息回执
  5. const sendReadAckMsg = (receivemsg) => {
  6. const { chatType, from, id } = receivemsg;
  7. let option = {
  8. type: 'read', // 消息是否已读。
  9. chatType: chatType, // 会话类型,这里为单聊。
  10. to: from, // 消息接收方的用户 ID。
  11. id: id, // 需要发送已读回执的消息 ID。
  12. };
  13. let msg = EaseSDK.message.create(option);
  14. EMClient.send(msg);
  15. };
  16. //发送撤回ack
  17. const sendRecallAckMsg = (recallSourceMsg) => {
  18. const { chatType, to, mid } = recallSourceMsg;
  19. let option = {
  20. // 要撤回消息的消息 ID。
  21. mid: mid,
  22. // 消息接收方:单聊为对方用户 ID,群聊和聊天室分别为群组 ID 和聊天室 ID。
  23. to: to,
  24. // 会话类型:单聊、群聊和聊天室分别为 `singleChat`、`groupChat` 和 `chatRoom`。
  25. chatType: chatType,
  26. };
  27. return new Promise((resolve, reject) => {
  28. EMClient.recallMessage(option)
  29. .then((res) => {
  30. console.log('recall success', res);
  31. resolve(res);
  32. })
  33. .catch((error) => {
  34. // 消息撤回失败,原因可能是超过了撤销时限(超过 2 分钟)。
  35. console.log('fail', error);
  36. reject(error);
  37. });
  38. });
  39. };
  40. return {
  41. sendReadAckMsg,
  42. sendRecallAckMsg,
  43. };
  44. };
  45. export default emSendReadAck;