@aochuang/client-sdk 1.0.358 → 1.0.359

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 (153) hide show
  1. package/components/index.js +1 -6
  2. package/components/session-select/session-select-item.vue +9 -8
  3. package/components/wechat-chat-control/image/image.vue +8 -13
  4. package/components/wechat-chat-control/url/url-miniprogram.vue +5 -1
  5. package/components/wework-chat-control/channel-live/channel-live.vue +2 -7
  6. package/components/wework-chat-control/company-card/company-card.vue +1 -1
  7. package/components/wework-chat-control/custom-expression/custom-expression.vue +1 -2
  8. package/components/wework-chat-control/file-url/file-url.vue +16 -34
  9. package/components/wework-chat-control/image/image.vue +2 -137
  10. package/components/wework-chat-control/index.js +7 -10
  11. package/components/wework-chat-control/location/location.vue +3 -3
  12. package/components/wework-chat-control/text/text.vue +144 -24
  13. package/components/wework-chat-control/url/url-miniprogram.vue +7 -6
  14. package/components/wework-chat-control/url/url.vue +2 -26
  15. package/components/wework-chat-control/util.js +19 -22
  16. package/components/wework-chat-control/video/video.vue +2 -10
  17. package/components/wework-chat-control/voice/voice.vue +4 -59
  18. package/components/wework-chat-panel/chat-panel-controls/company-card/company-card.vue +35 -0
  19. package/components/wework-chat-panel/chat-panel-controls/expression/expression.vue +36 -0
  20. package/components/wework-chat-panel/chat-panel-controls/file-url/file-url.vue +35 -0
  21. package/components/wework-chat-panel/chat-panel-controls/image/image.vue +36 -0
  22. package/components/wework-chat-panel/chat-panel-controls/index.js +35 -0
  23. package/components/wework-chat-panel/chat-panel-controls/jx-sys-text/jx-sys-text.vue +28 -0
  24. package/components/wework-chat-panel/chat-panel-controls/link/link.vue +35 -0
  25. package/components/wework-chat-panel/chat-panel-controls/location/location.vue +35 -0
  26. package/components/wework-chat-panel/chat-panel-controls/text/text.vue +43 -0
  27. package/components/wework-chat-panel/chat-panel-controls/unkonw/unkonw.vue +39 -0
  28. package/components/wework-chat-panel/chat-panel-controls/video/video.vue +37 -0
  29. package/components/wework-chat-panel/chat-panel-controls/voice/voice.vue +35 -0
  30. package/components/wework-chat-panel/chat-panel-item.vue +28 -38
  31. package/components/wework-chat-panel/chat-panel.vue +13 -96
  32. package/package.json +3 -10
  33. package/services/client-chat/client-chat-wechat/client-chat-session.js +196 -92
  34. package/services/client-chat/client-chat-wechat/client-chat.js +20 -33
  35. package/services/client-chat/client-chat-wework/client-chat-concats.js +17 -81
  36. package/services/client-chat/client-chat-wework/client-chat-message.js +5 -45
  37. package/services/client-chat/client-chat-wework/client-chat-session.js +2 -50
  38. package/services/client-chat/client-chat-wework/client-chat-socket.js +1 -9
  39. package/services/client-chat/client-chat-wework/client-chat.js +11 -281
  40. package/services/client-chat/client-chat-wework/utils.js +5 -5
  41. package/uni-common/account-portray/account-portray.vue +51 -0
  42. package/uni-common/account-select/account-select-item.vue +172 -0
  43. package/uni-common/account-select/account-select.vue +252 -0
  44. package/uni-common/all-friend-avatar/all-friend-avatar.vue +49 -0
  45. package/uni-common/friend-avatar/default.svg +1 -0
  46. package/uni-common/friend-avatar/friend-avatar.vue +27 -0
  47. package/uni-common/friend-avatar/index.js +3 -0
  48. package/uni-common/friend-loader/friend-loader.vue +53 -0
  49. package/uni-common/friend-portray/friend-portray.vue +56 -0
  50. package/uni-common/group-avatar/default.svg +1 -0
  51. package/uni-common/group-avatar/group-avatar.vue +18 -0
  52. package/uni-common/group-avatar/index.js +3 -0
  53. package/uni-common/room-avatar/default.svg +6 -0
  54. package/uni-common/room-avatar/index.js +3 -0
  55. package/uni-common/room-avatar/room-avatar.vue +27 -0
  56. package/uni-common/room-loader/room-loader.vue +53 -0
  57. package/uni-common/room-portray/room-portray.vue +56 -0
  58. package/uni-components/chat-control/calling/calling.vue +91 -0
  59. package/uni-components/chat-control/calling/phone-fill.svg +1 -0
  60. package/uni-components/chat-control/calling/vidicon-fill.svg +1 -0
  61. package/uni-components/chat-control/channel-video/channel-video.vue +89 -0
  62. package/uni-components/chat-control/channel-video-card/channel-video-card.vue +105 -0
  63. package/uni-components/chat-control/channel-video-live/channel-video-live.vue +92 -0
  64. package/uni-components/chat-control/chat-control-config-item/chat-control-config-item.vue +20 -0
  65. package/uni-components/chat-control/chat-control-config-item/index.js +3 -0
  66. package/uni-components/chat-control/chat-control-config-msg/chat-control-config-msg-app.vue +25 -0
  67. package/uni-components/chat-control/chat-control-config-msg/chat-control-config-msg-h5.vue +21 -0
  68. package/{components/wework-chat-control/wework-chat-control-config.vue → uni-components/chat-control/chat-control-config.vue} +13 -16
  69. package/uni-components/chat-control/chat-control.vue +218 -0
  70. package/uni-components/chat-control/company-card/company-card.vue +123 -0
  71. package/uni-components/chat-control/const.js +28 -0
  72. package/uni-components/chat-control/expression/expression.vue +41 -0
  73. package/uni-components/chat-control/image/image.vue +68 -0
  74. package/uni-components/chat-control/index.js +89 -0
  75. package/uni-components/chat-control/location/location.vue +110 -0
  76. package/uni-components/chat-control/member-change/member-change.vue +32 -0
  77. package/uni-components/chat-control/quote-message/quote-message.vue +216 -0
  78. package/uni-components/chat-control/real-time-position/real-time-position.vue +62 -0
  79. package/uni-components/chat-control/redpacket/red-envelope.svg +1 -0
  80. package/uni-components/chat-control/redpacket/redpacket.vue +75 -0
  81. package/uni-components/chat-control/share-card/share-card.vue +101 -0
  82. package/uni-components/chat-control/system/system.vue +69 -0
  83. package/uni-components/chat-control/system-batch-message/system-batch-message.vue +30 -0
  84. package/uni-components/chat-control/system-text/system-text.vue +32 -0
  85. package/uni-components/chat-control/text/text.vue +67 -0
  86. package/uni-components/chat-control/text-with-at/text-with-at.vue +51 -0
  87. package/uni-components/chat-control/transfer/red-transfer.svg +1 -0
  88. package/uni-components/chat-control/transfer/transfer.vue +80 -0
  89. package/uni-components/chat-control/unkonw/unkonw.vue +37 -0
  90. package/uni-components/chat-control/url/icons/file-excel-line.svg +1 -0
  91. package/uni-components/chat-control/url/icons/file-info-line.svg +1 -0
  92. package/uni-components/chat-control/url/icons/file-music-line.svg +1 -0
  93. package/uni-components/chat-control/url/icons/file-pdf-line.svg +1 -0
  94. package/uni-components/chat-control/url/icons/file-ppt-line.svg +1 -0
  95. package/uni-components/chat-control/url/icons/file-settings-line.svg +1 -0
  96. package/uni-components/chat-control/url/icons/file-text-line.svg +1 -0
  97. package/uni-components/chat-control/url/icons/file-unknow-line.svg +1 -0
  98. package/uni-components/chat-control/url/icons/file-word-line.svg +1 -0
  99. package/uni-components/chat-control/url/icons/file-zip-line.svg +1 -0
  100. package/uni-components/chat-control/url/icons/index.js +24 -0
  101. package/uni-components/chat-control/url/miniprogram.svg +1 -0
  102. package/uni-components/chat-control/url/url-miniprogram.vue +116 -0
  103. package/uni-components/chat-control/url/url.vue +306 -0
  104. package/uni-components/chat-control/url-new/icons/file-excel-line.svg +1 -0
  105. package/uni-components/chat-control/url-new/icons/file-info-line.svg +1 -0
  106. package/uni-components/chat-control/url-new/icons/file-music-line.svg +1 -0
  107. package/uni-components/chat-control/url-new/icons/file-pdf-line.svg +1 -0
  108. package/uni-components/chat-control/url-new/icons/file-ppt-line.svg +1 -0
  109. package/uni-components/chat-control/url-new/icons/file-settings-line.svg +1 -0
  110. package/uni-components/chat-control/url-new/icons/file-text-line.svg +1 -0
  111. package/uni-components/chat-control/url-new/icons/file-unknow-line.svg +1 -0
  112. package/uni-components/chat-control/url-new/icons/file-word-line.svg +1 -0
  113. package/uni-components/chat-control/url-new/icons/file-zip-line.svg +1 -0
  114. package/uni-components/chat-control/url-new/icons/index.js +24 -0
  115. package/uni-components/chat-control/url-new/url-new.vue +110 -0
  116. package/uni-components/chat-control/utils.js +12 -0
  117. package/uni-components/chat-control/video/video.vue +156 -0
  118. package/uni-components/chat-control/voice/voice.vue +166 -0
  119. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet-collect.vue +84 -0
  120. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet-system.vue +28 -0
  121. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet.vue +85 -0
  122. package/uni-components/chat-editor/chat-editor-func/chat-editor-func.vue +157 -0
  123. package/uni-components/chat-editor/chat-editor-func-at/chat-editor-func-at-panel.vue +158 -0
  124. package/uni-components/chat-editor/chat-editor-func-at/chat-editor-func-at.vue +61 -0
  125. package/uni-components/chat-editor/chat-editor-func-button/chat-editor-func-button.vue +58 -0
  126. package/uni-components/chat-editor/chat-editor-func-file/chat-editor-func-file.vue +54 -0
  127. package/uni-components/chat-editor/chat-editor-func-image/chat-editor-func-image.vue +42 -0
  128. package/uni-components/chat-editor/chat-editor-func-video/chat-editor-func-video.vue +42 -0
  129. package/uni-components/chat-editor/chat-editor-func-voice/chat-editor-func-voice.vue +25 -0
  130. package/uni-components/chat-editor/chat-editor-message-send/chat-editor-message-send.vue +158 -0
  131. package/uni-components/chat-editor/chat-editor-quote/chat-editor-quote.vue +75 -0
  132. package/uni-components/chat-editor/chat-editor.vue +257 -0
  133. package/uni-components/chat-editor/index.js +10 -0
  134. package/uni-components/chat-editor/util.js +65 -0
  135. package/uni-components/chat-panel/chat-panel-chats-box.vue +238 -0
  136. package/uni-components/chat-panel/chat-panel-chats-forward/chat-panel-chats-forward.vue +273 -0
  137. package/uni-components/chat-panel/chat-panel-chats-item.vue +578 -0
  138. package/uni-components/chat-panel/chat-panel-chats-status/chat-panel-chats-status.vue +71 -0
  139. package/uni-components/chat-panel/chat-panel-chats.vue +368 -0
  140. package/uni-components/chat-panel/chat-panel.vue +227 -0
  141. package/uni-components/contacts-group-select/contacts-group-select-item.vue +85 -0
  142. package/uni-components/contacts-group-select/contacts-group-select-panel.vue +119 -0
  143. package/uni-components/contacts-group-select/contacts-group-select.vue +150 -0
  144. package/components/wework-chat-control/channel-card/channel-card.vue +0 -144
  145. package/components/wework-chat-control/metting/enterprise-wechat.png +0 -0
  146. package/components/wework-chat-control/metting/meeting-video.svg +0 -4
  147. package/components/wework-chat-control/metting/metting.vue +0 -181
  148. package/components/wework-chat-control/text/text-default.vue +0 -99
  149. package/components/wework-chat-control/text/text-quote.vue +0 -105
  150. package/components/wework-chat-control/url/url-channel-live.vue +0 -53
  151. package/components/wework-chat-control/wework-chat-control-config-item.vue +0 -24
  152. package/components/wework-chat-control/wework-chat-control-config-msg.vue +0 -25
  153. package/components/wework-chat-panel/chat-panel-chat-status/chat-panel-chat-status.vue +0 -73
@@ -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 || {}
@@ -126,7 +126,11 @@ export default class ClientChatContacts {
126
126
  */
127
127
  roomBindMemberMap: {},
128
128
 
129
- modifiedAccountMap: {}
129
+ /**
130
+ * 标记通讯录是否修改了
131
+ * 如果修改了,比如接收到了分配好友的会话时,一定通讯录变了,变了的时候界面需要根据这个状态刷新通讯录
132
+ */
133
+ isModify: false
130
134
  })
131
135
 
132
136
  friendMap = {}
@@ -233,6 +237,10 @@ export default class ClientChatContacts {
233
237
  return this.data.roomGroupData
234
238
  }
235
239
 
240
+ get isModify () {
241
+ return this.data.isModify
242
+ }
243
+
236
244
  setRoomGroup (data) {
237
245
  this.data.roomGroupData = []
238
246
  if (data && data.length) {
@@ -483,10 +491,10 @@ export default class ClientChatContacts {
483
491
  }
484
492
  }
485
493
  const qwAccountId = this.roomMap[id].qwAccountId
486
- if (qwAccountId && this.data.accountBindRoomMap[qwAccountId] && this.data.accountBindRoomMap[qwAccountId][groupId]) {
487
- const bindIndex = this.data.accountBindRoomMap[qwAccountId][groupId].indexOf(this.roomMap[id])
494
+ if (qwAccountId && this.data.accountBindFriendMap[qwAccountId] && this.data.accountBindFriendMap[qwAccountId][groupId]) {
495
+ const bindIndex = this.data.accountBindFriendMap[qwAccountId][groupId].indexOf(this.roomMap[id])
488
496
  if (bindIndex >= 0) {
489
- this.data.accountBindRoomMap[qwAccountId][groupId].splice(bindIndex, 1)
497
+ this.data.accountBindFriendMap[qwAccountId][groupId].splice(bindIndex, 1)
490
498
  }
491
499
  }
492
500
  })
@@ -620,37 +628,6 @@ export default class ClientChatContacts {
620
628
  return rs
621
629
  })
622
630
  }
623
-
624
- /**
625
- * 强制从服务端刷新好友资料,绕过本地缓存。
626
- */
627
- refreshFriend (friendId) {
628
- if (!friendId) {
629
- return Promise.reject('缺少好友id')
630
- }
631
- if (!this.getContactsFriendMethod) {
632
- return Promise.reject(new Error('getContactsFriendMethod未定义'))
633
- }
634
- return this.getContactsFriendMethod({
635
- id: friendId
636
- }).then(rs => {
637
- if (!rs || !rs.data) {
638
- return Promise.reject('未找到好友' + friendId)
639
- }
640
- if (this.friendMap[friendId]) {
641
- const nextKeys = Object.keys(rs.data)
642
- Object.keys(this.friendMap[friendId]).forEach(key => {
643
- if (!nextKeys.includes(key)) {
644
- Vue.delete(this.friendMap[friendId], key)
645
- }
646
- })
647
- this.updateFriend(friendId, rs.data)
648
- } else {
649
- this.addFriend(rs.data)
650
- }
651
- return rs
652
- })
653
- }
654
631
 
655
632
  setRoomMemberData (roomId, data) {
656
633
  if (!roomId) {
@@ -761,52 +738,12 @@ export default class ClientChatContacts {
761
738
  })
762
739
  }
763
740
 
764
- refreshRoom (id) {
765
- if (!id) {
766
- return Promise.reject('缺少群id')
767
- }
768
- if (!this.getContactsRoomMethod) {
769
- return Promise.reject(new Error('getContactsRoomMethod未定义'))
770
- }
771
- return this.getContactsRoomMethod({
772
- id
773
- }).then(rs => {
774
- if (!rs || !rs.data) {
775
- return Promise.reject('未找到群' + id)
776
- }
777
- const localRoom = this.roomMap[id]
778
- if (localRoom) {
779
- this.removeRoom(id)
780
- const nextKeys = Object.keys(rs.data)
781
- Object.keys(localRoom).forEach(key => {
782
- if (!nextKeys.includes(key)) {
783
- Vue.delete(localRoom, key)
784
- }
785
- })
786
- Object.keys(rs.data).forEach(key => {
787
- Vue.set(localRoom, key, rs.data[key])
788
- })
789
- }
790
- this.addRoom(localRoom || rs.data)
791
- return rs
792
- })
793
- }
794
-
795
- isModify (qwAccountId) {
796
- return !!(qwAccountId && this.data.modifiedAccountMap[qwAccountId])
797
- }
798
-
799
- markModify (qwAccountIds) {
800
- const ids = Array.isArray(qwAccountIds) ? qwAccountIds : [qwAccountIds]
801
- ids.filter(Boolean).forEach(id => {
802
- Vue.set(this.data.modifiedAccountMap, id, true)
803
- })
741
+ markModify () {
742
+ this.data.isModify = true
804
743
  }
805
744
 
806
- unmarkModify (qwAccountId) {
807
- if (qwAccountId) {
808
- Vue.delete(this.data.modifiedAccountMap, qwAccountId)
809
- }
745
+ unmarkModify () {
746
+ this.data.isModify = false
810
747
  }
811
748
 
812
749
  reset () {
@@ -821,7 +758,6 @@ export default class ClientChatContacts {
821
758
  this.data.groupBindRoomMap = {}
822
759
  this.data.accountBindFriendMap = {}
823
760
  this.data.accountBindRoomMap = {}
824
- this.data.modifiedAccountMap = {}
825
761
  this._cacheFriendGroupCountMap = null
826
762
  this._cacheRoomGroupCountMap = null
827
763
  if (this.cancelConnectRequest) {
@@ -833,4 +769,4 @@ export default class ClientChatContacts {
833
769
  this.cancelRefreshRequest = null
834
770
  }
835
771
  }
836
- }
772
+ }