@aochuang/client-sdk 1.0.359 → 1.0.362

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 (167) 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/image/image.vue +13 -8
  7. package/components/wechat-chat-control/transfer/.DS_Store +0 -0
  8. package/components/wechat-chat-control/url/.DS_Store +0 -0
  9. package/components/wechat-chat-control/url/url-miniprogram.vue +1 -5
  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-wechat/client-chat-session.js +92 -196
  46. package/services/client-chat/client-chat-wechat/client-chat.js +33 -20
  47. package/services/client-chat/client-chat-wework/client-chat-account.js +84 -1
  48. package/services/client-chat/client-chat-wework/client-chat-concats.js +81 -17
  49. package/services/client-chat/client-chat-wework/client-chat-message.js +45 -5
  50. package/services/client-chat/client-chat-wework/client-chat-session.js +50 -2
  51. package/services/client-chat/client-chat-wework/client-chat-socket.js +13 -1
  52. package/services/client-chat/client-chat-wework/client-chat.js +320 -11
  53. package/services/client-chat/client-chat-wework/utils.js +5 -5
  54. package/components/wework-chat-panel/chat-panel-controls/company-card/company-card.vue +0 -35
  55. package/components/wework-chat-panel/chat-panel-controls/expression/expression.vue +0 -36
  56. package/components/wework-chat-panel/chat-panel-controls/file-url/file-url.vue +0 -35
  57. package/components/wework-chat-panel/chat-panel-controls/image/image.vue +0 -36
  58. package/components/wework-chat-panel/chat-panel-controls/index.js +0 -35
  59. package/components/wework-chat-panel/chat-panel-controls/jx-sys-text/jx-sys-text.vue +0 -28
  60. package/components/wework-chat-panel/chat-panel-controls/link/link.vue +0 -35
  61. package/components/wework-chat-panel/chat-panel-controls/location/location.vue +0 -35
  62. package/components/wework-chat-panel/chat-panel-controls/text/text.vue +0 -43
  63. package/components/wework-chat-panel/chat-panel-controls/unkonw/unkonw.vue +0 -39
  64. package/components/wework-chat-panel/chat-panel-controls/video/video.vue +0 -37
  65. package/components/wework-chat-panel/chat-panel-controls/voice/voice.vue +0 -35
  66. package/uni-common/account-portray/account-portray.vue +0 -51
  67. package/uni-common/account-select/account-select-item.vue +0 -172
  68. package/uni-common/account-select/account-select.vue +0 -252
  69. package/uni-common/all-friend-avatar/all-friend-avatar.vue +0 -49
  70. package/uni-common/friend-avatar/default.svg +0 -1
  71. package/uni-common/friend-avatar/friend-avatar.vue +0 -27
  72. package/uni-common/friend-avatar/index.js +0 -3
  73. package/uni-common/friend-loader/friend-loader.vue +0 -53
  74. package/uni-common/friend-portray/friend-portray.vue +0 -56
  75. package/uni-common/group-avatar/default.svg +0 -1
  76. package/uni-common/group-avatar/group-avatar.vue +0 -18
  77. package/uni-common/group-avatar/index.js +0 -3
  78. package/uni-common/room-avatar/default.svg +0 -6
  79. package/uni-common/room-avatar/index.js +0 -3
  80. package/uni-common/room-avatar/room-avatar.vue +0 -27
  81. package/uni-common/room-loader/room-loader.vue +0 -53
  82. package/uni-common/room-portray/room-portray.vue +0 -56
  83. package/uni-components/chat-control/calling/calling.vue +0 -91
  84. package/uni-components/chat-control/calling/phone-fill.svg +0 -1
  85. package/uni-components/chat-control/calling/vidicon-fill.svg +0 -1
  86. package/uni-components/chat-control/channel-video/channel-video.vue +0 -89
  87. package/uni-components/chat-control/channel-video-card/channel-video-card.vue +0 -105
  88. package/uni-components/chat-control/channel-video-live/channel-video-live.vue +0 -92
  89. package/uni-components/chat-control/chat-control-config-item/chat-control-config-item.vue +0 -20
  90. package/uni-components/chat-control/chat-control-config-item/index.js +0 -3
  91. package/uni-components/chat-control/chat-control-config-msg/chat-control-config-msg-app.vue +0 -25
  92. package/uni-components/chat-control/chat-control-config-msg/chat-control-config-msg-h5.vue +0 -21
  93. package/uni-components/chat-control/chat-control.vue +0 -218
  94. package/uni-components/chat-control/company-card/company-card.vue +0 -123
  95. package/uni-components/chat-control/const.js +0 -28
  96. package/uni-components/chat-control/expression/expression.vue +0 -41
  97. package/uni-components/chat-control/image/image.vue +0 -68
  98. package/uni-components/chat-control/index.js +0 -89
  99. package/uni-components/chat-control/location/location.vue +0 -110
  100. package/uni-components/chat-control/member-change/member-change.vue +0 -32
  101. package/uni-components/chat-control/quote-message/quote-message.vue +0 -216
  102. package/uni-components/chat-control/real-time-position/real-time-position.vue +0 -62
  103. package/uni-components/chat-control/redpacket/red-envelope.svg +0 -1
  104. package/uni-components/chat-control/redpacket/redpacket.vue +0 -75
  105. package/uni-components/chat-control/share-card/share-card.vue +0 -101
  106. package/uni-components/chat-control/system/system.vue +0 -69
  107. package/uni-components/chat-control/system-batch-message/system-batch-message.vue +0 -30
  108. package/uni-components/chat-control/system-text/system-text.vue +0 -32
  109. package/uni-components/chat-control/text/text.vue +0 -67
  110. package/uni-components/chat-control/text-with-at/text-with-at.vue +0 -51
  111. package/uni-components/chat-control/transfer/red-transfer.svg +0 -1
  112. package/uni-components/chat-control/transfer/transfer.vue +0 -80
  113. package/uni-components/chat-control/unkonw/unkonw.vue +0 -37
  114. package/uni-components/chat-control/url/icons/file-excel-line.svg +0 -1
  115. package/uni-components/chat-control/url/icons/file-info-line.svg +0 -1
  116. package/uni-components/chat-control/url/icons/file-music-line.svg +0 -1
  117. package/uni-components/chat-control/url/icons/file-pdf-line.svg +0 -1
  118. package/uni-components/chat-control/url/icons/file-ppt-line.svg +0 -1
  119. package/uni-components/chat-control/url/icons/file-settings-line.svg +0 -1
  120. package/uni-components/chat-control/url/icons/file-text-line.svg +0 -1
  121. package/uni-components/chat-control/url/icons/file-unknow-line.svg +0 -1
  122. package/uni-components/chat-control/url/icons/file-word-line.svg +0 -1
  123. package/uni-components/chat-control/url/icons/file-zip-line.svg +0 -1
  124. package/uni-components/chat-control/url/icons/index.js +0 -24
  125. package/uni-components/chat-control/url/miniprogram.svg +0 -1
  126. package/uni-components/chat-control/url/url-miniprogram.vue +0 -116
  127. package/uni-components/chat-control/url/url.vue +0 -306
  128. package/uni-components/chat-control/url-new/icons/file-excel-line.svg +0 -1
  129. package/uni-components/chat-control/url-new/icons/file-info-line.svg +0 -1
  130. package/uni-components/chat-control/url-new/icons/file-music-line.svg +0 -1
  131. package/uni-components/chat-control/url-new/icons/file-pdf-line.svg +0 -1
  132. package/uni-components/chat-control/url-new/icons/file-ppt-line.svg +0 -1
  133. package/uni-components/chat-control/url-new/icons/file-settings-line.svg +0 -1
  134. package/uni-components/chat-control/url-new/icons/file-text-line.svg +0 -1
  135. package/uni-components/chat-control/url-new/icons/file-unknow-line.svg +0 -1
  136. package/uni-components/chat-control/url-new/icons/file-word-line.svg +0 -1
  137. package/uni-components/chat-control/url-new/icons/file-zip-line.svg +0 -1
  138. package/uni-components/chat-control/url-new/icons/index.js +0 -24
  139. package/uni-components/chat-control/url-new/url-new.vue +0 -110
  140. package/uni-components/chat-control/utils.js +0 -12
  141. package/uni-components/chat-control/video/video.vue +0 -156
  142. package/uni-components/chat-control/voice/voice.vue +0 -166
  143. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet-collect.vue +0 -84
  144. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet-system.vue +0 -28
  145. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet.vue +0 -85
  146. package/uni-components/chat-editor/chat-editor-func/chat-editor-func.vue +0 -157
  147. package/uni-components/chat-editor/chat-editor-func-at/chat-editor-func-at-panel.vue +0 -158
  148. package/uni-components/chat-editor/chat-editor-func-at/chat-editor-func-at.vue +0 -61
  149. package/uni-components/chat-editor/chat-editor-func-button/chat-editor-func-button.vue +0 -58
  150. package/uni-components/chat-editor/chat-editor-func-file/chat-editor-func-file.vue +0 -54
  151. package/uni-components/chat-editor/chat-editor-func-image/chat-editor-func-image.vue +0 -42
  152. package/uni-components/chat-editor/chat-editor-func-video/chat-editor-func-video.vue +0 -42
  153. package/uni-components/chat-editor/chat-editor-func-voice/chat-editor-func-voice.vue +0 -25
  154. package/uni-components/chat-editor/chat-editor-message-send/chat-editor-message-send.vue +0 -158
  155. package/uni-components/chat-editor/chat-editor-quote/chat-editor-quote.vue +0 -75
  156. package/uni-components/chat-editor/chat-editor.vue +0 -257
  157. package/uni-components/chat-editor/index.js +0 -10
  158. package/uni-components/chat-editor/util.js +0 -65
  159. package/uni-components/chat-panel/chat-panel-chats-box.vue +0 -238
  160. package/uni-components/chat-panel/chat-panel-chats-forward/chat-panel-chats-forward.vue +0 -273
  161. package/uni-components/chat-panel/chat-panel-chats-item.vue +0 -578
  162. package/uni-components/chat-panel/chat-panel-chats-status/chat-panel-chats-status.vue +0 -71
  163. package/uni-components/chat-panel/chat-panel-chats.vue +0 -368
  164. package/uni-components/chat-panel/chat-panel.vue +0 -227
  165. package/uni-components/contacts-group-select/contacts-group-select-item.vue +0 -85
  166. package/uni-components/contacts-group-select/contacts-group-select-panel.vue +0 -119
  167. package/uni-components/contacts-group-select/contacts-group-select.vue +0 -150
@@ -228,40 +228,50 @@ export default class ClientChatSession {
228
228
  })
229
229
  }
230
230
 
231
- getSession (sessionId, serializeMethod) {
231
+ getSession (sessionId, serializeMethod, callback = null, isCache = true) {
232
+ if (typeof callback === 'boolean') {
233
+ isCache = callback
234
+ callback = null
235
+ }
232
236
  if (this.sessionMap[sessionId]) {
233
237
  return Promise.resolve({
234
238
  data: this.sessionMap[sessionId]
235
239
  })
236
240
  }
237
241
  // 这里需要轮询从后端获取会话,后端会话更新和创建是异步的,所以要多轮训请求几次
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
- }
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) => {
253
254
  if (rs.data) {
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]
255
+ done(rs)
262
256
  }
263
257
  })
264
- }
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
+ })
265
275
  return this.pollRequestMap[sessionId].ps
266
276
  }
267
277
 
@@ -387,7 +397,7 @@ export default class ClientChatSession {
387
397
  * "wechatAccountId": "2a39a725814acf07502299ab2285fff8d44377f5"
388
398
  * }
389
399
  */
390
- addSession (data, wechatAccountId) {
400
+ addSession (data, wechatAccountId, callback) {
391
401
  if (!data || !data.conversationId) {
392
402
  throw new Error('缺少必须参数conversationId')
393
403
  }
@@ -402,53 +412,56 @@ export default class ClientChatSession {
402
412
  }) === false) {
403
413
  return
404
414
  }
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 = []
415
+ let nextData = data
411
416
  // 如果会话已经存在,那么取已经存在的,以后有需要可以用data更新已经存在的会话,保持引用关系
412
- // 一般比较容易出现,例如all的时候,分配的时候有可能会出现,例如以前的会话没有正确删除,后面有分配过来了
413
417
  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
- }
423
418
  nextData = this.sessionMap[data.conversationId]
424
- isRefreshAll = true
425
419
  } else {
426
- nextData = data
420
+ this.sessionMap[data.conversationId] = nextData
427
421
  }
428
- if (!nextData) {
429
- return
422
+ const topField = nextData.stickyOnTop ? 0 : 1 // 置顶
423
+ if (wechatAccountId && wechatAccountId !== ALL_WECHAT_ACCOUNT_ID && nextData.wechatAccountId !== wechatAccountId) {
424
+ throw new Error('会话的wechatAccount和加载分组的wechatAccountId不一致')
430
425
  }
426
+ const groupIds = []
427
+ // 传了wechatAccountId,是分页加载的,这里要保持分页加载数据的链路不受动态加载的影响
431
428
  if (wechatAccountId) {
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)
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
+ })
444
459
  } else {
445
460
  groupIds.push(nextData.wechatAccountId)
446
461
  groupIds.push(ALL_WECHAT_ACCOUNT_ID)
447
462
  }
448
- this.sessionMap[data.conversationId] = nextData
449
463
  // 分组的
450
464
  const sortFields = this.getSortField(nextData.lastMsgTime)
451
- const topField = nextData.stickyOnTop ? 0 : 1 // 置顶
452
465
  groupIds.forEach(groupId => {
453
466
  // 如果已经在分组里面了,就不新增了,
454
467
  if (this._getSessionBySessionGroup(nextData.conversationId, groupId)) {
@@ -479,62 +492,21 @@ export default class ClientChatSession {
479
492
  Vue.set(this.data.sessionMuteMap, nextData.wechatAccountId, {})
480
493
  }
481
494
  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
- }
486
495
  }
487
496
  // 检测一下是不是存在一样的虚拟会话,存在的话就删除
488
497
  const virtualSessionIndex = this.data.virtualSessionData.findIndex(v => v.conversationId === nextData.conversationId)
489
498
  if (virtualSessionIndex > -1) {
490
499
  this.data.virtualSessionData.splice(virtualSessionIndex, 1)
491
500
  }
492
- this.onAddSession && this.onAddSession({
493
- wechatAccountId,
494
- session: nextData
501
+ callback && callback({
502
+ session: data
495
503
  })
496
- }
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
- })
504
+ this.onAddSession && this.onAddSession({
505
+ session: data
534
506
  })
535
507
  }
536
-
537
- _removeSessionBySessionGroup (conversationId, wechatAccountId) {
508
+
509
+ removeSession (conversationId) {
538
510
  if (!this.sessionMap[conversationId]) {
539
511
  return
540
512
  }
@@ -543,7 +515,7 @@ export default class ClientChatSession {
543
515
  return
544
516
  }
545
517
  const topField = session.stickyOnTop ? 0 : 1 // 置顶
546
- const groupIds = wechatAccountId ? [wechatAccountId] : [session.wechatAccountId, ALL_WECHAT_ACCOUNT_ID]
518
+ const groupIds = [session.wechatAccountId, ALL_WECHAT_ACCOUNT_ID]
547
519
  const sortFields = this.getSortField(session.lastMsgTime)
548
520
  groupIds.forEach(groupId => {
549
521
  if (!this.data.sessionGroupData[groupId] || !this.data.sessionGroupData[groupId][topField]) {
@@ -551,7 +523,7 @@ export default class ClientChatSession {
551
523
  }
552
524
  const groupSession = this.data.sessionGroupData[groupId][topField]
553
525
  if (groupSession[sortFields.day] && groupSession[sortFields.day][sortFields.milliseconds]) {
554
- const groupIndex = groupSession[sortFields.day][sortFields.milliseconds].indexOf(session)
526
+ const groupIndex = groupSession[sortFields.day][sortFields.milliseconds].indexOf(this.sessionMap[conversationId])
555
527
  if (groupIndex >= 0) {
556
528
  groupSession[sortFields.day][sortFields.milliseconds].splice(groupIndex, 1)
557
529
  }
@@ -569,19 +541,10 @@ export default class ClientChatSession {
569
541
  }
570
542
  }
571
543
  })
572
- }
573
-
574
- _removeLastUpdateSessionMap (conversationId, wechatAccountId) {
575
- if (!this.sessionMap[conversationId]) {
576
- return
577
- }
578
- const session = this.sessionMap[conversationId]
579
- if (!session) {
580
- return
544
+ if (this.data.sessionMuteMap[session.wechatAccountId]) {
545
+ delete this.data.sessionMuteMap[session.wechatAccountId][conversationId]
581
546
  }
582
- let isDeleted = false
583
- const lastFields = ['lastMsgTime']
584
- const groupIds = wechatAccountId ? [wechatAccountId] : [session.wechatAccountId, ALL_WECHAT_ACCOUNT_ID]
547
+ const lastFields = ['lastMsgTime', 'lastUpdateTime']
585
548
  groupIds.forEach(groupId => {
586
549
  if (!this._lastUpdateSessionMap || !this._lastUpdateSessionMap[groupId]) {
587
550
  return
@@ -590,93 +553,26 @@ export default class ClientChatSession {
590
553
  if (!this._lastUpdateSessionMap[groupId][lastField]) {
591
554
  return
592
555
  }
593
- const loastUpdateSortFields = this.getSortField(session[lastField])
594
556
  Object.keys(this._lastUpdateSessionMap[groupId][lastField]).forEach(topField => {
595
557
  if (!this._lastUpdateSessionMap[groupId][lastField][topField]) {
596
558
  return
597
559
  }
560
+ const loastUpdateSortFields = this.getSortField(session.lastUpdateTime)
598
561
  if (this._lastUpdateSessionMap[groupId][lastField][topField][loastUpdateSortFields.day] && this._lastUpdateSessionMap[groupId][lastField][topField][loastUpdateSortFields.day][loastUpdateSortFields.milliseconds]) {
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
- })
562
+ const index = this._lastUpdateSessionMap[groupId][lastField][topField][loastUpdateSortFields.day][loastUpdateSortFields.milliseconds].indexOf(session)
606
563
  if (index >= 0) {
607
564
  this._lastUpdateSessionMap[groupId][lastField][topField][loastUpdateSortFields.day][loastUpdateSortFields.milliseconds].splice(index, 1)
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
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)
615
571
  }
616
572
  }
617
573
  })
618
574
  })
619
575
  })
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
- }
680
576
  delete this.sessionMap[conversationId]
681
577
  this.onRemoveSession && this.onRemoveSession({
682
578
  session
@@ -115,24 +115,7 @@ class ClientChat {
115
115
  const mergeSessionCommonOptions = (options, instance) => {
116
116
  let updateSessioning = false
117
117
  let removeSessioning = false
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
- }
118
+ options.onAddSession = ({ session }) => {
136
119
  // 同步未读会话
137
120
  if (instance !== this.sessionUnread && session.unreadMsgCount > 0) {
138
121
  const localSession = this.sessionUnread.findSession((localSession) => localSession.conversationId === session.conversationId)
@@ -440,7 +423,22 @@ class ClientChat {
440
423
  rs.data.lastUpdateTime = data.updateDate
441
424
  }
442
425
  return rs
443
- }).then((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 => {
444
442
  // 前面更新未读消息数量只是处理会话的时候,因为getSession是异步的,会导致addMessage多次执行到这里,不会倒下面更新会话的逻辑
445
443
  // 比如连续发了3条消息,然后getSession后端返回可能只会返回2条未读数,所以这里还需要补偿一下
446
444
  const session = rs.data || {}
@@ -596,7 +594,22 @@ class ClientChat {
596
594
  rs.data.lastAtMsgContent = appendLastAtMsgContent(rs.data.lastAtMsgContent, atMessage)
597
595
  }
598
596
  return rs
599
- }).then(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 => {
600
613
  // 前面更新未读消息数量只是处理会话的时候,因为getSession是异步的,会导致addMessage多次执行到这里,不会倒下面更新会话的逻辑
601
614
  // 比如连续发了3条消息,然后getSession后端返回可能只会返回2条未读数,所以这里还需要补偿一下
602
615
  const session = rs.data || {}
@@ -5,14 +5,20 @@ export default class ClientChatAccount {
5
5
  data = Vue.observable({
6
6
  accountData: [],
7
7
  accountUnreadMessageNumData: [],
8
+ accountGreetingUnreadMsgCountData: {},
8
9
  currentAccount: null
9
10
  })
10
11
 
11
12
  loadAccountDataMethod = null
12
13
 
13
14
  getAccountUnreadMessageNumMethod = null
15
+
16
+ getAccountGreetingUnreadMsgCountMethod = null
14
17
 
15
18
  accountMap = {}
19
+
20
+ // 好友请求数量请求合并,key为账号id列表
21
+ greetingUnreadRequestMap = {}
16
22
 
17
23
  constructor (options) {
18
24
  options = Object.assign({
@@ -21,11 +27,13 @@ export default class ClientChatAccount {
21
27
  getAccountUnreadMessageNumMethod: null,
22
28
  updateAccountMessageReadMethod: null,
23
29
  deleteAccountSessionMethod: null,
30
+ getAccountGreetingUnreadMsgCountMethod: null,
24
31
  onCurrentAccountChange: null,
25
32
  onAccountAdded: null,
26
33
  onAccountRemoved: null,
27
34
  onUnreadMessageNumChange: null,
28
- onDeleteAccountSession: null
35
+ onDeleteAccountSession: null,
36
+ onAccountLoaded: null
29
37
  }, options)
30
38
  if (!options.loadAccountDataMethod) {
31
39
  throw new Error('缺少loadAccountDataMethod配置')
@@ -38,10 +46,12 @@ export default class ClientChatAccount {
38
46
  this.getAccountUnreadMessageNumMethod = options.getAccountUnreadMessageNumMethod
39
47
  this.updateAccountMessageReadMethod = options.updateAccountMessageReadMethod
40
48
  this.deleteAccountSessionMethod = options.deleteAccountSessionMethod
49
+ this.getAccountGreetingUnreadMsgCountMethod = options.getAccountGreetingUnreadMsgCountMethod
41
50
  this.onAccountAdded = options.onAccountAdded
42
51
  this.onAccountRemoved = options.onAccountRemoved,
43
52
  this.onUnreadMessageNumChange = options.onUnreadMessageNumChange
44
53
  this.onDeleteAccountSession = options.onDeleteAccountSession
54
+ this.onAccountLoaded = options.onAccountLoaded
45
55
  }
46
56
 
47
57
  get accountData () {
@@ -55,6 +65,10 @@ export default class ClientChatAccount {
55
65
  get currentAccount () {
56
66
  return this.data.currentAccount
57
67
  }
68
+
69
+ get accountGreetingUnreadMsgCountData () {
70
+ return this.data.accountGreetingUnreadMsgCountData
71
+ }
58
72
 
59
73
  setCurrentAccount (accountId) {
60
74
  let account = null
@@ -282,6 +296,9 @@ export default class ClientChatAccount {
282
296
  this._cacheLoadPromise = this.loadAccountDataMethod()
283
297
  this._cacheLoadPromise.then(rs => {
284
298
  this.setAccountData(rs.data)
299
+ this.onAccountLoaded && this.onAccountLoaded({
300
+ data: rs.data
301
+ })
285
302
  })
286
303
  this.cancelConnectRequest = () => {
287
304
  this._cacheLoadPromise.abort()
@@ -298,9 +315,75 @@ export default class ClientChatAccount {
298
315
  return this.loadData()
299
316
  }
300
317
 
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
+
301
382
  reset () {
302
383
  this.data.accountData = []
303
384
  this.data.accountUnreadMessageNumData = []
385
+ this.data.accountGreetingUnreadMsgCountData = {}
386
+ this.greetingUnreadRequestMap = {}
304
387
  if (this.cancelConnectRequest) {
305
388
  this.cancelConnectRequest()
306
389
  }