@aochuang/client-sdk 1.0.382 → 1.0.401

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/components/chat-editor/chat-editor-suggestions/chat-editor-suggestions.vue +4 -40
  2. package/components/chat-editor/chat-editor.vue +5 -75
  3. package/components/index.js +6 -1
  4. package/components/session-select/session-select-item.vue +8 -9
  5. package/components/wechat-chat-control/location/location.vue +3 -3
  6. package/components/wework-chat-control/channel-card/channel-card.vue +144 -0
  7. package/components/wework-chat-control/channel-live/channel-live.vue +7 -2
  8. package/components/wework-chat-control/company-card/company-card.vue +1 -1
  9. package/components/wework-chat-control/custom-expression/custom-expression.vue +2 -1
  10. package/components/wework-chat-control/file-url/file-url.vue +34 -16
  11. package/components/wework-chat-control/image/image.vue +137 -2
  12. package/components/wework-chat-control/index.js +15 -7
  13. package/components/wework-chat-control/location/location.vue +3 -3
  14. package/components/wework-chat-control/merge-message/merge-message-panel.vue +63 -0
  15. package/components/wework-chat-control/merge-message/merge-message.vue +84 -0
  16. package/components/wework-chat-control/merge-message/util.js +59 -0
  17. package/components/wework-chat-control/metting/enterprise-wechat.png +0 -0
  18. package/components/wework-chat-control/metting/meeting-video.svg +4 -0
  19. package/components/wework-chat-control/metting/metting.vue +181 -0
  20. package/components/wework-chat-control/red-envelopes/red-envelopes.vue +3 -2
  21. package/components/wework-chat-control/text/text-default.vue +99 -0
  22. package/components/wework-chat-control/text/text-quote.vue +138 -0
  23. package/components/wework-chat-control/text/text.vue +27 -143
  24. package/components/wework-chat-control/url/url-channel-live.vue +53 -0
  25. package/components/wework-chat-control/url/url-miniprogram.vue +6 -7
  26. package/components/wework-chat-control/url/url.vue +26 -2
  27. package/components/wework-chat-control/util.js +30 -17
  28. package/components/wework-chat-control/video/video.vue +11 -3
  29. package/components/wework-chat-control/voice/voice.vue +14 -3
  30. package/components/wework-chat-control/wework-chat-control-config-item.vue +24 -0
  31. package/components/wework-chat-control/wework-chat-control-config-msg.vue +25 -0
  32. package/{uni-components/chat-control/chat-control-config.vue → components/wework-chat-control/wework-chat-control-config.vue} +16 -13
  33. package/components/wework-chat-panel/chat-panel-chat-status/chat-panel-chat-status.vue +120 -0
  34. package/components/wework-chat-panel/chat-panel-item.vue +70 -39
  35. package/components/wework-chat-panel/chat-panel.vue +96 -13
  36. package/package.json +10 -3
  37. package/services/client-chat/client-chat-wechat/client-chat-account.js +37 -7
  38. package/services/client-chat/client-chat-wechat/client-chat-message.js +175 -18
  39. package/services/client-chat/client-chat-wechat/client-chat-session.js +83 -10
  40. package/services/client-chat/client-chat-wechat/client-chat-socket.js +80 -22
  41. package/services/client-chat/client-chat-wechat/client-chat.js +59 -11
  42. package/services/client-chat/client-chat-wework/client-chat-account.js +93 -1
  43. package/services/client-chat/client-chat-wework/client-chat-concats.js +104 -18
  44. package/services/client-chat/client-chat-wework/client-chat-message.js +268 -11
  45. package/services/client-chat/client-chat-wework/client-chat-session.js +271 -191
  46. package/services/client-chat/client-chat-wework/client-chat-socket.js +18 -2
  47. package/services/client-chat/client-chat-wework/client-chat.js +470 -85
  48. package/services/client-chat/client-chat-wework/docs/README.md +308 -0
  49. package/services/client-chat/client-chat-wework/utils.js +5 -5
  50. package/services/socket/socket.js +56 -7
  51. package/utils/log/constants.js +13 -0
  52. package/utils/log/export.js +88 -0
  53. package/utils/log/findings.md +141 -0
  54. package/utils/log/index.js +331 -0
  55. package/utils/log/indexed-db.js +228 -0
  56. package/utils/log/progress.md +267 -0
  57. package/utils/log/serialize.js +146 -0
  58. package/utils/log/task_plan.md +149 -0
  59. package/utils/log//345/210/206/346/236/220/344/270/216/344/274/230/345/214/226/346/226/271/346/241/210.md +303 -0
  60. package/utils/log//346/212/200/346/234/257/346/226/271/346/241/210/346/226/207/346/241/243.md +201 -0
  61. package/utils/log//346/236/266/346/236/204/346/226/207/346/241/243.md +169 -0
  62. package/utils/log//351/234/200/346/261/202/346/226/207/346/241/243.md +124 -0
  63. package/utils/log.js +2 -626
  64. package/components/wework-chat-panel/chat-panel-controls/company-card/company-card.vue +0 -35
  65. package/components/wework-chat-panel/chat-panel-controls/expression/expression.vue +0 -36
  66. package/components/wework-chat-panel/chat-panel-controls/file-url/file-url.vue +0 -35
  67. package/components/wework-chat-panel/chat-panel-controls/image/image.vue +0 -36
  68. package/components/wework-chat-panel/chat-panel-controls/index.js +0 -35
  69. package/components/wework-chat-panel/chat-panel-controls/jx-sys-text/jx-sys-text.vue +0 -28
  70. package/components/wework-chat-panel/chat-panel-controls/link/link.vue +0 -35
  71. package/components/wework-chat-panel/chat-panel-controls/location/location.vue +0 -35
  72. package/components/wework-chat-panel/chat-panel-controls/text/text.vue +0 -43
  73. package/components/wework-chat-panel/chat-panel-controls/unkonw/unkonw.vue +0 -39
  74. package/components/wework-chat-panel/chat-panel-controls/video/video.vue +0 -37
  75. package/components/wework-chat-panel/chat-panel-controls/voice/voice.vue +0 -35
  76. package/uni-common/account-portray/account-portray.vue +0 -51
  77. package/uni-common/account-select/account-select-item.vue +0 -172
  78. package/uni-common/account-select/account-select.vue +0 -252
  79. package/uni-common/all-friend-avatar/all-friend-avatar.vue +0 -49
  80. package/uni-common/friend-avatar/default.svg +0 -1
  81. package/uni-common/friend-avatar/friend-avatar.vue +0 -27
  82. package/uni-common/friend-avatar/index.js +0 -3
  83. package/uni-common/friend-loader/friend-loader.vue +0 -53
  84. package/uni-common/friend-portray/friend-portray.vue +0 -56
  85. package/uni-common/group-avatar/default.svg +0 -1
  86. package/uni-common/group-avatar/group-avatar.vue +0 -18
  87. package/uni-common/group-avatar/index.js +0 -3
  88. package/uni-common/room-avatar/default.svg +0 -6
  89. package/uni-common/room-avatar/index.js +0 -3
  90. package/uni-common/room-avatar/room-avatar.vue +0 -27
  91. package/uni-common/room-loader/room-loader.vue +0 -53
  92. package/uni-common/room-portray/room-portray.vue +0 -56
  93. package/uni-components/chat-control/calling/calling.vue +0 -91
  94. package/uni-components/chat-control/calling/phone-fill.svg +0 -1
  95. package/uni-components/chat-control/calling/vidicon-fill.svg +0 -1
  96. package/uni-components/chat-control/channel-video/channel-video.vue +0 -89
  97. package/uni-components/chat-control/channel-video-card/channel-video-card.vue +0 -105
  98. package/uni-components/chat-control/channel-video-live/channel-video-live.vue +0 -92
  99. package/uni-components/chat-control/chat-control-config-item/chat-control-config-item.vue +0 -20
  100. package/uni-components/chat-control/chat-control-config-item/index.js +0 -3
  101. package/uni-components/chat-control/chat-control-config-msg/chat-control-config-msg-app.vue +0 -25
  102. package/uni-components/chat-control/chat-control-config-msg/chat-control-config-msg-h5.vue +0 -21
  103. package/uni-components/chat-control/chat-control.vue +0 -218
  104. package/uni-components/chat-control/company-card/company-card.vue +0 -123
  105. package/uni-components/chat-control/const.js +0 -28
  106. package/uni-components/chat-control/expression/expression.vue +0 -41
  107. package/uni-components/chat-control/image/image.vue +0 -68
  108. package/uni-components/chat-control/index.js +0 -89
  109. package/uni-components/chat-control/location/location.vue +0 -110
  110. package/uni-components/chat-control/member-change/member-change.vue +0 -32
  111. package/uni-components/chat-control/quote-message/quote-message.vue +0 -216
  112. package/uni-components/chat-control/real-time-position/real-time-position.vue +0 -62
  113. package/uni-components/chat-control/redpacket/red-envelope.svg +0 -1
  114. package/uni-components/chat-control/redpacket/redpacket.vue +0 -75
  115. package/uni-components/chat-control/share-card/share-card.vue +0 -101
  116. package/uni-components/chat-control/system/system.vue +0 -69
  117. package/uni-components/chat-control/system-batch-message/system-batch-message.vue +0 -30
  118. package/uni-components/chat-control/system-text/system-text.vue +0 -32
  119. package/uni-components/chat-control/text/text.vue +0 -67
  120. package/uni-components/chat-control/text-with-at/text-with-at.vue +0 -51
  121. package/uni-components/chat-control/transfer/red-transfer.svg +0 -1
  122. package/uni-components/chat-control/transfer/transfer.vue +0 -80
  123. package/uni-components/chat-control/unkonw/unkonw.vue +0 -37
  124. package/uni-components/chat-control/url/icons/file-excel-line.svg +0 -1
  125. package/uni-components/chat-control/url/icons/file-info-line.svg +0 -1
  126. package/uni-components/chat-control/url/icons/file-music-line.svg +0 -1
  127. package/uni-components/chat-control/url/icons/file-pdf-line.svg +0 -1
  128. package/uni-components/chat-control/url/icons/file-ppt-line.svg +0 -1
  129. package/uni-components/chat-control/url/icons/file-settings-line.svg +0 -1
  130. package/uni-components/chat-control/url/icons/file-text-line.svg +0 -1
  131. package/uni-components/chat-control/url/icons/file-unknow-line.svg +0 -1
  132. package/uni-components/chat-control/url/icons/file-word-line.svg +0 -1
  133. package/uni-components/chat-control/url/icons/file-zip-line.svg +0 -1
  134. package/uni-components/chat-control/url/icons/index.js +0 -24
  135. package/uni-components/chat-control/url/miniprogram.svg +0 -1
  136. package/uni-components/chat-control/url/url-miniprogram.vue +0 -116
  137. package/uni-components/chat-control/url/url.vue +0 -306
  138. package/uni-components/chat-control/url-new/icons/file-excel-line.svg +0 -1
  139. package/uni-components/chat-control/url-new/icons/file-info-line.svg +0 -1
  140. package/uni-components/chat-control/url-new/icons/file-music-line.svg +0 -1
  141. package/uni-components/chat-control/url-new/icons/file-pdf-line.svg +0 -1
  142. package/uni-components/chat-control/url-new/icons/file-ppt-line.svg +0 -1
  143. package/uni-components/chat-control/url-new/icons/file-settings-line.svg +0 -1
  144. package/uni-components/chat-control/url-new/icons/file-text-line.svg +0 -1
  145. package/uni-components/chat-control/url-new/icons/file-unknow-line.svg +0 -1
  146. package/uni-components/chat-control/url-new/icons/file-word-line.svg +0 -1
  147. package/uni-components/chat-control/url-new/icons/file-zip-line.svg +0 -1
  148. package/uni-components/chat-control/url-new/icons/index.js +0 -24
  149. package/uni-components/chat-control/url-new/url-new.vue +0 -110
  150. package/uni-components/chat-control/utils.js +0 -12
  151. package/uni-components/chat-control/video/video.vue +0 -156
  152. package/uni-components/chat-control/voice/voice.vue +0 -166
  153. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet-collect.vue +0 -84
  154. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet-system.vue +0 -28
  155. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet.vue +0 -85
  156. package/uni-components/chat-editor/chat-editor-func/chat-editor-func.vue +0 -157
  157. package/uni-components/chat-editor/chat-editor-func-at/chat-editor-func-at-panel.vue +0 -158
  158. package/uni-components/chat-editor/chat-editor-func-at/chat-editor-func-at.vue +0 -61
  159. package/uni-components/chat-editor/chat-editor-func-button/chat-editor-func-button.vue +0 -58
  160. package/uni-components/chat-editor/chat-editor-func-file/chat-editor-func-file.vue +0 -54
  161. package/uni-components/chat-editor/chat-editor-func-image/chat-editor-func-image.vue +0 -42
  162. package/uni-components/chat-editor/chat-editor-func-video/chat-editor-func-video.vue +0 -42
  163. package/uni-components/chat-editor/chat-editor-func-voice/chat-editor-func-voice.vue +0 -25
  164. package/uni-components/chat-editor/chat-editor-message-send/chat-editor-message-send.vue +0 -158
  165. package/uni-components/chat-editor/chat-editor-quote/chat-editor-quote.vue +0 -75
  166. package/uni-components/chat-editor/chat-editor.vue +0 -257
  167. package/uni-components/chat-editor/index.js +0 -10
  168. package/uni-components/chat-editor/util.js +0 -65
  169. package/uni-components/chat-panel/chat-panel-chats-box.vue +0 -238
  170. package/uni-components/chat-panel/chat-panel-chats-forward/chat-panel-chats-forward.vue +0 -273
  171. package/uni-components/chat-panel/chat-panel-chats-item.vue +0 -578
  172. package/uni-components/chat-panel/chat-panel-chats-status/chat-panel-chats-status.vue +0 -71
  173. package/uni-components/chat-panel/chat-panel-chats.vue +0 -368
  174. package/uni-components/chat-panel/chat-panel.vue +0 -227
  175. package/uni-components/contacts-group-select/contacts-group-select-item.vue +0 -85
  176. package/uni-components/contacts-group-select/contacts-group-select-panel.vue +0 -119
  177. package/uni-components/contacts-group-select/contacts-group-select.vue +0 -150
@@ -126,11 +126,7 @@ export default class ClientChatContacts {
126
126
  */
127
127
  roomBindMemberMap: {},
128
128
 
129
- /**
130
- * 标记通讯录是否修改了
131
- * 如果修改了,比如接收到了分配好友的会话时,一定通讯录变了,变了的时候界面需要根据这个状态刷新通讯录
132
- */
133
- isModify: false
129
+ modifiedAccountMap: {}
134
130
  })
135
131
 
136
132
  friendMap = {}
@@ -237,10 +233,6 @@ export default class ClientChatContacts {
237
233
  return this.data.roomGroupData
238
234
  }
239
235
 
240
- get isModify () {
241
- return this.data.isModify
242
- }
243
-
244
236
  setRoomGroup (data) {
245
237
  this.data.roomGroupData = []
246
238
  if (data && data.length) {
@@ -491,10 +483,10 @@ export default class ClientChatContacts {
491
483
  }
492
484
  }
493
485
  const qwAccountId = this.roomMap[id].qwAccountId
494
- if (qwAccountId && this.data.accountBindFriendMap[qwAccountId] && this.data.accountBindFriendMap[qwAccountId][groupId]) {
495
- const bindIndex = this.data.accountBindFriendMap[qwAccountId][groupId].indexOf(this.roomMap[id])
486
+ if (qwAccountId && this.data.accountBindRoomMap[qwAccountId] && this.data.accountBindRoomMap[qwAccountId][groupId]) {
487
+ const bindIndex = this.data.accountBindRoomMap[qwAccountId][groupId].indexOf(this.roomMap[id])
496
488
  if (bindIndex >= 0) {
497
- this.data.accountBindFriendMap[qwAccountId][groupId].splice(bindIndex, 1)
489
+ this.data.accountBindRoomMap[qwAccountId][groupId].splice(bindIndex, 1)
498
490
  }
499
491
  }
500
492
  })
@@ -611,7 +603,29 @@ export default class ClientChatContacts {
611
603
  })
612
604
  return this._cacheRoomGroupCountMap[qwAccountId]
613
605
  }
614
-
606
+
607
+ /**
608
+ * 清理企微号好友分组数量缓存,同时清理全部企微号的缓存,下次refreshAllFriendGroupCount会重新请求
609
+ */
610
+ clearAllFriendGroupCountCache (qwAccountId) {
611
+ if (!this._cacheFriendGroupCountMap) {
612
+ return
613
+ }
614
+ delete this._cacheFriendGroupCountMap[qwAccountId]
615
+ delete this._cacheFriendGroupCountMap[null]
616
+ }
617
+
618
+ /**
619
+ * 清理企微号群聊分组数量缓存,同时清理全部企微号的缓存,下次refreshAllRoomGroupCount会重新请求
620
+ */
621
+ clearAllRoomGroupCountCache (qwAccountId) {
622
+ if (!this._cacheRoomGroupCountMap) {
623
+ return
624
+ }
625
+ delete this._cacheRoomGroupCountMap[qwAccountId]
626
+ delete this._cacheRoomGroupCountMap[null]
627
+ }
628
+
615
629
  getFriend (friendId) {
616
630
  if (!this.getContactsFriendMethod) {
617
631
  return Promise.reject(new Error('getContactsFriendMethod未定义'))
@@ -628,6 +642,37 @@ export default class ClientChatContacts {
628
642
  return rs
629
643
  })
630
644
  }
645
+
646
+ /**
647
+ * 强制从服务端刷新好友资料,绕过本地缓存。
648
+ */
649
+ refreshFriend (friendId) {
650
+ if (!friendId) {
651
+ return Promise.reject('缺少好友id')
652
+ }
653
+ if (!this.getContactsFriendMethod) {
654
+ return Promise.reject(new Error('getContactsFriendMethod未定义'))
655
+ }
656
+ return this.getContactsFriendMethod({
657
+ id: friendId
658
+ }).then(rs => {
659
+ if (!rs || !rs.data) {
660
+ return Promise.reject('未找到好友' + friendId)
661
+ }
662
+ if (this.friendMap[friendId]) {
663
+ const nextKeys = Object.keys(rs.data)
664
+ Object.keys(this.friendMap[friendId]).forEach(key => {
665
+ if (!nextKeys.includes(key)) {
666
+ Vue.delete(this.friendMap[friendId], key)
667
+ }
668
+ })
669
+ this.updateFriend(friendId, rs.data)
670
+ } else {
671
+ this.addFriend(rs.data)
672
+ }
673
+ return rs
674
+ })
675
+ }
631
676
 
632
677
  setRoomMemberData (roomId, data) {
633
678
  if (!roomId) {
@@ -738,12 +783,52 @@ export default class ClientChatContacts {
738
783
  })
739
784
  }
740
785
 
741
- markModify () {
742
- this.data.isModify = true
786
+ refreshRoom (id) {
787
+ if (!id) {
788
+ return Promise.reject('缺少群id')
789
+ }
790
+ if (!this.getContactsRoomMethod) {
791
+ return Promise.reject(new Error('getContactsRoomMethod未定义'))
792
+ }
793
+ return this.getContactsRoomMethod({
794
+ id
795
+ }).then(rs => {
796
+ if (!rs || !rs.data) {
797
+ return Promise.reject('未找到群' + id)
798
+ }
799
+ const localRoom = this.roomMap[id]
800
+ if (localRoom) {
801
+ this.removeRoom(id)
802
+ const nextKeys = Object.keys(rs.data)
803
+ Object.keys(localRoom).forEach(key => {
804
+ if (!nextKeys.includes(key)) {
805
+ Vue.delete(localRoom, key)
806
+ }
807
+ })
808
+ Object.keys(rs.data).forEach(key => {
809
+ Vue.set(localRoom, key, rs.data[key])
810
+ })
811
+ }
812
+ this.addRoom(localRoom || rs.data)
813
+ return rs
814
+ })
815
+ }
816
+
817
+ isModify (qwAccountId) {
818
+ return !!(qwAccountId && this.data.modifiedAccountMap[qwAccountId])
819
+ }
820
+
821
+ markModify (qwAccountIds) {
822
+ const ids = Array.isArray(qwAccountIds) ? qwAccountIds : [qwAccountIds]
823
+ ids.filter(Boolean).forEach(id => {
824
+ Vue.set(this.data.modifiedAccountMap, id, true)
825
+ })
743
826
  }
744
827
 
745
- unmarkModify () {
746
- this.data.isModify = false
828
+ unmarkModify (qwAccountId) {
829
+ if (qwAccountId) {
830
+ Vue.delete(this.data.modifiedAccountMap, qwAccountId)
831
+ }
747
832
  }
748
833
 
749
834
  reset () {
@@ -758,6 +843,7 @@ export default class ClientChatContacts {
758
843
  this.data.groupBindRoomMap = {}
759
844
  this.data.accountBindFriendMap = {}
760
845
  this.data.accountBindRoomMap = {}
846
+ this.data.modifiedAccountMap = {}
761
847
  this._cacheFriendGroupCountMap = null
762
848
  this._cacheRoomGroupCountMap = null
763
849
  if (this.cancelConnectRequest) {
@@ -769,4 +855,4 @@ export default class ClientChatContacts {
769
855
  this.cancelRefreshRequest = null
770
856
  }
771
857
  }
772
- }
858
+ }
@@ -2,6 +2,7 @@ import Vue from 'vue'
2
2
  import Event from '../../../utils/event.js'
3
3
  import { unique } from '../../../utils/string.js'
4
4
  import { formatDate } from '../../../utils/date.js'
5
+ import { createPromise } from '../../../utils/util'
5
6
 
6
7
  export default class ClientChatMessage {
7
8
 
@@ -20,8 +21,12 @@ export default class ClientChatMessage {
20
21
  */
21
22
  messageData: {}
22
23
  })
23
-
24
+
24
25
  messageMap = {}
26
+ lastMessageTimeMap = {}
27
+ tempMessageMap = {}
28
+ checkMessageSendResultTaskList = []
29
+ recallTaskMap = {}
25
30
 
26
31
  get messageData () {
27
32
  return this.data.messageData
@@ -33,18 +38,29 @@ export default class ClientChatMessage {
33
38
  queryMethod: null,
34
39
  sortField: null, // 排序的字段,必须是唯一的,例如时间
35
40
  groupField: null, // 分组的字段
41
+ checkMessageSendResultMethod: null,
42
+ recallMessageMethod: null,
43
+ recallMessageIdField: null,
36
44
  onAddMessageSuccess: null // 新增消息成功回调事件
37
45
  }, options)
38
46
  if (!options.clientChat) {
39
47
  throw new Error('必须将clientChat传递过来')
40
48
  }
49
+ if (!options.checkMessageSendResultMethod) throw new Error('缺少checkMessageSendResultMethod配置')
41
50
  this.queryMethod = options.queryMethod
42
51
  this.clientChat = options.clientChat
43
52
  this.groupField = options.groupField
44
53
  this.sortField = options.sortField
54
+ this.checkMessageSendResultMethod = options.checkMessageSendResultMethod
55
+ this.recallMessageMethod = options.recallMessageMethod
56
+ this.recallMessageIdField = options.recallMessageIdField
45
57
  this.onAddMessageSuccess = options.onAddMessageSuccess
46
58
  this.event = new Event()
47
59
  }
60
+
61
+ setRelatedMessageService (messageService) {
62
+ this.relatedMessageService = messageService
63
+ }
48
64
 
49
65
  getSortField (time) {
50
66
  const step = 1000 * 60 * 60 * 24
@@ -74,7 +90,7 @@ export default class ClientChatMessage {
74
90
  * "msgSvrId": "4319123759514541049",
75
91
  * "msgType": 1,
76
92
  * "origin": "0",
77
- * "sendStatus": 0,
93
+ * "status": 0,
78
94
  * "tenantId": "1761952223049924608",
79
95
  * "wechatAccountId": "ad9d9ae2a8be4f27311312cdd4af3549dc8427ef",
80
96
  * "wechatFriendId": "2089efcc7f8f40b00b7f05fa4c6dfd3bb642774d",
@@ -89,7 +105,13 @@ export default class ClientChatMessage {
89
105
  if (this.messageMap[data.id]) {
90
106
  return
91
107
  }
108
+ if (this.tempMessageMap[data.id]) {
109
+ Object.assign(data, this.tempMessageMap[data.id])
110
+ delete this.tempMessageMap[data.id]
111
+ }
92
112
  const groupField = data[this.groupField]
113
+ const lastMessageTime = this.getLastMessageTime(groupField)
114
+ const isBeforeLastMessage = !data.isSend && lastMessageTime && data[this.sortField] < lastMessageTime
93
115
  if (!this.data.messageData[groupField]) {
94
116
  Vue.set(this.data.messageData, groupField, {})
95
117
  }
@@ -105,13 +127,27 @@ export default class ClientChatMessage {
105
127
  }
106
128
  this.data.messageData[groupField][sortFields.day][sortFields.milliseconds].push(data)
107
129
  this.messageMap[data.id] = data
130
+ this.setLastMessageTime(groupField, data[this.sortField], data)
131
+ if (data.isSend && data.status === 1 && !data._temp) this.addCheckMessageSendResultTask(data)
108
132
  if (fireEvent !== false) {
133
+ try {
134
+ this.onAddMessageSuccess && this.onAddMessageSuccess({
135
+ data,
136
+ lastMessageTime,
137
+ isBeforeLastMessage
138
+ })
139
+ } catch (error) {
140
+ console.error('[client-chat-message] onAddMessageSuccess error', {
141
+ messageId: data.id,
142
+ error
143
+ })
144
+ }
145
+ if (isBeforeLastMessage) {
146
+ return
147
+ }
109
148
  this.event && this.event.emit('add-message', {
110
149
  data
111
150
  })
112
- this.onAddMessageSuccess && this.onAddMessageSuccess({
113
- data
114
- })
115
151
  }
116
152
  }
117
153
 
@@ -119,6 +155,8 @@ export default class ClientChatMessage {
119
155
  if (!id) {
120
156
  return
121
157
  }
158
+ this.removeCheckMessageSendResultTask(id)
159
+ this.clearRecallState(id)
122
160
  const message = this.messageMap[id]
123
161
  if (!message) {
124
162
  return
@@ -147,21 +185,57 @@ export default class ClientChatMessage {
147
185
  delete this.data.messageData[groupField]
148
186
  }
149
187
  this.event && this.event.emit('remove-message', {
150
- data
188
+ data: message
151
189
  })
152
190
  }
153
191
 
154
192
  updateMessage (id, props) {
155
193
  const message = this.getMessage(id)
156
194
  if (!message) {
195
+ this.tempMessageMap[id] = props
157
196
  return
158
197
  }
159
198
  if (!props) {
160
199
  return
161
200
  }
201
+ const groupField = message[this.groupField]
202
+ const oldSortFieldValue = message[this.sortField]
203
+ const oldSortFields = this.getSortField(oldSortFieldValue)
162
204
  Object.keys(props).forEach(key => {
163
- message[key] = props[key]
205
+ Vue.set(message, key, props[key])
164
206
  })
207
+ if (typeof props[this.sortField] !== 'undefined' && props[this.sortField] !== oldSortFieldValue) {
208
+ const oldBucket = this.data.messageData[groupField] &&
209
+ this.data.messageData[groupField][oldSortFields.day] &&
210
+ this.data.messageData[groupField][oldSortFields.day][oldSortFields.milliseconds]
211
+ if (oldBucket) {
212
+ const index = oldBucket.findIndex(item => item.id === message.id)
213
+ if (index >= 0) {
214
+ oldBucket.splice(index, 1)
215
+ }
216
+ if (!oldBucket.length) {
217
+ Vue.delete(this.data.messageData[groupField][oldSortFields.day], oldSortFields.milliseconds)
218
+ }
219
+ if (!Object.keys(this.data.messageData[groupField][oldSortFields.day]).length) {
220
+ Vue.delete(this.data.messageData[groupField], oldSortFields.day)
221
+ }
222
+ }
223
+ const newSortFields = this.getSortField(message[this.sortField])
224
+ if (!this.data.messageData[groupField]) {
225
+ Vue.set(this.data.messageData, groupField, {})
226
+ }
227
+ if (!this.data.messageData[groupField][newSortFields.day]) {
228
+ Vue.set(this.data.messageData[groupField], newSortFields.day, {})
229
+ }
230
+ if (!this.data.messageData[groupField][newSortFields.day][newSortFields.milliseconds]) {
231
+ Vue.set(this.data.messageData[groupField][newSortFields.day], newSortFields.milliseconds, [])
232
+ }
233
+ const newBucket = this.data.messageData[groupField][newSortFields.day][newSortFields.milliseconds]
234
+ if (!newBucket.some(item => item.id === message.id)) {
235
+ newBucket.push(message)
236
+ }
237
+ this.setLastMessageTime(groupField, message[this.sortField], message)
238
+ }
165
239
  }
166
240
 
167
241
  getMessage (id) {
@@ -178,6 +252,7 @@ export default class ClientChatMessage {
178
252
  message
179
253
  })
180
254
  if (rs === false) {
255
+ this.clearRecallState(message.id)
181
256
  delete this.messageMap[message.id]
182
257
  }
183
258
  return rs
@@ -199,6 +274,8 @@ export default class ClientChatMessage {
199
274
  return rs
200
275
  }, {})
201
276
  } else {
277
+ this.clearRecallTasks()
278
+ this.tempMessageMap = {}
202
279
  this.data.messageData = {}
203
280
  this.messageMap = {}
204
281
  }
@@ -215,11 +292,11 @@ export default class ClientChatMessage {
215
292
  }, data, {
216
293
  cmdType: 'CmdQwSendMessage'
217
294
  })).then(({ data }) => {
218
- if (data.sendStatus === 0) {
295
+ if (data.status === 0) {
219
296
  // 发送成功
220
- } else if (data.sendStatus === 2) {
297
+ } else if (data.status === 2) {
221
298
  // 发送失败
222
- } else if (data.sendStatus === 1) {
299
+ } else if (data.status === 1) {
223
300
  // 发送中
224
301
  }
225
302
  // 如果返回的是对象,证明发送成功了
@@ -230,6 +307,139 @@ export default class ClientChatMessage {
230
307
  return data
231
308
  })
232
309
  }
310
+
311
+ getRecallMessage (id) {
312
+ return this.getMessage(id) || this.tempMessageMap[id] ||
313
+ (this.relatedMessageService && (this.relatedMessageService.getMessage(id) || this.relatedMessageService.tempMessageMap[id]))
314
+ }
315
+
316
+ updateRecallMessage (id, props) {
317
+ this.updateMessage(id, props)
318
+ if (this.relatedMessageService) {
319
+ this.relatedMessageService.updateMessage(id, props)
320
+ }
321
+ }
322
+
323
+ clearRecallTask (id) {
324
+ const task = this.recallTaskMap[id]
325
+ if (!task) {
326
+ return
327
+ }
328
+ clearTimeout(task.timer)
329
+ delete this.recallTaskMap[id]
330
+ }
331
+
332
+ clearRecallState (id) {
333
+ this.clearRecallTask(id)
334
+ delete this.tempMessageMap[id]
335
+ }
336
+
337
+ getRecallErrorMessage (error) {
338
+ const responseData = error && error.response && error.response.data
339
+ if (responseData) {
340
+ return responseData.msg || responseData.message || responseData.error_description || '未知原因'
341
+ }
342
+ if (typeof error === 'string') {
343
+ return error
344
+ }
345
+ return (error && (error.errMsg || error.message)) || '未知原因'
346
+ }
347
+
348
+ recallMessage (params) {
349
+ const data = params || {}
350
+ const messageId = data[this.recallMessageIdField]
351
+ if (!this.recallMessageIdField || !messageId) {
352
+ return Promise.reject(new Error('缺少消息ID'))
353
+ }
354
+ if (!data.sendTime) {
355
+ return Promise.reject(new Error('缺少消息发送时间'))
356
+ }
357
+ if (!this.recallMessageMethod) {
358
+ return Promise.reject(new Error('缺少撤回消息接口配置'))
359
+ }
360
+ const message = this.getRecallMessage(messageId)
361
+ if (message && message.recalled) {
362
+ return Promise.reject(new Error('消息已撤回'))
363
+ }
364
+ if (message && message.recalling) {
365
+ return Promise.reject(new Error('消息正在撤回中'))
366
+ }
367
+ const requestData = {
368
+ [this.recallMessageIdField]: messageId,
369
+ sendTime: data.sendTime
370
+ }
371
+ this.clearRecallTask(messageId)
372
+ this.updateRecallMessage(messageId, {
373
+ recalling: true,
374
+ recallStatus: null,
375
+ recallResultMsg: null
376
+ })
377
+ const task = {
378
+ timer: setTimeout(() => {
379
+ if (this.recallTaskMap[messageId] !== task) {
380
+ return
381
+ }
382
+ delete this.recallTaskMap[messageId]
383
+ this.updateRecallMessage(messageId, {
384
+ recalling: false,
385
+ recallStatus: 'timeout',
386
+ recallResultMsg: '获取结果超时'
387
+ })
388
+ }, 10 * 1000)
389
+ }
390
+ this.recallTaskMap[messageId] = task
391
+
392
+ return Promise.resolve().then(() => this.recallMessageMethod(requestData)).catch(error => {
393
+ if (this.recallTaskMap[messageId] === task) {
394
+ this.clearRecallTask(messageId)
395
+ this.updateRecallMessage(messageId, {
396
+ recalling: false,
397
+ recallStatus: 'failed',
398
+ recallResultMsg: this.getRecallErrorMessage(error)
399
+ })
400
+ }
401
+ return Promise.reject(error)
402
+ })
403
+ }
404
+
405
+ handleMessageRecalled (data) {
406
+ const messageId = data && data[this.recallMessageIdField]
407
+ if (!messageId) {
408
+ return
409
+ }
410
+ this.clearRecallTask(messageId)
411
+ this.updateRecallMessage(messageId, {
412
+ recalled: true,
413
+ recalling: false,
414
+ recallStatus: null,
415
+ recallResultMsg: null,
416
+ revokeTime: data.revokeTime
417
+ })
418
+ }
419
+
420
+ handleMessageRecallFailed (data) {
421
+ const messageId = data && data[this.recallMessageIdField]
422
+ if (!messageId) {
423
+ return
424
+ }
425
+ const message = this.getRecallMessage(messageId)
426
+ if (message && message.recalled) {
427
+ return
428
+ }
429
+ this.clearRecallTask(messageId)
430
+ this.updateRecallMessage(messageId, {
431
+ recalling: false,
432
+ recallStatus: 'failed',
433
+ recallResultMsg: data.reason || '未知原因'
434
+ })
435
+ }
436
+
437
+ clearRecallTasks () {
438
+ Object.keys(this.recallTaskMap).forEach(id => {
439
+ clearTimeout(this.recallTaskMap[id].timer)
440
+ })
441
+ this.recallTaskMap = {}
442
+ }
233
443
 
234
444
  /***
235
445
  * 远程加载消息
@@ -273,8 +483,55 @@ export default class ClientChatMessage {
273
483
  this.clearMessage()
274
484
  return this.loadMessageData(params)
275
485
  }
486
+
487
+ addCheckMessageSendResultTask (message) {
488
+ if (this.checkMessageSendResultTaskList.some(v => v.id === message.id)) return
489
+ let timer
490
+ const task = { id: message.id, promise: createPromise(), check: () => {
491
+ if (message.status !== 1) return task.promise.resolve()
492
+ if (Date.now() - (message.createTime || message.sendTime) > 5 * 60 * 1000) return task.promise.resolve({status: 3, resultMsg: '消息发送超时'})
493
+ timer = setTimeout(() => {
494
+ Promise.resolve(this.checkMessageSendResultMethod({message})).then(rs => {
495
+ const data = rs && rs.data
496
+ if (data && data.status === 1) task.check()
497
+ else task.promise.resolve(data || {})
498
+ }, () => task.check())
499
+ }, 3000)
500
+ }, cancel: () => { clearTimeout(timer); task.promise.reject('reject') } }
501
+ this.checkMessageSendResultTaskList.push(task)
502
+ task.check()
503
+ task.promise.then(rs => this.updateMessage(message.id, rs || {})).finally(() => this.removeCheckMessageSendResultTask(message.id))
504
+ }
505
+
506
+ removeCheckMessageSendResultTask (id) {
507
+ const index = this.checkMessageSendResultTaskList.findIndex(v => v.id === id)
508
+ if (index >= 0) { this.checkMessageSendResultTaskList[index].cancel(); this.checkMessageSendResultTaskList.splice(index, 1) }
509
+ }
276
510
 
277
511
  reset () {
512
+ this.clearRecallTasks()
513
+ this.checkMessageSendResultTaskList.forEach(task => task.cancel())
514
+ this.checkMessageSendResultTaskList = []
515
+ this.tempMessageMap = {}
516
+ this.messageMap = {}
517
+ this.lastMessageTimeMap = {}
278
518
  this.data.messageData = {}
279
519
  }
280
- }
520
+
521
+ getLastMessageTime (groupField) {
522
+ return this.lastMessageTimeMap[groupField]
523
+ }
524
+
525
+ setLastMessageTime (groupField, messageTime, message) {
526
+ if (!groupField || !messageTime || (message && message.msgType === '_EMPTY_')) {
527
+ return
528
+ }
529
+ if (message && message._temp) {
530
+ return
531
+ }
532
+ const lastMessageTime = this.getLastMessageTime(groupField)
533
+ if (!lastMessageTime || messageTime > lastMessageTime) {
534
+ this.lastMessageTimeMap[groupField] = messageTime
535
+ }
536
+ }
537
+ }