@aochuang/client-sdk 1.0.363 → 1.0.364

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 (168) hide show
  1. package/components/index.js +1 -6
  2. package/components/layout/layout.vue +4 -1
  3. package/components/session-select/session-select-item.vue +9 -8
  4. package/components/wechat-chat-control/image/image.vue +8 -13
  5. package/components/wechat-chat-control/url/url-miniprogram.vue +5 -1
  6. package/components/wework-chat-control/channel-live/channel-live.vue +2 -7
  7. package/components/wework-chat-control/company-card/company-card.vue +1 -1
  8. package/components/wework-chat-control/custom-expression/custom-expression.vue +1 -2
  9. package/components/wework-chat-control/file-url/file-url.vue +16 -34
  10. package/components/wework-chat-control/image/image.vue +2 -137
  11. package/components/wework-chat-control/index.js +7 -15
  12. package/components/wework-chat-control/location/location.vue +3 -3
  13. package/components/wework-chat-control/red-envelopes/red-envelopes.vue +2 -3
  14. package/components/wework-chat-control/text/text.vue +144 -24
  15. package/components/wework-chat-control/url/url-miniprogram.vue +7 -6
  16. package/components/wework-chat-control/url/url.vue +2 -26
  17. package/components/wework-chat-control/util.js +17 -26
  18. package/components/wework-chat-control/video/video.vue +2 -10
  19. package/components/wework-chat-control/voice/voice.vue +2 -9
  20. package/components/wework-chat-panel/chat-panel-controls/company-card/company-card.vue +35 -0
  21. package/components/wework-chat-panel/chat-panel-controls/expression/expression.vue +36 -0
  22. package/components/wework-chat-panel/chat-panel-controls/file-url/file-url.vue +35 -0
  23. package/components/wework-chat-panel/chat-panel-controls/image/image.vue +36 -0
  24. package/components/wework-chat-panel/chat-panel-controls/index.js +35 -0
  25. package/components/wework-chat-panel/chat-panel-controls/jx-sys-text/jx-sys-text.vue +28 -0
  26. package/components/wework-chat-panel/chat-panel-controls/link/link.vue +35 -0
  27. package/components/wework-chat-panel/chat-panel-controls/location/location.vue +35 -0
  28. package/components/wework-chat-panel/chat-panel-controls/text/text.vue +43 -0
  29. package/components/wework-chat-panel/chat-panel-controls/unkonw/unkonw.vue +39 -0
  30. package/components/wework-chat-panel/chat-panel-controls/video/video.vue +37 -0
  31. package/components/wework-chat-panel/chat-panel-controls/voice/voice.vue +35 -0
  32. package/components/wework-chat-panel/chat-panel-item.vue +25 -56
  33. package/components/wework-chat-panel/chat-panel.vue +13 -96
  34. package/package.json +3 -10
  35. package/services/client-chat/client-chat-wechat/client-chat-session.js +196 -92
  36. package/services/client-chat/client-chat-wechat/client-chat.js +20 -33
  37. package/services/client-chat/client-chat-wework/client-chat-account.js +1 -84
  38. package/services/client-chat/client-chat-wework/client-chat-concats.js +17 -81
  39. package/services/client-chat/client-chat-wework/client-chat-message.js +5 -45
  40. package/services/client-chat/client-chat-wework/client-chat-session.js +4 -59
  41. package/services/client-chat/client-chat-wework/client-chat-socket.js +1 -13
  42. package/services/client-chat/client-chat-wework/client-chat.js +11 -320
  43. package/services/client-chat/client-chat-wework/utils.js +5 -5
  44. package/uni-common/account-portray/account-portray.vue +51 -0
  45. package/uni-common/account-select/account-select-item.vue +172 -0
  46. package/uni-common/account-select/account-select.vue +252 -0
  47. package/uni-common/all-friend-avatar/all-friend-avatar.vue +49 -0
  48. package/uni-common/friend-avatar/default.svg +1 -0
  49. package/uni-common/friend-avatar/friend-avatar.vue +27 -0
  50. package/uni-common/friend-avatar/index.js +3 -0
  51. package/uni-common/friend-loader/friend-loader.vue +53 -0
  52. package/uni-common/friend-portray/friend-portray.vue +56 -0
  53. package/uni-common/group-avatar/default.svg +1 -0
  54. package/uni-common/group-avatar/group-avatar.vue +18 -0
  55. package/uni-common/group-avatar/index.js +3 -0
  56. package/uni-common/room-avatar/default.svg +6 -0
  57. package/uni-common/room-avatar/index.js +3 -0
  58. package/uni-common/room-avatar/room-avatar.vue +27 -0
  59. package/uni-common/room-loader/room-loader.vue +53 -0
  60. package/uni-common/room-portray/room-portray.vue +56 -0
  61. package/uni-components/chat-control/calling/calling.vue +91 -0
  62. package/uni-components/chat-control/calling/phone-fill.svg +1 -0
  63. package/uni-components/chat-control/calling/vidicon-fill.svg +1 -0
  64. package/uni-components/chat-control/channel-video/channel-video.vue +89 -0
  65. package/uni-components/chat-control/channel-video-card/channel-video-card.vue +105 -0
  66. package/uni-components/chat-control/channel-video-live/channel-video-live.vue +92 -0
  67. package/uni-components/chat-control/chat-control-config-item/chat-control-config-item.vue +20 -0
  68. package/uni-components/chat-control/chat-control-config-item/index.js +3 -0
  69. package/uni-components/chat-control/chat-control-config-msg/chat-control-config-msg-app.vue +25 -0
  70. package/uni-components/chat-control/chat-control-config-msg/chat-control-config-msg-h5.vue +21 -0
  71. package/{components/wework-chat-control/wework-chat-control-config.vue → uni-components/chat-control/chat-control-config.vue} +13 -16
  72. package/uni-components/chat-control/chat-control.vue +218 -0
  73. package/uni-components/chat-control/company-card/company-card.vue +123 -0
  74. package/uni-components/chat-control/const.js +28 -0
  75. package/uni-components/chat-control/expression/expression.vue +41 -0
  76. package/uni-components/chat-control/image/image.vue +68 -0
  77. package/uni-components/chat-control/index.js +89 -0
  78. package/uni-components/chat-control/location/location.vue +110 -0
  79. package/uni-components/chat-control/member-change/member-change.vue +32 -0
  80. package/uni-components/chat-control/quote-message/quote-message.vue +216 -0
  81. package/uni-components/chat-control/real-time-position/real-time-position.vue +62 -0
  82. package/uni-components/chat-control/redpacket/red-envelope.svg +1 -0
  83. package/uni-components/chat-control/redpacket/redpacket.vue +75 -0
  84. package/uni-components/chat-control/share-card/share-card.vue +101 -0
  85. package/uni-components/chat-control/system/system.vue +69 -0
  86. package/uni-components/chat-control/system-batch-message/system-batch-message.vue +30 -0
  87. package/uni-components/chat-control/system-text/system-text.vue +32 -0
  88. package/uni-components/chat-control/text/text.vue +67 -0
  89. package/uni-components/chat-control/text-with-at/text-with-at.vue +51 -0
  90. package/uni-components/chat-control/transfer/red-transfer.svg +1 -0
  91. package/uni-components/chat-control/transfer/transfer.vue +80 -0
  92. package/uni-components/chat-control/unkonw/unkonw.vue +37 -0
  93. package/uni-components/chat-control/url/icons/file-excel-line.svg +1 -0
  94. package/uni-components/chat-control/url/icons/file-info-line.svg +1 -0
  95. package/uni-components/chat-control/url/icons/file-music-line.svg +1 -0
  96. package/uni-components/chat-control/url/icons/file-pdf-line.svg +1 -0
  97. package/uni-components/chat-control/url/icons/file-ppt-line.svg +1 -0
  98. package/uni-components/chat-control/url/icons/file-settings-line.svg +1 -0
  99. package/uni-components/chat-control/url/icons/file-text-line.svg +1 -0
  100. package/uni-components/chat-control/url/icons/file-unknow-line.svg +1 -0
  101. package/uni-components/chat-control/url/icons/file-word-line.svg +1 -0
  102. package/uni-components/chat-control/url/icons/file-zip-line.svg +1 -0
  103. package/uni-components/chat-control/url/icons/index.js +24 -0
  104. package/uni-components/chat-control/url/miniprogram.svg +1 -0
  105. package/uni-components/chat-control/url/url-miniprogram.vue +116 -0
  106. package/uni-components/chat-control/url/url.vue +306 -0
  107. package/uni-components/chat-control/url-new/icons/file-excel-line.svg +1 -0
  108. package/uni-components/chat-control/url-new/icons/file-info-line.svg +1 -0
  109. package/uni-components/chat-control/url-new/icons/file-music-line.svg +1 -0
  110. package/uni-components/chat-control/url-new/icons/file-pdf-line.svg +1 -0
  111. package/uni-components/chat-control/url-new/icons/file-ppt-line.svg +1 -0
  112. package/uni-components/chat-control/url-new/icons/file-settings-line.svg +1 -0
  113. package/uni-components/chat-control/url-new/icons/file-text-line.svg +1 -0
  114. package/uni-components/chat-control/url-new/icons/file-unknow-line.svg +1 -0
  115. package/uni-components/chat-control/url-new/icons/file-word-line.svg +1 -0
  116. package/uni-components/chat-control/url-new/icons/file-zip-line.svg +1 -0
  117. package/uni-components/chat-control/url-new/icons/index.js +24 -0
  118. package/uni-components/chat-control/url-new/url-new.vue +110 -0
  119. package/uni-components/chat-control/utils.js +12 -0
  120. package/uni-components/chat-control/video/video.vue +156 -0
  121. package/uni-components/chat-control/voice/voice.vue +166 -0
  122. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet-collect.vue +84 -0
  123. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet-system.vue +28 -0
  124. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet.vue +85 -0
  125. package/uni-components/chat-editor/chat-editor-func/chat-editor-func.vue +157 -0
  126. package/uni-components/chat-editor/chat-editor-func-at/chat-editor-func-at-panel.vue +158 -0
  127. package/uni-components/chat-editor/chat-editor-func-at/chat-editor-func-at.vue +61 -0
  128. package/uni-components/chat-editor/chat-editor-func-button/chat-editor-func-button.vue +58 -0
  129. package/uni-components/chat-editor/chat-editor-func-file/chat-editor-func-file.vue +54 -0
  130. package/uni-components/chat-editor/chat-editor-func-image/chat-editor-func-image.vue +42 -0
  131. package/uni-components/chat-editor/chat-editor-func-video/chat-editor-func-video.vue +42 -0
  132. package/uni-components/chat-editor/chat-editor-func-voice/chat-editor-func-voice.vue +25 -0
  133. package/uni-components/chat-editor/chat-editor-message-send/chat-editor-message-send.vue +158 -0
  134. package/uni-components/chat-editor/chat-editor-quote/chat-editor-quote.vue +75 -0
  135. package/uni-components/chat-editor/chat-editor.vue +257 -0
  136. package/uni-components/chat-editor/index.js +10 -0
  137. package/uni-components/chat-editor/util.js +65 -0
  138. package/uni-components/chat-panel/chat-panel-chats-box.vue +238 -0
  139. package/uni-components/chat-panel/chat-panel-chats-forward/chat-panel-chats-forward.vue +273 -0
  140. package/uni-components/chat-panel/chat-panel-chats-item.vue +578 -0
  141. package/uni-components/chat-panel/chat-panel-chats-status/chat-panel-chats-status.vue +71 -0
  142. package/uni-components/chat-panel/chat-panel-chats.vue +368 -0
  143. package/uni-components/chat-panel/chat-panel.vue +227 -0
  144. package/uni-components/contacts-group-select/contacts-group-select-item.vue +85 -0
  145. package/uni-components/contacts-group-select/contacts-group-select-panel.vue +119 -0
  146. package/uni-components/contacts-group-select/contacts-group-select.vue +150 -0
  147. package/common/.DS_Store +0 -0
  148. package/components/.DS_Store +0 -0
  149. package/components/wechat-chat-control/.DS_Store +0 -0
  150. package/components/wechat-chat-control/transfer/.DS_Store +0 -0
  151. package/components/wechat-chat-control/url/.DS_Store +0 -0
  152. package/components/wechat-chat-control/voice/.DS_Store +0 -0
  153. package/components/wework-chat-control/channel-card/channel-card.vue +0 -144
  154. package/components/wework-chat-control/link/.DS_Store +0 -0
  155. package/components/wework-chat-control/merge-message/merge-message-panel.vue +0 -63
  156. package/components/wework-chat-control/merge-message/merge-message.vue +0 -84
  157. package/components/wework-chat-control/merge-message/util.js +0 -59
  158. package/components/wework-chat-control/metting/enterprise-wechat.png +0 -0
  159. package/components/wework-chat-control/metting/meeting-video.svg +0 -4
  160. package/components/wework-chat-control/metting/metting.vue +0 -181
  161. package/components/wework-chat-control/text/text-default.vue +0 -99
  162. package/components/wework-chat-control/text/text-quote.vue +0 -105
  163. package/components/wework-chat-control/url/url-channel-live.vue +0 -53
  164. package/components/wework-chat-control/video/.DS_Store +0 -0
  165. package/components/wework-chat-control/wework-chat-control-config-item.vue +0 -24
  166. package/components/wework-chat-control/wework-chat-control-config-msg.vue +0 -25
  167. package/components/wework-chat-panel/chat-panel-chat-status/chat-panel-chat-status.vue +0 -73
  168. package/services/.DS_Store +0 -0
@@ -228,50 +228,40 @@ export default class ClientChatSession {
228
228
  })
229
229
  }
230
230
 
231
- getSession (sessionId, serializeMethod, callback = null, isCache = true) {
232
- if (typeof callback === 'boolean') {
233
- isCache = callback
234
- callback = null
235
- }
231
+ getSession (sessionId, serializeMethod) {
236
232
  if (this.sessionMap[sessionId]) {
237
233
  return Promise.resolve({
238
234
  data: this.sessionMap[sessionId]
239
235
  })
240
236
  }
241
237
  // 这里需要轮询从后端获取会话,后端会话更新和创建是异步的,所以要多轮训请求几次
242
- if (this.pollRequestMap[sessionId]) {
243
- // 因为有的地方要复用缓存,有的地方不能缓存,比如onAddMessagSuccess的时候不能缓存
244
- if (isCache) {
245
- return this.pollRequestMap[sessionId].ps
246
- } else {
247
- this.pollRequestMap[sessionId].stop()
248
- }
249
- }
250
- const pollRequest = createPollRequest(({ done, fail }) => {
251
- return this.getSessionMethod({
252
- id: sessionId
253
- }).then((rs) => {
238
+ if (!this.pollRequestMap[sessionId] || !this.pollRequestMap[sessionId].ps) {
239
+ const pollRequest = createPollRequest(({ done, fail }) => {
240
+ return this.getSessionMethod({
241
+ id: sessionId
242
+ }).then((rs) => {
243
+ if (rs.data) {
244
+ done(rs)
245
+ }
246
+ })
247
+ })
248
+ this.pollRequestMap[sessionId] = pollRequest
249
+ this.pollRequestMap[sessionId].ps = pollRequest.start().then(rs => {
250
+ if (serializeMethod) {
251
+ rs = serializeMethod(rs)
252
+ }
254
253
  if (rs.data) {
255
- done(rs)
254
+ this.addSession(rs.data, null)
255
+ return rs
256
+ } else {
257
+ return Promise.reject('未找到会话' + sessionId)
258
+ }
259
+ }).finally(() => {
260
+ if (this.pollRequestMap[sessionId] === pollRequest) {
261
+ delete this.pollRequestMap[sessionId]
256
262
  }
257
263
  })
258
- })
259
- this.pollRequestMap[sessionId] = pollRequest
260
- this.pollRequestMap[sessionId].ps = pollRequest.start().then(rs => {
261
- if (serializeMethod) {
262
- rs = serializeMethod(rs)
263
- }
264
- if (rs.data) {
265
- this.addSession(rs.data, null, callback)
266
- return rs
267
- } else {
268
- return Promise.reject('未找到会话' + sessionId)
269
- }
270
- }).finally(() => {
271
- if (this.pollRequestMap[sessionId] === pollRequest) {
272
- delete this.pollRequestMap[sessionId]
273
- }
274
- })
264
+ }
275
265
  return this.pollRequestMap[sessionId].ps
276
266
  }
277
267
 
@@ -397,7 +387,7 @@ export default class ClientChatSession {
397
387
  * "wechatAccountId": "2a39a725814acf07502299ab2285fff8d44377f5"
398
388
  * }
399
389
  */
400
- addSession (data, wechatAccountId, callback) {
390
+ addSession (data, wechatAccountId) {
401
391
  if (!data || !data.conversationId) {
402
392
  throw new Error('缺少必须参数conversationId')
403
393
  }
@@ -412,56 +402,53 @@ export default class ClientChatSession {
412
402
  }) === false) {
413
403
  return
414
404
  }
415
- let nextData = data
405
+ if (wechatAccountId && wechatAccountId !== ALL_WECHAT_ACCOUNT_ID && data.wechatAccountId !== wechatAccountId) {
406
+ throw new Error('会话的wechatAccount和加载分组的wechatAccountId不一致')
407
+ }
408
+ let nextData = null
409
+ let isRefreshAll = false
410
+ let groupIds = []
416
411
  // 如果会话已经存在,那么取已经存在的,以后有需要可以用data更新已经存在的会话,保持引用关系
412
+ // 一般比较容易出现,例如all的时候,分配的时候有可能会出现,例如以前的会话没有正确删除,后面有分配过来了
417
413
  if (this.sessionMap[data.conversationId]) {
414
+ // 如果会话比较老,就不更新属性
415
+ if (this.sessionMap[data.conversationId].lastMsgTime && data.lastMsgTime && this.sessionMap[data.conversationId].lastMsgTime <= data.lastMsgTime) {
416
+ // 先删后插
417
+ this._removeSessionBySessionGroup(this.sessionMap[data.conversationId].conversationId)
418
+ // 更新属性
419
+ Object.keys(data).forEach(k => {
420
+ Vue.set(this.sessionMap[data.conversationId], k, data[k])
421
+ })
422
+ }
418
423
  nextData = this.sessionMap[data.conversationId]
424
+ isRefreshAll = true
419
425
  } else {
420
- this.sessionMap[data.conversationId] = nextData
426
+ nextData = data
421
427
  }
422
- const topField = nextData.stickyOnTop ? 0 : 1 // 置顶
423
- if (wechatAccountId && wechatAccountId !== ALL_WECHAT_ACCOUNT_ID && nextData.wechatAccountId !== wechatAccountId) {
424
- throw new Error('会话的wechatAccount和加载分组的wechatAccountId不一致')
428
+ if (!nextData) {
429
+ return
425
430
  }
426
- const groupIds = []
427
- // 传了wechatAccountId,是分页加载的,这里要保持分页加载数据的链路不受动态加载的影响
428
431
  if (wechatAccountId) {
429
- groupIds.push(wechatAccountId)
430
- // 传了wechatAccountId才记录lastMsgTime和lastUpdateTime
431
- const lastFields = ['lastMsgTime', 'lastUpdateTime']
432
- groupIds.forEach(groupId => {
433
- lastFields.forEach(lastField => {
434
- const lastUpdateSortFields = this.getSortField(nextData[lastField])
435
- if (!lastUpdateSortFields) {
436
- return
437
- }
438
- if (!this._lastUpdateSessionMap) {
439
- this._lastUpdateSessionMap = {}
440
- }
441
- if (!this._lastUpdateSessionMap[groupId]) {
442
- this._lastUpdateSessionMap[groupId] = {}
443
- }
444
- if (!this._lastUpdateSessionMap[groupId][lastField]) {
445
- this._lastUpdateSessionMap[groupId][lastField] = {}
446
- }
447
- if (!this._lastUpdateSessionMap[groupId][lastField][topField]) {
448
- this._lastUpdateSessionMap[groupId][lastField][topField] = {}
449
- }
450
- if (!this._lastUpdateSessionMap[groupId][lastField][topField][lastUpdateSortFields.day]) {
451
- this._lastUpdateSessionMap[groupId][lastField][topField][lastUpdateSortFields.day] = {}
452
- }
453
- if (!this._lastUpdateSessionMap[groupId][lastField][topField][lastUpdateSortFields.day][lastUpdateSortFields.milliseconds]) {
454
- this._lastUpdateSessionMap[groupId][lastField][topField][lastUpdateSortFields.day][lastUpdateSortFields.milliseconds] = []
455
- }
456
- this._lastUpdateSessionMap[groupId][lastField][topField][lastUpdateSortFields.day][lastUpdateSortFields.milliseconds].push(nextData)
457
- })
458
- })
432
+ // 传了wechatAccountId,是分页加载的,这里要保持分页加载数据的链路不受动态加载的影响
433
+ // 加载会话是新的在上面,老的在下面,所以一定要记录好上次分页加载的时间点
434
+ if (isRefreshAll) {
435
+ groupIds.push(nextData.wechatAccountId)
436
+ groupIds.push(ALL_WECHAT_ACCOUNT_ID)
437
+ } else {
438
+ groupIds.push(wechatAccountId)
439
+ }
440
+ // 先把老的删除掉
441
+ this._removeLastUpdateSessionMap(nextData.conversationId, wechatAccountId)
442
+ // 再插入新的
443
+ this._updateLastUpdateSessionMap([wechatAccountId], nextData)
459
444
  } else {
460
445
  groupIds.push(nextData.wechatAccountId)
461
446
  groupIds.push(ALL_WECHAT_ACCOUNT_ID)
462
447
  }
448
+ this.sessionMap[data.conversationId] = nextData
463
449
  // 分组的
464
450
  const sortFields = this.getSortField(nextData.lastMsgTime)
451
+ const topField = nextData.stickyOnTop ? 0 : 1 // 置顶
465
452
  groupIds.forEach(groupId => {
466
453
  // 如果已经在分组里面了,就不新增了,
467
454
  if (this._getSessionBySessionGroup(nextData.conversationId, groupId)) {
@@ -492,21 +479,62 @@ export default class ClientChatSession {
492
479
  Vue.set(this.data.sessionMuteMap, nextData.wechatAccountId, {})
493
480
  }
494
481
  Vue.set(this.data.sessionMuteMap[nextData.wechatAccountId], nextData.conversationId, nextData)
482
+ } else {
483
+ if (this.data.sessionMuteMap[nextData.wechatAccountId]) {
484
+ Vue.delete(this.data.sessionMuteMap[nextData.wechatAccountId], nextData.conversationId)
485
+ }
495
486
  }
496
487
  // 检测一下是不是存在一样的虚拟会话,存在的话就删除
497
488
  const virtualSessionIndex = this.data.virtualSessionData.findIndex(v => v.conversationId === nextData.conversationId)
498
489
  if (virtualSessionIndex > -1) {
499
490
  this.data.virtualSessionData.splice(virtualSessionIndex, 1)
500
491
  }
501
- callback && callback({
502
- session: data
503
- })
504
492
  this.onAddSession && this.onAddSession({
505
- session: data
493
+ wechatAccountId,
494
+ session: nextData
506
495
  })
507
496
  }
508
-
509
- removeSession (conversationId) {
497
+
498
+ _updateLastUpdateSessionMap (groupIds, nextData) {
499
+ if (!groupIds || !groupIds.length || !nextData) {
500
+ return
501
+ }
502
+ // 传了wechatAccountId才记录lastMsgTime
503
+ const lastFields = ['lastMsgTime']
504
+ const topField = nextData.stickyOnTop ? 0 : 1 // 置顶
505
+ groupIds.forEach(groupId => {
506
+ lastFields.forEach(lastField => {
507
+ const lastUpdateSortFields = this.getSortField(nextData[lastField])
508
+ if (!lastUpdateSortFields) {
509
+ return
510
+ }
511
+ if (!this._lastUpdateSessionMap) {
512
+ this._lastUpdateSessionMap = {}
513
+ }
514
+ if (!this._lastUpdateSessionMap[groupId]) {
515
+ this._lastUpdateSessionMap[groupId] = {}
516
+ }
517
+ if (!this._lastUpdateSessionMap[groupId][lastField]) {
518
+ this._lastUpdateSessionMap[groupId][lastField] = {}
519
+ }
520
+ if (!this._lastUpdateSessionMap[groupId][lastField][topField]) {
521
+ this._lastUpdateSessionMap[groupId][lastField][topField] = {}
522
+ }
523
+ if (!this._lastUpdateSessionMap[groupId][lastField][topField][lastUpdateSortFields.day]) {
524
+ this._lastUpdateSessionMap[groupId][lastField][topField][lastUpdateSortFields.day] = {}
525
+ }
526
+ if (!this._lastUpdateSessionMap[groupId][lastField][topField][lastUpdateSortFields.day][lastUpdateSortFields.milliseconds]) {
527
+ this._lastUpdateSessionMap[groupId][lastField][topField][lastUpdateSortFields.day][lastUpdateSortFields.milliseconds] = []
528
+ }
529
+ this._lastUpdateSessionMap[groupId][lastField][topField][lastUpdateSortFields.day][lastUpdateSortFields.milliseconds].push({
530
+ conversationId: nextData.conversationId,
531
+ lastMsgTime: nextData.lastMsgTime
532
+ })
533
+ })
534
+ })
535
+ }
536
+
537
+ _removeSessionBySessionGroup (conversationId, wechatAccountId) {
510
538
  if (!this.sessionMap[conversationId]) {
511
539
  return
512
540
  }
@@ -515,7 +543,7 @@ export default class ClientChatSession {
515
543
  return
516
544
  }
517
545
  const topField = session.stickyOnTop ? 0 : 1 // 置顶
518
- const groupIds = [session.wechatAccountId, ALL_WECHAT_ACCOUNT_ID]
546
+ const groupIds = wechatAccountId ? [wechatAccountId] : [session.wechatAccountId, ALL_WECHAT_ACCOUNT_ID]
519
547
  const sortFields = this.getSortField(session.lastMsgTime)
520
548
  groupIds.forEach(groupId => {
521
549
  if (!this.data.sessionGroupData[groupId] || !this.data.sessionGroupData[groupId][topField]) {
@@ -523,7 +551,7 @@ export default class ClientChatSession {
523
551
  }
524
552
  const groupSession = this.data.sessionGroupData[groupId][topField]
525
553
  if (groupSession[sortFields.day] && groupSession[sortFields.day][sortFields.milliseconds]) {
526
- const groupIndex = groupSession[sortFields.day][sortFields.milliseconds].indexOf(this.sessionMap[conversationId])
554
+ const groupIndex = groupSession[sortFields.day][sortFields.milliseconds].indexOf(session)
527
555
  if (groupIndex >= 0) {
528
556
  groupSession[sortFields.day][sortFields.milliseconds].splice(groupIndex, 1)
529
557
  }
@@ -541,10 +569,19 @@ export default class ClientChatSession {
541
569
  }
542
570
  }
543
571
  })
544
- if (this.data.sessionMuteMap[session.wechatAccountId]) {
545
- delete this.data.sessionMuteMap[session.wechatAccountId][conversationId]
572
+ }
573
+
574
+ _removeLastUpdateSessionMap (conversationId, wechatAccountId) {
575
+ if (!this.sessionMap[conversationId]) {
576
+ return
546
577
  }
547
- const lastFields = ['lastMsgTime', 'lastUpdateTime']
578
+ const session = this.sessionMap[conversationId]
579
+ if (!session) {
580
+ return
581
+ }
582
+ let isDeleted = false
583
+ const lastFields = ['lastMsgTime']
584
+ const groupIds = wechatAccountId ? [wechatAccountId] : [session.wechatAccountId, ALL_WECHAT_ACCOUNT_ID]
548
585
  groupIds.forEach(groupId => {
549
586
  if (!this._lastUpdateSessionMap || !this._lastUpdateSessionMap[groupId]) {
550
587
  return
@@ -553,26 +590,93 @@ export default class ClientChatSession {
553
590
  if (!this._lastUpdateSessionMap[groupId][lastField]) {
554
591
  return
555
592
  }
593
+ const loastUpdateSortFields = this.getSortField(session[lastField])
556
594
  Object.keys(this._lastUpdateSessionMap[groupId][lastField]).forEach(topField => {
557
595
  if (!this._lastUpdateSessionMap[groupId][lastField][topField]) {
558
596
  return
559
597
  }
560
- const loastUpdateSortFields = this.getSortField(session.lastUpdateTime)
561
598
  if (this._lastUpdateSessionMap[groupId][lastField][topField][loastUpdateSortFields.day] && this._lastUpdateSessionMap[groupId][lastField][topField][loastUpdateSortFields.day][loastUpdateSortFields.milliseconds]) {
562
- const index = this._lastUpdateSessionMap[groupId][lastField][topField][loastUpdateSortFields.day][loastUpdateSortFields.milliseconds].indexOf(session)
599
+ let index = -1
600
+ this._lastUpdateSessionMap[groupId][lastField][topField][loastUpdateSortFields.day][loastUpdateSortFields.milliseconds].some((v, i) => {
601
+ if (v.conversationId === session.conversationId) {
602
+ index = i
603
+ return true
604
+ }
605
+ })
563
606
  if (index >= 0) {
564
607
  this._lastUpdateSessionMap[groupId][lastField][topField][loastUpdateSortFields.day][loastUpdateSortFields.milliseconds].splice(index, 1)
565
- }
566
- if (!this._lastUpdateSessionMap[groupId][lastField][topField][loastUpdateSortFields.day][loastUpdateSortFields.milliseconds].length) {
567
- Vue.delete(this._lastUpdateSessionMap[groupId][lastField][topField][loastUpdateSortFields.day], loastUpdateSortFields.milliseconds)
568
- }
569
- if (isEmptyObject(this._lastUpdateSessionMap[groupId][lastField][topField][loastUpdateSortFields.day])) {
570
- Vue.delete(this._lastUpdateSessionMap[groupId][lastField][topField], loastUpdateSortFields.day)
608
+ if (!this._lastUpdateSessionMap[groupId][lastField][topField][loastUpdateSortFields.day][loastUpdateSortFields.milliseconds].length) {
609
+ Vue.delete(this._lastUpdateSessionMap[groupId][lastField][topField][loastUpdateSortFields.day], loastUpdateSortFields.milliseconds)
610
+ }
611
+ if (isEmptyObject(this._lastUpdateSessionMap[groupId][lastField][topField][loastUpdateSortFields.day])) {
612
+ Vue.delete(this._lastUpdateSessionMap[groupId][lastField][topField], loastUpdateSortFields.day)
613
+ }
614
+ isDeleted = true
571
615
  }
572
616
  }
573
617
  })
574
618
  })
575
619
  })
620
+ if (!isDeleted) {
621
+ groupIds.some(groupId => {
622
+ if (!this._lastUpdateSessionMap || !this._lastUpdateSessionMap[groupId]) {
623
+ return
624
+ }
625
+ return lastFields.some(lastField => {
626
+ if (!this._lastUpdateSessionMap[groupId][lastField]) {
627
+ return
628
+ }
629
+ return Object.keys(this._lastUpdateSessionMap[groupId][lastField]).some(topField => {
630
+ if (!this._lastUpdateSessionMap[groupId][lastField][topField]) {
631
+ return
632
+ }
633
+ return Object.keys(this._lastUpdateSessionMap[groupId][lastField][topField]).some(day => {
634
+ if (!this._lastUpdateSessionMap[groupId][lastField][topField][day]) {
635
+ return
636
+ }
637
+ return Object.keys(this._lastUpdateSessionMap[groupId][lastField][topField][day]).some(milliseconds => {
638
+ if (!this._lastUpdateSessionMap[groupId][lastField][topField][day][milliseconds]) {
639
+ return
640
+ }
641
+ let index = -1
642
+ this._lastUpdateSessionMap[groupId][lastField][topField][day][milliseconds].some((v, i) => {
643
+ if (v.conversationId === session.conversationId) {
644
+ index = i
645
+ return true
646
+ }
647
+ })
648
+ if (index >= 0) {
649
+ this._lastUpdateSessionMap[groupId][lastField][topField][day][milliseconds].splice(index, 1)
650
+ if (!this._lastUpdateSessionMap[groupId][lastField][topField][day][milliseconds].length) {
651
+ Vue.delete(this._lastUpdateSessionMap[groupId][lastField][topField][day], milliseconds)
652
+ }
653
+ if (isEmptyObject(this._lastUpdateSessionMap[groupId][lastField][topField][day])) {
654
+ Vue.delete(this._lastUpdateSessionMap[groupId][lastField][topField], day)
655
+ }
656
+ isDeleted = true
657
+ return true
658
+ }
659
+ })
660
+ })
661
+ })
662
+ })
663
+ })
664
+ }
665
+ }
666
+
667
+ removeSession (conversationId) {
668
+ if (!this.sessionMap[conversationId]) {
669
+ return
670
+ }
671
+ const session = this.sessionMap[conversationId]
672
+ if (!session) {
673
+ return
674
+ }
675
+ this._removeSessionBySessionGroup(conversationId)
676
+ this._removeLastUpdateSessionMap(conversationId)
677
+ if (this.data.sessionMuteMap[session.wechatAccountId]) {
678
+ delete this.data.sessionMuteMap[session.wechatAccountId][conversationId]
679
+ }
576
680
  delete this.sessionMap[conversationId]
577
681
  this.onRemoveSession && this.onRemoveSession({
578
682
  session
@@ -115,7 +115,24 @@ class ClientChat {
115
115
  const mergeSessionCommonOptions = (options, instance) => {
116
116
  let updateSessioning = false
117
117
  let removeSessioning = false
118
- options.onAddSession = ({ session }) => {
118
+ options.onAddSession = ({ session, wechatAccountId }) => {
119
+ // 不是来源于分页的时候,没有wechatAccountId就是代表不是走的分页增加的会话,一般为获取新消息或则分配的会话
120
+ if (!wechatAccountId && instance === this.session) {
121
+ // 更新账号未读消息数量
122
+ this.account.updateAccountUnreadMessageNum(session.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => {
123
+ if (session.mute) {
124
+ return {
125
+ num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
126
+ muteNum: (unreadMessageMuteNum || 0) + (session.unreadMsgCount || 0)
127
+ }
128
+ } else {
129
+ return {
130
+ num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
131
+ muteNum: unreadMessageMuteNum
132
+ }
133
+ }
134
+ })
135
+ }
119
136
  // 同步未读会话
120
137
  if (instance !== this.sessionUnread && session.unreadMsgCount > 0) {
121
138
  const localSession = this.sessionUnread.findSession((localSession) => localSession.conversationId === session.conversationId)
@@ -423,22 +440,7 @@ class ClientChat {
423
440
  rs.data.lastUpdateTime = data.updateDate
424
441
  }
425
442
  return rs
426
- }, ({ session }) => {
427
- // 更新账号未读消息数量
428
- this.account.updateAccountUnreadMessageNum(session.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => {
429
- if (session.mute) {
430
- return {
431
- num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
432
- muteNum: (unreadMessageMuteNum || 0) + (session.unreadMsgCount || 0)
433
- }
434
- } else {
435
- return {
436
- num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
437
- muteNum: unreadMessageMuteNum
438
- }
439
- }
440
- })
441
- }, false).then((rs => {
443
+ }).then((rs => {
442
444
  // 前面更新未读消息数量只是处理会话的时候,因为getSession是异步的,会导致addMessage多次执行到这里,不会倒下面更新会话的逻辑
443
445
  // 比如连续发了3条消息,然后getSession后端返回可能只会返回2条未读数,所以这里还需要补偿一下
444
446
  const session = rs.data || {}
@@ -594,22 +596,7 @@ class ClientChat {
594
596
  rs.data.lastAtMsgContent = appendLastAtMsgContent(rs.data.lastAtMsgContent, atMessage)
595
597
  }
596
598
  return rs
597
- }, ({ session }) => {
598
- // 更新账号未读消息数量
599
- this.account.updateAccountUnreadMessageNum(session.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => {
600
- if (session.mute) {
601
- return {
602
- num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
603
- muteNum: (unreadMessageMuteNum || 0) + (session.unreadMsgCount || 0)
604
- }
605
- } else {
606
- return {
607
- num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
608
- muteNum: unreadMessageMuteNum
609
- }
610
- }
611
- })
612
- }, false).then(rs => {
599
+ }).then(rs => {
613
600
  // 前面更新未读消息数量只是处理会话的时候,因为getSession是异步的,会导致addMessage多次执行到这里,不会倒下面更新会话的逻辑
614
601
  // 比如连续发了3条消息,然后getSession后端返回可能只会返回2条未读数,所以这里还需要补偿一下
615
602
  const session = rs.data || {}
@@ -5,20 +5,14 @@ export default class ClientChatAccount {
5
5
  data = Vue.observable({
6
6
  accountData: [],
7
7
  accountUnreadMessageNumData: [],
8
- accountGreetingUnreadMsgCountData: {},
9
8
  currentAccount: null
10
9
  })
11
10
 
12
11
  loadAccountDataMethod = null
13
12
 
14
13
  getAccountUnreadMessageNumMethod = null
15
-
16
- getAccountGreetingUnreadMsgCountMethod = null
17
14
 
18
15
  accountMap = {}
19
-
20
- // 好友请求数量请求合并,key为账号id列表
21
- greetingUnreadRequestMap = {}
22
16
 
23
17
  constructor (options) {
24
18
  options = Object.assign({
@@ -27,13 +21,11 @@ export default class ClientChatAccount {
27
21
  getAccountUnreadMessageNumMethod: null,
28
22
  updateAccountMessageReadMethod: null,
29
23
  deleteAccountSessionMethod: null,
30
- getAccountGreetingUnreadMsgCountMethod: null,
31
24
  onCurrentAccountChange: null,
32
25
  onAccountAdded: null,
33
26
  onAccountRemoved: null,
34
27
  onUnreadMessageNumChange: null,
35
- onDeleteAccountSession: null,
36
- onAccountLoaded: null
28
+ onDeleteAccountSession: null
37
29
  }, options)
38
30
  if (!options.loadAccountDataMethod) {
39
31
  throw new Error('缺少loadAccountDataMethod配置')
@@ -46,12 +38,10 @@ export default class ClientChatAccount {
46
38
  this.getAccountUnreadMessageNumMethod = options.getAccountUnreadMessageNumMethod
47
39
  this.updateAccountMessageReadMethod = options.updateAccountMessageReadMethod
48
40
  this.deleteAccountSessionMethod = options.deleteAccountSessionMethod
49
- this.getAccountGreetingUnreadMsgCountMethod = options.getAccountGreetingUnreadMsgCountMethod
50
41
  this.onAccountAdded = options.onAccountAdded
51
42
  this.onAccountRemoved = options.onAccountRemoved,
52
43
  this.onUnreadMessageNumChange = options.onUnreadMessageNumChange
53
44
  this.onDeleteAccountSession = options.onDeleteAccountSession
54
- this.onAccountLoaded = options.onAccountLoaded
55
45
  }
56
46
 
57
47
  get accountData () {
@@ -65,10 +55,6 @@ export default class ClientChatAccount {
65
55
  get currentAccount () {
66
56
  return this.data.currentAccount
67
57
  }
68
-
69
- get accountGreetingUnreadMsgCountData () {
70
- return this.data.accountGreetingUnreadMsgCountData
71
- }
72
58
 
73
59
  setCurrentAccount (accountId) {
74
60
  let account = null
@@ -296,9 +282,6 @@ export default class ClientChatAccount {
296
282
  this._cacheLoadPromise = this.loadAccountDataMethod()
297
283
  this._cacheLoadPromise.then(rs => {
298
284
  this.setAccountData(rs.data)
299
- this.onAccountLoaded && this.onAccountLoaded({
300
- data: rs.data
301
- })
302
285
  })
303
286
  this.cancelConnectRequest = () => {
304
287
  this._cacheLoadPromise.abort()
@@ -315,75 +298,9 @@ export default class ClientChatAccount {
315
298
  return this.loadData()
316
299
  }
317
300
 
318
- /**
319
- * 设置指定企微账号的待处理好友请求数量,并重算all
320
- */
321
- setAccountGreetingUnreadMsgCount (params) {
322
- if (!params || !params.qwAccountId) {
323
- throw new Error('缺少必须参数')
324
- }
325
- Vue.set(this.data.accountGreetingUnreadMsgCountData, params.qwAccountId, params.count || 0)
326
- this.updateAllAccountGreetingUnreadMsgCount()
327
- }
328
-
329
- updateAllAccountGreetingUnreadMsgCount () {
330
- const allCount = Object.keys(this.data.accountGreetingUnreadMsgCountData).reduce((rs, key) => {
331
- return key === 'all' ? rs : rs + (this.data.accountGreetingUnreadMsgCountData[key] || 0)
332
- }, 0)
333
- Vue.set(this.data.accountGreetingUnreadMsgCountData, 'all', allCount)
334
- }
335
-
336
- /**
337
- * 获取待处理好友请求数量
338
- * qwAccountIds不传则刷新所有账号;后端数量为0的账号不返回,所以先置0再覆盖
339
- */
340
- getAccountGreetingUnreadMsgCount (params) {
341
- if (!this.getAccountGreetingUnreadMsgCountMethod) {
342
- return Promise.reject(new Error('getAccountGreetingUnreadMsgCountMethod未定义'))
343
- }
344
- let qwAccountIds = (params || {}).qwAccountIds
345
- if (qwAccountIds && !Array.isArray(qwAccountIds)) {
346
- qwAccountIds = [qwAccountIds]
347
- }
348
- qwAccountIds = (qwAccountIds || []).filter((id, index, data) => id && data.indexOf(id) === index).map(String)
349
- const isAll = !qwAccountIds.length
350
- const requestKey = isAll ? 'all' : qwAccountIds.slice().sort().join(',')
351
- if (this.greetingUnreadRequestMap[requestKey]) {
352
- return this.greetingUnreadRequestMap[requestKey]
353
- }
354
- const request = this.getAccountGreetingUnreadMsgCountMethod({
355
- qwAccountIds: isAll ? undefined : qwAccountIds
356
- }).then(rs => {
357
- const targetIds = isAll ? Object.keys(this.accountMap) : qwAccountIds
358
- targetIds.forEach(id => {
359
- Vue.set(this.data.accountGreetingUnreadMsgCountData, id, 0)
360
- })
361
- ;((rs && rs.data) || []).forEach(item => {
362
- if (item && item.qwAccountId) {
363
- Vue.set(this.data.accountGreetingUnreadMsgCountData, String(item.qwAccountId), item.count || 0)
364
- }
365
- })
366
- this.updateAllAccountGreetingUnreadMsgCount()
367
- return this.data.accountGreetingUnreadMsgCountData
368
- }).finally(() => {
369
- delete this.greetingUnreadRequestMap[requestKey]
370
- })
371
- this.greetingUnreadRequestMap[requestKey] = request
372
- return request
373
- }
374
-
375
- /**
376
- * 刷新所有账号的待处理好友请求数量
377
- */
378
- refreshAllAccountGreetingUnreadMsgCount () {
379
- return this.getAccountGreetingUnreadMsgCount()
380
- }
381
-
382
301
  reset () {
383
302
  this.data.accountData = []
384
303
  this.data.accountUnreadMessageNumData = []
385
- this.data.accountGreetingUnreadMsgCountData = {}
386
- this.greetingUnreadRequestMap = {}
387
304
  if (this.cancelConnectRequest) {
388
305
  this.cancelConnectRequest()
389
306
  }