@aochuang/client-sdk 1.0.371 → 1.0.373

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 (165) hide show
  1. package/common/.DS_Store +0 -0
  2. package/components/.DS_Store +0 -0
  3. package/components/chat-editor/chat-editor-suggestions/chat-editor-suggestions.vue +28 -2
  4. package/components/chat-editor/chat-editor.vue +62 -1
  5. package/components/index.js +6 -1
  6. package/components/session-select/session-select-item.vue +8 -9
  7. package/components/wechat-chat-control/.DS_Store +0 -0
  8. package/components/wechat-chat-control/transfer/.DS_Store +0 -0
  9. package/components/wechat-chat-control/url/.DS_Store +0 -0
  10. package/components/wechat-chat-control/voice/.DS_Store +0 -0
  11. package/components/wework-chat-control/channel-card/channel-card.vue +144 -0
  12. package/components/wework-chat-control/channel-live/channel-live.vue +7 -2
  13. package/components/wework-chat-control/company-card/company-card.vue +1 -1
  14. package/components/wework-chat-control/custom-expression/custom-expression.vue +2 -1
  15. package/components/wework-chat-control/file-url/file-url.vue +34 -16
  16. package/components/wework-chat-control/image/image.vue +137 -2
  17. package/components/wework-chat-control/index.js +15 -7
  18. package/components/wework-chat-control/link/.DS_Store +0 -0
  19. package/components/wework-chat-control/location/location.vue +3 -3
  20. package/components/wework-chat-control/merge-message/merge-message-panel.vue +63 -0
  21. package/components/wework-chat-control/merge-message/merge-message.vue +84 -0
  22. package/components/wework-chat-control/merge-message/util.js +59 -0
  23. package/components/wework-chat-control/metting/enterprise-wechat.png +0 -0
  24. package/components/wework-chat-control/metting/meeting-video.svg +4 -0
  25. package/components/wework-chat-control/metting/metting.vue +181 -0
  26. package/components/wework-chat-control/red-envelopes/red-envelopes.vue +3 -2
  27. package/components/wework-chat-control/text/text-default.vue +99 -0
  28. package/components/wework-chat-control/text/text-quote.vue +105 -0
  29. package/components/wework-chat-control/text/text.vue +24 -144
  30. package/components/wework-chat-control/url/url-channel-live.vue +53 -0
  31. package/components/wework-chat-control/url/url-miniprogram.vue +6 -7
  32. package/components/wework-chat-control/url/url.vue +26 -2
  33. package/components/wework-chat-control/util.js +26 -17
  34. package/components/wework-chat-control/video/.DS_Store +0 -0
  35. package/components/wework-chat-control/video/video.vue +10 -2
  36. package/components/wework-chat-control/voice/voice.vue +9 -2
  37. package/components/wework-chat-control/wework-chat-control-config-item.vue +24 -0
  38. package/components/wework-chat-control/wework-chat-control-config-msg.vue +25 -0
  39. package/{uni-components/chat-control/chat-control-config.vue → components/wework-chat-control/wework-chat-control-config.vue} +16 -13
  40. package/components/wework-chat-panel/chat-panel-chat-status/chat-panel-chat-status.vue +73 -0
  41. package/components/wework-chat-panel/chat-panel-item.vue +56 -25
  42. package/components/wework-chat-panel/chat-panel.vue +96 -13
  43. package/package.json +10 -3
  44. package/services/.DS_Store +0 -0
  45. package/services/client-chat/client-chat-wework/client-chat-account.js +84 -1
  46. package/services/client-chat/client-chat-wework/client-chat-concats.js +81 -17
  47. package/services/client-chat/client-chat-wework/client-chat-message.js +45 -5
  48. package/services/client-chat/client-chat-wework/client-chat-session.js +59 -4
  49. package/services/client-chat/client-chat-wework/client-chat-socket.js +13 -1
  50. package/services/client-chat/client-chat-wework/client-chat.js +320 -11
  51. package/services/client-chat/client-chat-wework/utils.js +5 -5
  52. package/components/wework-chat-panel/chat-panel-controls/company-card/company-card.vue +0 -35
  53. package/components/wework-chat-panel/chat-panel-controls/expression/expression.vue +0 -36
  54. package/components/wework-chat-panel/chat-panel-controls/file-url/file-url.vue +0 -35
  55. package/components/wework-chat-panel/chat-panel-controls/image/image.vue +0 -36
  56. package/components/wework-chat-panel/chat-panel-controls/index.js +0 -35
  57. package/components/wework-chat-panel/chat-panel-controls/jx-sys-text/jx-sys-text.vue +0 -28
  58. package/components/wework-chat-panel/chat-panel-controls/link/link.vue +0 -35
  59. package/components/wework-chat-panel/chat-panel-controls/location/location.vue +0 -35
  60. package/components/wework-chat-panel/chat-panel-controls/text/text.vue +0 -43
  61. package/components/wework-chat-panel/chat-panel-controls/unkonw/unkonw.vue +0 -39
  62. package/components/wework-chat-panel/chat-panel-controls/video/video.vue +0 -37
  63. package/components/wework-chat-panel/chat-panel-controls/voice/voice.vue +0 -35
  64. package/uni-common/account-portray/account-portray.vue +0 -51
  65. package/uni-common/account-select/account-select-item.vue +0 -172
  66. package/uni-common/account-select/account-select.vue +0 -252
  67. package/uni-common/all-friend-avatar/all-friend-avatar.vue +0 -49
  68. package/uni-common/friend-avatar/default.svg +0 -1
  69. package/uni-common/friend-avatar/friend-avatar.vue +0 -27
  70. package/uni-common/friend-avatar/index.js +0 -3
  71. package/uni-common/friend-loader/friend-loader.vue +0 -53
  72. package/uni-common/friend-portray/friend-portray.vue +0 -56
  73. package/uni-common/group-avatar/default.svg +0 -1
  74. package/uni-common/group-avatar/group-avatar.vue +0 -18
  75. package/uni-common/group-avatar/index.js +0 -3
  76. package/uni-common/room-avatar/default.svg +0 -6
  77. package/uni-common/room-avatar/index.js +0 -3
  78. package/uni-common/room-avatar/room-avatar.vue +0 -27
  79. package/uni-common/room-loader/room-loader.vue +0 -53
  80. package/uni-common/room-portray/room-portray.vue +0 -56
  81. package/uni-components/chat-control/calling/calling.vue +0 -91
  82. package/uni-components/chat-control/calling/phone-fill.svg +0 -1
  83. package/uni-components/chat-control/calling/vidicon-fill.svg +0 -1
  84. package/uni-components/chat-control/channel-video/channel-video.vue +0 -89
  85. package/uni-components/chat-control/channel-video-card/channel-video-card.vue +0 -105
  86. package/uni-components/chat-control/channel-video-live/channel-video-live.vue +0 -92
  87. package/uni-components/chat-control/chat-control-config-item/chat-control-config-item.vue +0 -20
  88. package/uni-components/chat-control/chat-control-config-item/index.js +0 -3
  89. package/uni-components/chat-control/chat-control-config-msg/chat-control-config-msg-app.vue +0 -25
  90. package/uni-components/chat-control/chat-control-config-msg/chat-control-config-msg-h5.vue +0 -21
  91. package/uni-components/chat-control/chat-control.vue +0 -218
  92. package/uni-components/chat-control/company-card/company-card.vue +0 -123
  93. package/uni-components/chat-control/const.js +0 -28
  94. package/uni-components/chat-control/expression/expression.vue +0 -41
  95. package/uni-components/chat-control/image/image.vue +0 -68
  96. package/uni-components/chat-control/index.js +0 -89
  97. package/uni-components/chat-control/location/location.vue +0 -110
  98. package/uni-components/chat-control/member-change/member-change.vue +0 -32
  99. package/uni-components/chat-control/quote-message/quote-message.vue +0 -216
  100. package/uni-components/chat-control/real-time-position/real-time-position.vue +0 -62
  101. package/uni-components/chat-control/redpacket/red-envelope.svg +0 -1
  102. package/uni-components/chat-control/redpacket/redpacket.vue +0 -75
  103. package/uni-components/chat-control/share-card/share-card.vue +0 -101
  104. package/uni-components/chat-control/system/system.vue +0 -69
  105. package/uni-components/chat-control/system-batch-message/system-batch-message.vue +0 -30
  106. package/uni-components/chat-control/system-text/system-text.vue +0 -32
  107. package/uni-components/chat-control/text/text.vue +0 -67
  108. package/uni-components/chat-control/text-with-at/text-with-at.vue +0 -51
  109. package/uni-components/chat-control/transfer/red-transfer.svg +0 -1
  110. package/uni-components/chat-control/transfer/transfer.vue +0 -80
  111. package/uni-components/chat-control/unkonw/unkonw.vue +0 -37
  112. package/uni-components/chat-control/url/icons/file-excel-line.svg +0 -1
  113. package/uni-components/chat-control/url/icons/file-info-line.svg +0 -1
  114. package/uni-components/chat-control/url/icons/file-music-line.svg +0 -1
  115. package/uni-components/chat-control/url/icons/file-pdf-line.svg +0 -1
  116. package/uni-components/chat-control/url/icons/file-ppt-line.svg +0 -1
  117. package/uni-components/chat-control/url/icons/file-settings-line.svg +0 -1
  118. package/uni-components/chat-control/url/icons/file-text-line.svg +0 -1
  119. package/uni-components/chat-control/url/icons/file-unknow-line.svg +0 -1
  120. package/uni-components/chat-control/url/icons/file-word-line.svg +0 -1
  121. package/uni-components/chat-control/url/icons/file-zip-line.svg +0 -1
  122. package/uni-components/chat-control/url/icons/index.js +0 -24
  123. package/uni-components/chat-control/url/miniprogram.svg +0 -1
  124. package/uni-components/chat-control/url/url-miniprogram.vue +0 -116
  125. package/uni-components/chat-control/url/url.vue +0 -306
  126. package/uni-components/chat-control/url-new/icons/file-excel-line.svg +0 -1
  127. package/uni-components/chat-control/url-new/icons/file-info-line.svg +0 -1
  128. package/uni-components/chat-control/url-new/icons/file-music-line.svg +0 -1
  129. package/uni-components/chat-control/url-new/icons/file-pdf-line.svg +0 -1
  130. package/uni-components/chat-control/url-new/icons/file-ppt-line.svg +0 -1
  131. package/uni-components/chat-control/url-new/icons/file-settings-line.svg +0 -1
  132. package/uni-components/chat-control/url-new/icons/file-text-line.svg +0 -1
  133. package/uni-components/chat-control/url-new/icons/file-unknow-line.svg +0 -1
  134. package/uni-components/chat-control/url-new/icons/file-word-line.svg +0 -1
  135. package/uni-components/chat-control/url-new/icons/file-zip-line.svg +0 -1
  136. package/uni-components/chat-control/url-new/icons/index.js +0 -24
  137. package/uni-components/chat-control/url-new/url-new.vue +0 -110
  138. package/uni-components/chat-control/utils.js +0 -12
  139. package/uni-components/chat-control/video/video.vue +0 -156
  140. package/uni-components/chat-control/voice/voice.vue +0 -166
  141. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet-collect.vue +0 -84
  142. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet-system.vue +0 -28
  143. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet.vue +0 -85
  144. package/uni-components/chat-editor/chat-editor-func/chat-editor-func.vue +0 -157
  145. package/uni-components/chat-editor/chat-editor-func-at/chat-editor-func-at-panel.vue +0 -158
  146. package/uni-components/chat-editor/chat-editor-func-at/chat-editor-func-at.vue +0 -61
  147. package/uni-components/chat-editor/chat-editor-func-button/chat-editor-func-button.vue +0 -58
  148. package/uni-components/chat-editor/chat-editor-func-file/chat-editor-func-file.vue +0 -54
  149. package/uni-components/chat-editor/chat-editor-func-image/chat-editor-func-image.vue +0 -42
  150. package/uni-components/chat-editor/chat-editor-func-video/chat-editor-func-video.vue +0 -42
  151. package/uni-components/chat-editor/chat-editor-func-voice/chat-editor-func-voice.vue +0 -25
  152. package/uni-components/chat-editor/chat-editor-message-send/chat-editor-message-send.vue +0 -158
  153. package/uni-components/chat-editor/chat-editor-quote/chat-editor-quote.vue +0 -75
  154. package/uni-components/chat-editor/chat-editor.vue +0 -257
  155. package/uni-components/chat-editor/index.js +0 -10
  156. package/uni-components/chat-editor/util.js +0 -65
  157. package/uni-components/chat-panel/chat-panel-chats-box.vue +0 -238
  158. package/uni-components/chat-panel/chat-panel-chats-forward/chat-panel-chats-forward.vue +0 -273
  159. package/uni-components/chat-panel/chat-panel-chats-item.vue +0 -578
  160. package/uni-components/chat-panel/chat-panel-chats-status/chat-panel-chats-status.vue +0 -71
  161. package/uni-components/chat-panel/chat-panel-chats.vue +0 -368
  162. package/uni-components/chat-panel/chat-panel.vue +0 -227
  163. package/uni-components/contacts-group-select/contacts-group-select-item.vue +0 -85
  164. package/uni-components/contacts-group-select/contacts-group-select-panel.vue +0 -119
  165. package/uni-components/contacts-group-select/contacts-group-select.vue +0 -150
@@ -82,7 +82,8 @@ export default class ClientChatSession {
82
82
  /**
83
83
  * 删除会话
84
84
  */
85
- deleteSessionMethod: null
85
+ deleteSessionMethod: null,
86
+ modifiedAccountMap: {}
86
87
  })
87
88
 
88
89
  accountIds = []
@@ -119,6 +120,23 @@ export default class ClientChatSession {
119
120
  return this.data.loading
120
121
  }
121
122
 
123
+ isModify (qwAccountId) {
124
+ return !!(qwAccountId && this.data.modifiedAccountMap[qwAccountId])
125
+ }
126
+
127
+ markModify (qwAccountIds) {
128
+ const ids = Array.isArray(qwAccountIds) ? qwAccountIds : [qwAccountIds]
129
+ ids.filter(Boolean).forEach(id => {
130
+ Vue.set(this.data.modifiedAccountMap, id, true)
131
+ })
132
+ }
133
+
134
+ unmarkModify (qwAccountId) {
135
+ if (qwAccountId) {
136
+ Vue.delete(this.data.modifiedAccountMap, qwAccountId)
137
+ }
138
+ }
139
+
122
140
  get loadAssignTaskSessioning () {
123
141
  return this.data.loadAssignTaskSessioning
124
142
  }
@@ -205,6 +223,35 @@ export default class ClientChatSession {
205
223
  getSessionByLocal (sessionId) {
206
224
  return this.sessionMap[sessionId]
207
225
  }
226
+
227
+ /**
228
+ * 强制从服务端刷新会话,绕过本地缓存。
229
+ */
230
+ refreshSession (sessionId) {
231
+ if (!sessionId) {
232
+ return Promise.reject('缺少会话id')
233
+ }
234
+ return this.getSessionMethod({
235
+ id: sessionId
236
+ }).then(rs => {
237
+ if (!rs || !rs.data) {
238
+ return Promise.reject('未找到会话' + sessionId)
239
+ }
240
+ // 事件计算出的 sessionId 是本地索引,始终保持与服务端返回对象一致。
241
+ const serverSession = Object.assign({}, rs.data, {
242
+ id: sessionId
243
+ })
244
+ const localSession = this.getSessionByLocal(sessionId)
245
+ if (localSession) {
246
+ this.updateSession(sessionId, serverSession)
247
+ } else {
248
+ this.addSession(serverSession)
249
+ }
250
+ return Object.assign({}, rs, {
251
+ data: serverSession
252
+ })
253
+ })
254
+ }
208
255
 
209
256
  findSession (findFn) {
210
257
  let result
@@ -418,6 +465,9 @@ export default class ClientChatSession {
418
465
  }
419
466
  }
420
467
  delete this.sessionMap[id]
468
+ if (this.data.currentSessionId === id) {
469
+ this.data.currentSessionId = null
470
+ }
421
471
  if (checkLastUpdateSession !== false) {
422
472
  // todo 后面可能会删掉这块的逻辑,因为后端排序逻辑变了
423
473
  this.checkAndUpdateLastUpdateSession()
@@ -562,7 +612,9 @@ export default class ClientChatSession {
562
612
  return true
563
613
  }
564
614
  })
565
- this.data.sessionGroupData[groupField][topField][oldSortFields.day][oldSortFields.milliseconds].splice(index, 1)
615
+ if (index >= 0) {
616
+ this.data.sessionGroupData[groupField][topField][oldSortFields.day][oldSortFields.milliseconds].splice(index, 1)
617
+ }
566
618
  }
567
619
  })
568
620
  // 按照新的时间来分组排序
@@ -635,7 +687,9 @@ export default class ClientChatSession {
635
687
  return true
636
688
  }
637
689
  })
638
- this.data.sessionGroupData[groupField][topField][sortFields.day][sortFields.milliseconds].splice(index, 1)
690
+ if (index >= 0) {
691
+ this.data.sessionGroupData[groupField][topField][sortFields.day][sortFields.milliseconds].splice(index, 1)
692
+ }
639
693
  }
640
694
  })
641
695
  // 所有的
@@ -915,6 +969,7 @@ export default class ClientChatSession {
915
969
  this.data.sessionData = {}
916
970
  this.data.sessionGroupData = {}
917
971
  this.data.sessionMuteMap = {}
972
+ this.data.modifiedAccountMap = {}
918
973
  // this.data.sessionUnreadCountMap = {}
919
974
  this.sessionMap = {}
920
975
  if (this.cancelLoadDataRequest) {
@@ -926,4 +981,4 @@ export default class ClientChatSession {
926
981
  this.cancelRefreshRequest = null
927
982
  }
928
983
  }
929
- }
984
+ }
@@ -15,11 +15,16 @@ export default class ClietChatSocket {
15
15
  // 执行回调事件前的方法
16
16
  beforeFireCallback: null,
17
17
  onCmdQwNewMessage: null,
18
+ onCmdQwContactInfoChanged: null,
19
+ onCmdQwContactRequestChanged: null,
20
+ onCmdQwAcceptContactRequest: null,
21
+ onCmdQwRoomInfoChanged: null,
18
22
  onCmdSendMessageResult: null,
19
23
  onCmdFriendInfoChanged: null,
20
24
  onCmdDownloadVideoResult: null,
21
25
  onCmdChatroomInfoChanged: null,
22
26
  onCmdChatroomInfoChangedBatch: null,
27
+ onHeartbeatSuccess: null,
23
28
  onHeartbeatCheck: null
24
29
  }, options)
25
30
  if (!options.socket) {
@@ -27,6 +32,13 @@ export default class ClietChatSocket {
27
32
  }
28
33
  this.socket = options.socket
29
34
  this.socket.event.on('onCmdQwNewMessage', options.onCmdQwNewMessage)
35
+ this.socket.event.on('onCmdQwContactInfoChanged', options.onCmdQwContactInfoChanged)
36
+ this.socket.event.on('onCmdQwContactRequestChanged', options.onCmdQwContactRequestChanged)
37
+ this.socket.event.on('onCmdQwAcceptContactRequest', options.onCmdQwAcceptContactRequest)
38
+ this.socket.event.on('onCmdQwRoomInfoChanged', options.onCmdQwRoomInfoChanged)
39
+ this.socket.event.on('onHeartbeatSuccess', (evt) => {
40
+ options.onHeartbeatSuccess && options.onHeartbeatSuccess(evt)
41
+ })
30
42
  this.socket.event.on('onHeartbeatCheck', ({ mergeParams }) => {
31
43
  options.onHeartbeatCheck && options.onHeartbeatCheck({
32
44
  mergeParams
@@ -62,4 +74,4 @@ export default class ClietChatSocket {
62
74
  setUrl (url) {
63
75
  this.socket.setUrl(url)
64
76
  }
65
- }
77
+ }
@@ -32,6 +32,7 @@ class ClientChat {
32
32
  getLoginUserIdMethod: null,
33
33
  getLoginUserTokenMethod: null,
34
34
  loadAccountDataMethod: null,
35
+ getLoginAccountIdMethod: null, // 因为1.0有帮聊逻辑,帮聊消息以及通讯录的accountId不是登录用户的accountId,会导致找到的会话出现问题,所以这里提供一个方法让外部传入
35
36
  loadSessionDataMethod: null,
36
37
  updateSessionReadMethod: null,
37
38
  getSessionMethod: null,
@@ -39,6 +40,7 @@ class ClientChat {
39
40
  getAccountUnreadMessageNumMethod: null,
40
41
  updateAccountMessageReadMethod: null,
41
42
  deleteAccountSessionMethod: null,
43
+ getAccountGreetingUnreadMsgCountMethod: null,
42
44
  loadContactsRoomGroupDataMethod: null,
43
45
  loadContactsFriendGroupDataMethod: null,
44
46
  loadContactsFriendDataMethod: null,
@@ -50,6 +52,7 @@ class ClientChat {
50
52
  getContactsRoomMethod: null,
51
53
  loadFriendMessageDataMethod: null,
52
54
  loadRoomMessageDataMethod: null,
55
+ checkMessageSendResultMethod: null,
53
56
  onOverwriteFriendInfoChange: null // 为了兼容1.0拉取会话逻辑加的,1.0暂时不支持根据taskId拉取
54
57
  }, options)
55
58
  if (!options.loadFriendMessageDataMethod) {
@@ -57,8 +60,9 @@ class ClientChat {
57
60
  }
58
61
  if (!options.loadRoomMessageDataMethod) {
59
62
  throw new Error('loadRoomMessageDataMethod不能为空')
60
- }
63
+ }
61
64
  this.onOverwriteFriendInfoChange = options.onOverwriteFriendInfoChange
65
+ this.getLoginAccountIdMethod = options.getLoginAccountIdMethod
62
66
  this.event = new Event({
63
67
  checkOnMethod: (name) => {
64
68
  if (name === 'ready') {
@@ -85,8 +89,10 @@ class ClientChat {
85
89
  groupField: 'contactId',
86
90
  sortField: 'sendTime',
87
91
  clientChat: this,
92
+ checkMessageSendResultMethod: options.checkMessageSendResultMethod,
88
93
  onAddMessageSuccess: ({ data }) => {
89
- let sessionId = createSessionId(data.corpId, data.qwAccountId, data.contactId)
94
+ const accountId = this.getLoginAccountIdMethod ? this.getLoginAccountIdMethod() : data.qwAccountId
95
+ let sessionId = createSessionId(accountId, data.contactId)
90
96
  // 更新会话
91
97
  if (!sessionId) {
92
98
  return
@@ -100,6 +106,15 @@ class ClientChat {
100
106
  return this.session.getSession(sessionId).then(done)
101
107
  })
102
108
  this._sessionPollRequestMap[sessionId].start().then((rs) => {
109
+ // 后端更新会话是异步过程,返回的会话信息可能还未包含当前消息
110
+ if (rs && rs.data && !rs.data.unreadMsgCount) {
111
+ rs.data.unreadMsgCount = data.isSend ? 0 : 1
112
+ rs.data.lastMsgContent = data.content
113
+ rs.data.lastMsgType = data.msgType
114
+ rs.data.lastMsgTime = data.sendTime
115
+ rs.data.lastMsgId = data.id
116
+ rs.data.lastUpdateTime = data.updateDate
117
+ }
103
118
  // 更新账号未读消息数量
104
119
  this.account.updateAccountUnreadMessageNum(rs.data.qwAccountId, ({ unreadMesasgeNum }) => {
105
120
  return unreadMesasgeNum += (rs.data.unreadMsgCount || 0)
@@ -144,7 +159,7 @@ class ClientChat {
144
159
  groupField: 'contactId',
145
160
  sortField: 'sendTime',
146
161
  clientChat: this,
147
- // checkMessageSendResultMethod: options.checkMessageSendResultMethod,
162
+ checkMessageSendResultMethod: options.checkMessageSendResultMethod,
148
163
  // loadLossMessageDataMethod: options.loadLossFriendMessageDataMethod,
149
164
  queryMethod: (params) => {
150
165
  return options.loadFriendMessageDataMethod(params)
@@ -154,8 +169,10 @@ class ClientChat {
154
169
  groupField: 'roomId',
155
170
  sortField: 'sendTime',
156
171
  clientChat: this,
172
+ checkMessageSendResultMethod: options.checkMessageSendResultMethod,
157
173
  onAddMessageSuccess: ({ data }) => {
158
- let sessionId = createSessionId(data.corpId, data.qwAccountId, data.roomId)
174
+ const accountId = this.getLoginAccountIdMethod ? this.getLoginAccountIdMethod() : data.qwAccountId
175
+ let sessionId = createSessionId(accountId, data.roomId)
159
176
  // 更新会话
160
177
  if (!sessionId) {
161
178
  return
@@ -170,6 +187,15 @@ class ClientChat {
170
187
  return this.session.getSession(sessionId).then(done)
171
188
  })
172
189
  this._sessionPollRequestMap[sessionId].start().then((rs) => {
190
+ // 后端更新会话是异步过程,返回的会话信息可能还未包含当前消息
191
+ if (rs && rs.data && !rs.data.unreadMsgCount) {
192
+ rs.data.unreadMsgCount = data.isSend ? 0 : 1
193
+ rs.data.lastMsgContent = data.content
194
+ rs.data.lastMsgType = data.msgType
195
+ rs.data.lastMsgTime = data.sendTime
196
+ rs.data.lastMsgId = data.id
197
+ rs.data.lastUpdateTime = data.updateDate
198
+ }
173
199
  // 更新账号未读消息数量
174
200
  this.account.updateAccountUnreadMessageNum(rs.data.qwAccountId, ({ unreadMesasgeNum }) => {
175
201
  return unreadMesasgeNum += (rs.data.unreadMsgCount || 0)
@@ -214,7 +240,7 @@ class ClientChat {
214
240
  groupField: 'roomId',
215
241
  sortField: 'sendTime',
216
242
  clientChat: this,
217
- // checkMessageSendResultMethod: options.checkMessageSendResultMethod,
243
+ checkMessageSendResultMethod: options.checkMessageSendResultMethod,
218
244
  // loadLossMessageDataMethod: options.loadLossRoomMessageDataMethod,
219
245
  queryMethod: (params) => {
220
246
  return options.loadRoomMessageDataMethod(params)
@@ -237,12 +263,18 @@ class ClientChat {
237
263
  loadAccountDataMethod: options.loadAccountDataMethod,
238
264
  getAccountUnreadMessageNumMethod: options.getAccountUnreadMessageNumMethod,
239
265
  updateAccountMessageReadMethod: options.updateAccountMessageReadMethod,
266
+ getAccountGreetingUnreadMsgCountMethod: options.getAccountGreetingUnreadMsgCountMethod,
240
267
  onAccountAdded: ({ account }) => {
241
268
  return this.account.refreshAccountUnreadMessageNum({
242
269
  qwAccountId: account.id,
243
270
  corpId: account.corpId
244
271
  })
245
272
  },
273
+ onAccountLoaded: () => {
274
+ if (options.getAccountGreetingUnreadMsgCountMethod) {
275
+ this.account.refreshAllAccountGreetingUnreadMsgCount().catch(() => {})
276
+ }
277
+ },
246
278
  onCurrentAccountChange: ({ currentAccount }) => {
247
279
  this.contacts.refreshAllFriendGroupCount({
248
280
  qwAccountId: currentAccount ? currentAccount.id : null
@@ -258,6 +290,95 @@ class ClientChat {
258
290
  })
259
291
  this.socket = new ClientChatSocket({
260
292
  socket: options.socket,
293
+ onCmdQwContactRequestChanged: ({ data } = {}) => {
294
+ // {
295
+ // "cmdType": CmdQwContactRequestChanged
296
+ // "seq": 123,
297
+ // "cmdType": "CmdQwContactRequestChanged",
298
+ // "changeType": 1,
299
+ // "record": { ...QwContactRequestRecordDto...
300
+ // }
301
+ // changeType:1 = 新增、2 = 状态变化(值来自 ChangeTypeEnum,序列化为数字)
302
+ // 触发时机:新同步到一条好友请求 → changeType=1;之后每次状态流转(1/2/3/4)→ changeType=2
303
+ // 推送目标:该记录 accountId 对应的客服端。若该请求未分配客服(设备无保管者)则不推送,前端不能依赖推送判断「没有新的好友请求」
304
+ // 新增和状态流转都会影响待处理数量,刷新对应账号的好友请求数
305
+ this.refreshGreetingUnreadMsgCountByPush(data)
306
+ },
307
+ onCmdQwAcceptContactRequest: ({ data } = {}) => {
308
+ // CmdQwAcceptContactRequest 请求字段不变(qwAccountId、remoteId),错误提示文案不变。但点击通过后状态立即变为 1(请求中),需等设备回执:超时→2、失败→3、成功→4。原来把「通过成功」判断为 2 的逻辑必须改成 4
309
+ this.refreshGreetingUnreadMsgCountByPush(data)
310
+ },
311
+ onCmdQwContactInfoChanged: ({ data }) => {
312
+ const contacts = data && (Array.isArray(data.contacts)
313
+ ? data.contacts
314
+ : (data.contactId ? [data] : []))
315
+ if (!contacts || !contacts.length) {
316
+ this.markAccountsModified(data && data.qwAccountIds)
317
+ return
318
+ }
319
+ const tasks = []
320
+ const removedTasks = []
321
+ contacts.forEach(contact => {
322
+ if (!contact) {
323
+ return
324
+ }
325
+ const changeType = Number(contact.changeType)
326
+ if (changeType === 1) {
327
+ tasks.push(this.handleQwContactAdded(contact, data))
328
+ } else if (changeType === 2) {
329
+ tasks.push(this.handleQwContactUpdated(contact))
330
+ } else if (changeType === 3) {
331
+ removedTasks.push(this.handleQwContactRemoved(contact, data))
332
+ }
333
+ })
334
+ return Promise.all(tasks.concat(removedTasks)).then(results => {
335
+ const accountUnreadCountMap = {}
336
+ removedTasks.forEach((task, index) => {
337
+ const result = results[tasks.length + index]
338
+ if (!result || !result.accountId || !result.unreadCount) {
339
+ return
340
+ }
341
+ accountUnreadCountMap[result.accountId] = (accountUnreadCountMap[result.accountId] || 0) + result.unreadCount
342
+ })
343
+ return Promise.all(Object.keys(accountUnreadCountMap).map(accountId => {
344
+ const removedUnreadCount = accountUnreadCountMap[accountId]
345
+ return this.account.updateAccountUnreadMessageNum(accountId, ({ unreadMesasgeNum }) => {
346
+ return Math.max(0, unreadMesasgeNum - removedUnreadCount)
347
+ }).catch(error => {
348
+ console.warn('[client-chat] update account unread count failed', error)
349
+ })
350
+ }))
351
+ })
352
+ },
353
+ onCmdQwRoomInfoChanged: ({ data }) => {
354
+ const rooms = data && (Array.isArray(data.rooms)
355
+ ? data.rooms
356
+ : (data.roomId ? [data] : []))
357
+ if (!rooms || !rooms.length) {
358
+ this.markAccountsModified(data && data.qwAccountIds)
359
+ return
360
+ }
361
+ const tasks = []
362
+ const removedTasks = []
363
+ rooms.forEach(room => {
364
+ if (!room) {
365
+ return
366
+ }
367
+ const changeType = Number(room.changeType)
368
+ if (changeType === 1) {
369
+ tasks.push(this.handleQwRoomAdded(room, data))
370
+ } else if (changeType === 2) {
371
+ tasks.push(this.handleQwRoomUpdated(room))
372
+ } else if (changeType === 3) {
373
+ removedTasks.push(this.handleQwRoomRemoved(room, data))
374
+ }
375
+ })
376
+ return Promise.all(tasks.concat(removedTasks)).then(results => {
377
+ return this.updateRemovedSessionUnreadCounts(
378
+ results.slice(tasks.length)
379
+ )
380
+ })
381
+ },
261
382
  // 接受新消息
262
383
  onCmdQwNewMessage: ({ data }) => {
263
384
  // 插入消息
@@ -279,19 +400,207 @@ class ClientChat {
279
400
  })
280
401
  },
281
402
  onHeartbeatSuccess: ({ data }) => {
282
- if (!data.wq) {
283
- return
284
- }
285
- const onlineMap = data.wq || {}
403
+ const onlineMap = data || {}
286
404
  Object.keys(onlineMap).forEach(k => {
287
405
  this.account.updateAccount(k, {
288
406
  alive: onlineMap[k]
289
- })
407
+ })
290
408
  })
291
409
  }
292
410
  })
293
411
  }
412
+
413
+ getQwAccountCorpId (qwAccountId, corpId) {
414
+ if (corpId || !qwAccountId || !this.account) {
415
+ return corpId
416
+ }
417
+ const account = this.account.getAccountData().find(item => item.id === qwAccountId)
418
+ return account && account.corpId
419
+ }
420
+
421
+ markAccountsModified (qwAccountIds) {
422
+ if (!Array.isArray(qwAccountIds) || !qwAccountIds.length) {
423
+ return
424
+ }
425
+ this.session.markModify(qwAccountIds)
426
+ this.contacts.markModify(qwAccountIds)
427
+ }
428
+
429
+ /**
430
+ * 根据好友请求相关推送刷新待处理好友请求数量
431
+ * 推送里能拿到账号id就只刷该账号,否则刷全部
432
+ */
433
+ refreshGreetingUnreadMsgCountByPush (data) {
434
+ if (!this.account || !this.account.getAccountGreetingUnreadMsgCountMethod) {
435
+ return
436
+ }
437
+ const record = (data && data.record) || data || {}
438
+ const qwAccountId = record.qwAccountId || record.accountId || (data && data.qwAccountId)
439
+ const params = qwAccountId && this.account.accountMap[qwAccountId] ? { qwAccountIds: [qwAccountId] } : undefined
440
+ this.account.getAccountGreetingUnreadMsgCount(params).catch(() => {})
441
+ }
442
+
443
+ updateRemovedSessionUnreadCounts (results) {
444
+ const accountUnreadCountMap = {}
445
+ ;(results || []).forEach(result => {
446
+ if (!result || !result.accountId || !result.unreadCount) {
447
+ return
448
+ }
449
+ accountUnreadCountMap[result.accountId] = (accountUnreadCountMap[result.accountId] || 0) + result.unreadCount
450
+ })
451
+ return Promise.all(Object.keys(accountUnreadCountMap).map(accountId => {
452
+ const removedUnreadCount = accountUnreadCountMap[accountId]
453
+ return this.account.updateAccountUnreadMessageNum(accountId, ({ unreadMesasgeNum }) => {
454
+ return Math.max(0, unreadMesasgeNum - removedUnreadCount)
455
+ }).catch(error => {
456
+ console.warn('[client-chat] update account unread count failed', error)
457
+ })
458
+ }))
459
+ }
460
+
461
+ handleQwContactAdded (contact, eventData) {
462
+ const qwAccountId = contact.qwAccountId || (eventData && eventData.qwAccountId)
463
+ const corpId = this.getQwAccountCorpId(
464
+ qwAccountId,
465
+ contact.corpId || (eventData && eventData.corpId)
466
+ )
467
+ const contactId = contact.contactId
468
+ const accountId = this.getLoginAccountIdMethod ? this.getLoginAccountIdMethod() : qwAccountId
469
+ const sessionId = createSessionId(accountId, contactId)
470
+ if (!sessionId) {
471
+ return Promise.resolve()
472
+ }
473
+ const localSession = this.session.getSessionByLocal(sessionId)
474
+ const oldUnread = localSession ? (localSession.unreadMsgCount || 0) : 0
475
+ return this.session.refreshSession(sessionId).then(rs => {
476
+ const serverSession = rs && rs.data
477
+ const newUnread = serverSession ? (serverSession.unreadMsgCount || 0) : 0
478
+ const accountId = (serverSession && serverSession.qwAccountId) || qwAccountId
479
+ const unreadDiff = newUnread - oldUnread
480
+ if (accountId && unreadDiff) {
481
+ return this.account.updateAccountUnreadMessageNum(accountId, ({ unreadMesasgeNum }) => {
482
+ return Math.max(0, unreadMesasgeNum + unreadDiff)
483
+ })
484
+ }
485
+ }).catch(error => {
486
+ console.warn('[client-chat] refresh added contact session failed', error)
487
+ })
488
+ }
489
+
490
+ handleQwContactUpdated (contact) {
491
+ if (!contact.contactId) {
492
+ return Promise.resolve()
493
+ }
494
+ return this.contacts.refreshFriend(contact.contactId).catch(error => {
495
+ console.warn('[client-chat] refresh contact failed', error)
496
+ })
497
+ }
498
+
499
+ handleQwContactRemoved (contact, eventData) {
500
+ if (!contact.contactId) {
501
+ return Promise.resolve()
502
+ }
503
+ this.contacts.removeFriend(contact.contactId)
504
+ let session = this.session.findSession(({ session }) => {
505
+ return String(session.type) === '0' &&
506
+ session.targetId === contact.contactId &&
507
+ (!contact.qwAccountId || session.qwAccountId === contact.qwAccountId)
508
+ })
509
+ if (!session) {
510
+ const qwAccountId = contact.qwAccountId || (eventData && eventData.qwAccountId)
511
+ const accountId = this.getLoginAccountIdMethod ? this.getLoginAccountIdMethod() : qwAccountId
512
+ const sessionId = createSessionId(
513
+ accountId,
514
+ contact.contactId
515
+ )
516
+ session = sessionId && this.session.getSessionByLocal(sessionId)
517
+ }
518
+ if (!session) {
519
+ return Promise.resolve()
520
+ }
521
+ if (this.session.currentSession && this.session.currentSession.id === session.id) {
522
+ this.session.setCurrentSession(null)
523
+ }
524
+ const accountId = session.qwAccountId || contact.qwAccountId
525
+ const unreadCount = session.unreadMsgCount || 0
526
+ this.session.removeSession(session.id)
527
+ return Promise.resolve({
528
+ accountId,
529
+ unreadCount
530
+ })
531
+ }
294
532
 
533
+ handleQwRoomAdded (room, eventData) {
534
+ if (!room.roomId) {
535
+ return Promise.resolve()
536
+ }
537
+ const qwAccountId = room.qwAccountId || (eventData && eventData.qwAccountId)
538
+ const accountId = this.getLoginAccountIdMethod ? this.getLoginAccountIdMethod() : qwAccountId
539
+ const sessionId = createSessionId(accountId, room.roomId)
540
+ const localSession = sessionId && this.session.getSessionByLocal(sessionId)
541
+ const oldUnread = localSession ? (localSession.unreadMsgCount || 0) : 0
542
+ const tasks = [this.contacts.refreshRoom(room.roomId).catch(error => {
543
+ console.warn('[client-chat] refresh added room failed', error)
544
+ })]
545
+ if (sessionId) {
546
+ tasks.push(this.session.refreshSession(sessionId).then(rs => {
547
+ const serverSession = rs && rs.data
548
+ const unreadDiff = (serverSession ? (serverSession.unreadMsgCount || 0) : 0) - oldUnread
549
+ const changedAccountId = (serverSession && serverSession.qwAccountId) || qwAccountId
550
+ if (changedAccountId && unreadDiff) {
551
+ return this.account.updateAccountUnreadMessageNum(changedAccountId, ({ unreadMesasgeNum }) => {
552
+ return Math.max(0, unreadMesasgeNum + unreadDiff)
553
+ })
554
+ }
555
+ }).catch(error => {
556
+ console.warn('[client-chat] refresh added room session failed', error)
557
+ }))
558
+ }
559
+ return Promise.all(tasks)
560
+ }
561
+
562
+ handleQwRoomUpdated (room) {
563
+ if (!room.roomId) {
564
+ return Promise.resolve()
565
+ }
566
+ return this.contacts.refreshRoom(room.roomId).catch(error => {
567
+ console.warn('[client-chat] refresh room failed', error)
568
+ })
569
+ }
570
+
571
+ handleQwRoomRemoved (room, eventData) {
572
+ if (!room.roomId) {
573
+ return Promise.resolve()
574
+ }
575
+ this.contacts.removeRoom(room.roomId)
576
+ this.event.emit('roomRemoved', {
577
+ roomId: room.roomId
578
+ })
579
+ const qwAccountId = room.qwAccountId || (eventData && eventData.qwAccountId)
580
+ let session = this.session.findSession(({ session }) => {
581
+ return String(session.type) === '1' &&
582
+ session.targetId === room.roomId &&
583
+ (!qwAccountId || session.qwAccountId === qwAccountId)
584
+ })
585
+ if (!session) {
586
+ const accountId = this.getLoginAccountIdMethod ? this.getLoginAccountIdMethod() : qwAccountId
587
+ const sessionId = createSessionId(accountId, room.roomId)
588
+ session = sessionId && this.session.getSessionByLocal(sessionId)
589
+ }
590
+ if (!session) {
591
+ return Promise.resolve()
592
+ }
593
+ if (this.session.currentSession && this.session.currentSession.id === session.id) {
594
+ this.session.setCurrentSession(null)
595
+ }
596
+ const unreadCount = session.unreadMsgCount || 0
597
+ this.session.removeSession(session.id)
598
+ return Promise.resolve({
599
+ accountId: session.qwAccountId || qwAccountId,
600
+ unreadCount
601
+ })
602
+ }
603
+
295
604
  connect () {
296
605
  if (this.data.connectStatus === CONNECT_STATUS.Complete) {
297
606
  return Promise.resolve()
@@ -328,4 +637,4 @@ class ClientChat {
328
637
  }
329
638
  }
330
639
 
331
- export default ClientChat
640
+ export default ClientChat
@@ -13,11 +13,11 @@ export function isUni () {
13
13
  * @param accountId - 客服id
14
14
  * @param targetId - wechatFriendId | wechatChatroomId
15
15
  */
16
- export function createSessionId (corpId, accountId, targetId) {
17
- if (!corpId || !accountId || !targetId) {
16
+ export function createSessionId (accountId, targetId) {
17
+ if (!accountId || !targetId) {
18
18
  return
19
19
  }
20
- return shajs('sha1').update(`${corpId}${accountId}${targetId}`).digest('hex')
20
+ return shajs('sha1').update(`${accountId}${targetId}`).digest('hex')
21
21
  }
22
22
 
23
23
  /**
@@ -54,7 +54,7 @@ export function createSessionId (corpId, accountId, targetId) {
54
54
  * "msgSvrId": "4319123759514541049",
55
55
  * "msgType": 1,
56
56
  * "origin": "0",
57
- * "sendStatus": 0,
57
+ * "status": 0,
58
58
  * "tenantId": "1761952223049924608",
59
59
  * "wechatAccountId": "ad9d9ae2a8be4f27311312cdd4af3549dc8427ef",
60
60
  * "wechatFriendId": "2089efcc7f8f40b00b7f05fa4c6dfd3bb642774d",
@@ -79,4 +79,4 @@ export function createSessionData (message) {
79
79
  wechatAccountId: message.wechatAccountId
80
80
  }
81
81
  return nextSession
82
- }
82
+ }
@@ -1,35 +0,0 @@
1
- <script>
2
- import SdkChatPanelBox from '../../../chat-panel/chat-panel-box'
3
- import { companyCard } from '../../../wework-chat-control'
4
-
5
- export default {
6
- name: 'SdkWeworkChatPanelControlsCompanyCard',
7
- functional: true,
8
- props: {
9
- dir: {
10
- type: String
11
- },
12
- data: {
13
- type: Object,
14
- required: true
15
- },
16
- fetchUserMethod: {
17
- type: Function
18
- }
19
- },
20
- render (h, c) {
21
- const { props } = c
22
- return h(SdkChatPanelBox, {
23
- props: {
24
- dir: props.dir,
25
- data: props.data,
26
- fetchUserMethod: props.fetchUserMethod
27
- }
28
- }, [h(companyCard, {
29
- props: {
30
- data: props.data
31
- }
32
- })])
33
- }
34
- }
35
- </script>
@@ -1,36 +0,0 @@
1
- <script>
2
- import { expression } from '../../../wework-chat-control'
3
- import SdkChatPanelBox from '../../../chat-panel/chat-panel-box'
4
-
5
- export default {
6
- name: 'SdkWeworkChatPanelControlsExpression',
7
- functional: true,
8
- props: {
9
- dir: {
10
- type: String
11
- },
12
- data: {
13
- type: Object,
14
- default: () => ({})
15
- },
16
- fetchUserMethod: {
17
- type: Function
18
- }
19
- },
20
- render (h, c) {
21
- const { props } = c
22
- return h(SdkChatPanelBox, {
23
- props: {
24
- dir: props.dir,
25
- data: props.data,
26
- fetchUserMethod: props.fetchUserMethod
27
- }
28
- }, [h(expression, {
29
- props: {
30
- data: props.data
31
- },
32
- key: c.data.key
33
- })])
34
- }
35
- }
36
- </script>