@aochuang/client-sdk 1.0.371 → 1.0.372

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 (163) hide show
  1. package/common/.DS_Store +0 -0
  2. package/components/.DS_Store +0 -0
  3. package/components/index.js +6 -1
  4. package/components/session-select/session-select-item.vue +8 -9
  5. package/components/wechat-chat-control/.DS_Store +0 -0
  6. package/components/wechat-chat-control/transfer/.DS_Store +0 -0
  7. package/components/wechat-chat-control/url/.DS_Store +0 -0
  8. package/components/wechat-chat-control/voice/.DS_Store +0 -0
  9. package/components/wework-chat-control/channel-card/channel-card.vue +144 -0
  10. package/components/wework-chat-control/channel-live/channel-live.vue +7 -2
  11. package/components/wework-chat-control/company-card/company-card.vue +1 -1
  12. package/components/wework-chat-control/custom-expression/custom-expression.vue +2 -1
  13. package/components/wework-chat-control/file-url/file-url.vue +34 -16
  14. package/components/wework-chat-control/image/image.vue +137 -2
  15. package/components/wework-chat-control/index.js +15 -7
  16. package/components/wework-chat-control/link/.DS_Store +0 -0
  17. package/components/wework-chat-control/location/location.vue +3 -3
  18. package/components/wework-chat-control/merge-message/merge-message-panel.vue +63 -0
  19. package/components/wework-chat-control/merge-message/merge-message.vue +84 -0
  20. package/components/wework-chat-control/merge-message/util.js +59 -0
  21. package/components/wework-chat-control/metting/enterprise-wechat.png +0 -0
  22. package/components/wework-chat-control/metting/meeting-video.svg +4 -0
  23. package/components/wework-chat-control/metting/metting.vue +181 -0
  24. package/components/wework-chat-control/red-envelopes/red-envelopes.vue +3 -2
  25. package/components/wework-chat-control/text/text-default.vue +99 -0
  26. package/components/wework-chat-control/text/text-quote.vue +105 -0
  27. package/components/wework-chat-control/text/text.vue +24 -144
  28. package/components/wework-chat-control/url/url-channel-live.vue +53 -0
  29. package/components/wework-chat-control/url/url-miniprogram.vue +6 -7
  30. package/components/wework-chat-control/url/url.vue +26 -2
  31. package/components/wework-chat-control/util.js +26 -17
  32. package/components/wework-chat-control/video/.DS_Store +0 -0
  33. package/components/wework-chat-control/video/video.vue +10 -2
  34. package/components/wework-chat-control/voice/voice.vue +9 -2
  35. package/components/wework-chat-control/wework-chat-control-config-item.vue +24 -0
  36. package/components/wework-chat-control/wework-chat-control-config-msg.vue +25 -0
  37. package/{uni-components/chat-control/chat-control-config.vue → components/wework-chat-control/wework-chat-control-config.vue} +16 -13
  38. package/components/wework-chat-panel/chat-panel-chat-status/chat-panel-chat-status.vue +73 -0
  39. package/components/wework-chat-panel/chat-panel-item.vue +56 -25
  40. package/components/wework-chat-panel/chat-panel.vue +96 -13
  41. package/package.json +10 -3
  42. package/services/.DS_Store +0 -0
  43. package/services/client-chat/client-chat-wework/client-chat-account.js +84 -1
  44. package/services/client-chat/client-chat-wework/client-chat-concats.js +81 -17
  45. package/services/client-chat/client-chat-wework/client-chat-message.js +45 -5
  46. package/services/client-chat/client-chat-wework/client-chat-session.js +59 -4
  47. package/services/client-chat/client-chat-wework/client-chat-socket.js +13 -1
  48. package/services/client-chat/client-chat-wework/client-chat.js +320 -11
  49. package/services/client-chat/client-chat-wework/utils.js +5 -5
  50. package/components/wework-chat-panel/chat-panel-controls/company-card/company-card.vue +0 -35
  51. package/components/wework-chat-panel/chat-panel-controls/expression/expression.vue +0 -36
  52. package/components/wework-chat-panel/chat-panel-controls/file-url/file-url.vue +0 -35
  53. package/components/wework-chat-panel/chat-panel-controls/image/image.vue +0 -36
  54. package/components/wework-chat-panel/chat-panel-controls/index.js +0 -35
  55. package/components/wework-chat-panel/chat-panel-controls/jx-sys-text/jx-sys-text.vue +0 -28
  56. package/components/wework-chat-panel/chat-panel-controls/link/link.vue +0 -35
  57. package/components/wework-chat-panel/chat-panel-controls/location/location.vue +0 -35
  58. package/components/wework-chat-panel/chat-panel-controls/text/text.vue +0 -43
  59. package/components/wework-chat-panel/chat-panel-controls/unkonw/unkonw.vue +0 -39
  60. package/components/wework-chat-panel/chat-panel-controls/video/video.vue +0 -37
  61. package/components/wework-chat-panel/chat-panel-controls/voice/voice.vue +0 -35
  62. package/uni-common/account-portray/account-portray.vue +0 -51
  63. package/uni-common/account-select/account-select-item.vue +0 -172
  64. package/uni-common/account-select/account-select.vue +0 -252
  65. package/uni-common/all-friend-avatar/all-friend-avatar.vue +0 -49
  66. package/uni-common/friend-avatar/default.svg +0 -1
  67. package/uni-common/friend-avatar/friend-avatar.vue +0 -27
  68. package/uni-common/friend-avatar/index.js +0 -3
  69. package/uni-common/friend-loader/friend-loader.vue +0 -53
  70. package/uni-common/friend-portray/friend-portray.vue +0 -56
  71. package/uni-common/group-avatar/default.svg +0 -1
  72. package/uni-common/group-avatar/group-avatar.vue +0 -18
  73. package/uni-common/group-avatar/index.js +0 -3
  74. package/uni-common/room-avatar/default.svg +0 -6
  75. package/uni-common/room-avatar/index.js +0 -3
  76. package/uni-common/room-avatar/room-avatar.vue +0 -27
  77. package/uni-common/room-loader/room-loader.vue +0 -53
  78. package/uni-common/room-portray/room-portray.vue +0 -56
  79. package/uni-components/chat-control/calling/calling.vue +0 -91
  80. package/uni-components/chat-control/calling/phone-fill.svg +0 -1
  81. package/uni-components/chat-control/calling/vidicon-fill.svg +0 -1
  82. package/uni-components/chat-control/channel-video/channel-video.vue +0 -89
  83. package/uni-components/chat-control/channel-video-card/channel-video-card.vue +0 -105
  84. package/uni-components/chat-control/channel-video-live/channel-video-live.vue +0 -92
  85. package/uni-components/chat-control/chat-control-config-item/chat-control-config-item.vue +0 -20
  86. package/uni-components/chat-control/chat-control-config-item/index.js +0 -3
  87. package/uni-components/chat-control/chat-control-config-msg/chat-control-config-msg-app.vue +0 -25
  88. package/uni-components/chat-control/chat-control-config-msg/chat-control-config-msg-h5.vue +0 -21
  89. package/uni-components/chat-control/chat-control.vue +0 -218
  90. package/uni-components/chat-control/company-card/company-card.vue +0 -123
  91. package/uni-components/chat-control/const.js +0 -28
  92. package/uni-components/chat-control/expression/expression.vue +0 -41
  93. package/uni-components/chat-control/image/image.vue +0 -68
  94. package/uni-components/chat-control/index.js +0 -89
  95. package/uni-components/chat-control/location/location.vue +0 -110
  96. package/uni-components/chat-control/member-change/member-change.vue +0 -32
  97. package/uni-components/chat-control/quote-message/quote-message.vue +0 -216
  98. package/uni-components/chat-control/real-time-position/real-time-position.vue +0 -62
  99. package/uni-components/chat-control/redpacket/red-envelope.svg +0 -1
  100. package/uni-components/chat-control/redpacket/redpacket.vue +0 -75
  101. package/uni-components/chat-control/share-card/share-card.vue +0 -101
  102. package/uni-components/chat-control/system/system.vue +0 -69
  103. package/uni-components/chat-control/system-batch-message/system-batch-message.vue +0 -30
  104. package/uni-components/chat-control/system-text/system-text.vue +0 -32
  105. package/uni-components/chat-control/text/text.vue +0 -67
  106. package/uni-components/chat-control/text-with-at/text-with-at.vue +0 -51
  107. package/uni-components/chat-control/transfer/red-transfer.svg +0 -1
  108. package/uni-components/chat-control/transfer/transfer.vue +0 -80
  109. package/uni-components/chat-control/unkonw/unkonw.vue +0 -37
  110. package/uni-components/chat-control/url/icons/file-excel-line.svg +0 -1
  111. package/uni-components/chat-control/url/icons/file-info-line.svg +0 -1
  112. package/uni-components/chat-control/url/icons/file-music-line.svg +0 -1
  113. package/uni-components/chat-control/url/icons/file-pdf-line.svg +0 -1
  114. package/uni-components/chat-control/url/icons/file-ppt-line.svg +0 -1
  115. package/uni-components/chat-control/url/icons/file-settings-line.svg +0 -1
  116. package/uni-components/chat-control/url/icons/file-text-line.svg +0 -1
  117. package/uni-components/chat-control/url/icons/file-unknow-line.svg +0 -1
  118. package/uni-components/chat-control/url/icons/file-word-line.svg +0 -1
  119. package/uni-components/chat-control/url/icons/file-zip-line.svg +0 -1
  120. package/uni-components/chat-control/url/icons/index.js +0 -24
  121. package/uni-components/chat-control/url/miniprogram.svg +0 -1
  122. package/uni-components/chat-control/url/url-miniprogram.vue +0 -116
  123. package/uni-components/chat-control/url/url.vue +0 -306
  124. package/uni-components/chat-control/url-new/icons/file-excel-line.svg +0 -1
  125. package/uni-components/chat-control/url-new/icons/file-info-line.svg +0 -1
  126. package/uni-components/chat-control/url-new/icons/file-music-line.svg +0 -1
  127. package/uni-components/chat-control/url-new/icons/file-pdf-line.svg +0 -1
  128. package/uni-components/chat-control/url-new/icons/file-ppt-line.svg +0 -1
  129. package/uni-components/chat-control/url-new/icons/file-settings-line.svg +0 -1
  130. package/uni-components/chat-control/url-new/icons/file-text-line.svg +0 -1
  131. package/uni-components/chat-control/url-new/icons/file-unknow-line.svg +0 -1
  132. package/uni-components/chat-control/url-new/icons/file-word-line.svg +0 -1
  133. package/uni-components/chat-control/url-new/icons/file-zip-line.svg +0 -1
  134. package/uni-components/chat-control/url-new/icons/index.js +0 -24
  135. package/uni-components/chat-control/url-new/url-new.vue +0 -110
  136. package/uni-components/chat-control/utils.js +0 -12
  137. package/uni-components/chat-control/video/video.vue +0 -156
  138. package/uni-components/chat-control/voice/voice.vue +0 -166
  139. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet-collect.vue +0 -84
  140. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet-system.vue +0 -28
  141. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet.vue +0 -85
  142. package/uni-components/chat-editor/chat-editor-func/chat-editor-func.vue +0 -157
  143. package/uni-components/chat-editor/chat-editor-func-at/chat-editor-func-at-panel.vue +0 -158
  144. package/uni-components/chat-editor/chat-editor-func-at/chat-editor-func-at.vue +0 -61
  145. package/uni-components/chat-editor/chat-editor-func-button/chat-editor-func-button.vue +0 -58
  146. package/uni-components/chat-editor/chat-editor-func-file/chat-editor-func-file.vue +0 -54
  147. package/uni-components/chat-editor/chat-editor-func-image/chat-editor-func-image.vue +0 -42
  148. package/uni-components/chat-editor/chat-editor-func-video/chat-editor-func-video.vue +0 -42
  149. package/uni-components/chat-editor/chat-editor-func-voice/chat-editor-func-voice.vue +0 -25
  150. package/uni-components/chat-editor/chat-editor-message-send/chat-editor-message-send.vue +0 -158
  151. package/uni-components/chat-editor/chat-editor-quote/chat-editor-quote.vue +0 -75
  152. package/uni-components/chat-editor/chat-editor.vue +0 -257
  153. package/uni-components/chat-editor/index.js +0 -10
  154. package/uni-components/chat-editor/util.js +0 -65
  155. package/uni-components/chat-panel/chat-panel-chats-box.vue +0 -238
  156. package/uni-components/chat-panel/chat-panel-chats-forward/chat-panel-chats-forward.vue +0 -273
  157. package/uni-components/chat-panel/chat-panel-chats-item.vue +0 -578
  158. package/uni-components/chat-panel/chat-panel-chats-status/chat-panel-chats-status.vue +0 -71
  159. package/uni-components/chat-panel/chat-panel-chats.vue +0 -368
  160. package/uni-components/chat-panel/chat-panel.vue +0 -227
  161. package/uni-components/contacts-group-select/contacts-group-select-item.vue +0 -85
  162. package/uni-components/contacts-group-select/contacts-group-select-panel.vue +0 -119
  163. package/uni-components/contacts-group-select/contacts-group-select.vue +0 -150
@@ -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>
@@ -1,35 +0,0 @@
1
- <script>
2
- import SdkChatPanelBox from '../../../chat-panel/chat-panel-box'
3
- import { fileUrl } from '../../../wework-chat-control'
4
-
5
- export default {
6
- name: 'SdkWeworkChatPanelControlsFileUrl',
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(fileUrl, {
29
- props: {
30
- content: props.data.content
31
- }
32
- })])
33
- }
34
- }
35
- </script>
@@ -1,36 +0,0 @@
1
- <script>
2
- import { image } from '../../../wework-chat-control'
3
- import SdkChatPanelBox from '../../../chat-panel/chat-panel-box'
4
-
5
- export default {
6
- name: 'SdkWeworkChatPanelControlsImage',
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(image, {
29
- props: {
30
- data: props.data
31
- },
32
- key: c.data.key
33
- })])
34
- }
35
- }
36
- </script>
@@ -1,35 +0,0 @@
1
- import text from './text/text.vue'
2
- import link from './link/link.vue'
3
- import companyCard from './company-card/company-card.vue'
4
- import video from './video/video.vue'
5
- import image from './image/image.vue'
6
- import unkonw from './unkonw/unkonw.vue'
7
- import expression from './expression/expression.vue'
8
- import voice from './voice/voice.vue'
9
- import jxSysText from './jx-sys-text/jx-sys-text.vue'
10
- import fileUrl from './file-url/file-url.vue'
11
- import location from './location/location.vue'
12
-
13
- export default {
14
- 0: text,
15
- 2: text,
16
- 14: image,
17
- 101: image,
18
- // '49': link,
19
- 22: video,
20
- 23: video,
21
- 103: video,
22
- 29: expression,
23
- 104: expression,
24
- 16: voice,
25
- 40: voice,
26
- 1011: jxSysText,
27
- 1022: jxSysText,
28
- 41: companyCard,
29
- 13: fileUrl,
30
- 15: fileUrl,
31
- 20: fileUrl,
32
- 102: fileUrl,
33
- 6: location,
34
- unkonw
35
- }
@@ -1,28 +0,0 @@
1
- <script>
2
- import { jxSysText } from '../../../wework-chat-control'
3
-
4
- export default {
5
- name: 'SdkWeworkChatPanelControlsJxSysText',
6
- functional: true,
7
- props: {
8
- dir: {
9
- type: String
10
- },
11
- data: {
12
- type: Object,
13
- required: true
14
- },
15
- fetchUserMethod: {
16
- type: Function
17
- }
18
- },
19
- render (h, c) {
20
- const { props } = c
21
- return h(jxSysText, {
22
- props: {
23
- content: props.data.content
24
- }
25
- })
26
- }
27
- }
28
- </script>