@aochuang/client-sdk 1.0.345 → 1.0.347

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 (140) hide show
  1. package/components/index.js +6 -1
  2. package/components/session-select/session-select-item.vue +8 -9
  3. package/components/wework-chat-control/company-card/company-card.vue +1 -1
  4. package/components/wework-chat-control/file-url/file-url.vue +2 -5
  5. package/components/wework-chat-control/image/image.vue +137 -2
  6. package/components/wework-chat-control/index.js +6 -6
  7. package/components/wework-chat-control/text/text.vue +22 -3
  8. package/components/wework-chat-control/util.js +12 -6
  9. package/components/wework-chat-control/video/video.vue +10 -2
  10. package/components/wework-chat-control/voice/voice.vue +1 -1
  11. package/components/wework-chat-control/wework-chat-control-config-item.vue +24 -0
  12. package/components/wework-chat-control/wework-chat-control-config-msg.vue +25 -0
  13. package/{uni-components/chat-control/chat-control-config.vue → components/wework-chat-control/wework-chat-control-config.vue} +16 -13
  14. package/components/wework-chat-panel/chat-panel-chat-status/chat-panel-chat-status.vue +73 -0
  15. package/components/wework-chat-panel/chat-panel-item.vue +12 -35
  16. package/components/wework-chat-panel/chat-panel.vue +95 -12
  17. package/package.json +10 -3
  18. package/services/client-chat/client-chat-wechat/client-chat-account.js +1 -1
  19. package/services/client-chat/client-chat-wechat/client-chat-session.js +26 -105
  20. package/services/client-chat/client-chat-wechat/client-chat.js +110 -224
  21. package/services/client-chat/client-chat-wework/client-chat-concats.js +81 -17
  22. package/services/client-chat/client-chat-wework/client-chat-message.js +46 -6
  23. package/services/client-chat/client-chat-wework/client-chat-session.js +50 -2
  24. package/services/client-chat/client-chat-wework/client-chat-socket.js +9 -1
  25. package/services/client-chat/client-chat-wework/client-chat.js +281 -11
  26. package/services/client-chat/client-chat-wework/utils.js +5 -5
  27. package/components/wework-chat-panel/chat-panel-controls/company-card/company-card.vue +0 -35
  28. package/components/wework-chat-panel/chat-panel-controls/expression/expression.vue +0 -36
  29. package/components/wework-chat-panel/chat-panel-controls/file-url/file-url.vue +0 -35
  30. package/components/wework-chat-panel/chat-panel-controls/image/image.vue +0 -36
  31. package/components/wework-chat-panel/chat-panel-controls/index.js +0 -35
  32. package/components/wework-chat-panel/chat-panel-controls/jx-sys-text/jx-sys-text.vue +0 -28
  33. package/components/wework-chat-panel/chat-panel-controls/link/link.vue +0 -35
  34. package/components/wework-chat-panel/chat-panel-controls/location/location.vue +0 -35
  35. package/components/wework-chat-panel/chat-panel-controls/text/text.vue +0 -43
  36. package/components/wework-chat-panel/chat-panel-controls/unkonw/unkonw.vue +0 -39
  37. package/components/wework-chat-panel/chat-panel-controls/video/video.vue +0 -37
  38. package/components/wework-chat-panel/chat-panel-controls/voice/voice.vue +0 -35
  39. package/uni-common/account-portray/account-portray.vue +0 -51
  40. package/uni-common/account-select/account-select-item.vue +0 -172
  41. package/uni-common/account-select/account-select.vue +0 -252
  42. package/uni-common/all-friend-avatar/all-friend-avatar.vue +0 -49
  43. package/uni-common/friend-avatar/default.svg +0 -1
  44. package/uni-common/friend-avatar/friend-avatar.vue +0 -27
  45. package/uni-common/friend-avatar/index.js +0 -3
  46. package/uni-common/friend-loader/friend-loader.vue +0 -53
  47. package/uni-common/friend-portray/friend-portray.vue +0 -56
  48. package/uni-common/group-avatar/default.svg +0 -1
  49. package/uni-common/group-avatar/group-avatar.vue +0 -18
  50. package/uni-common/group-avatar/index.js +0 -3
  51. package/uni-common/room-avatar/default.svg +0 -6
  52. package/uni-common/room-avatar/index.js +0 -3
  53. package/uni-common/room-avatar/room-avatar.vue +0 -27
  54. package/uni-common/room-loader/room-loader.vue +0 -53
  55. package/uni-common/room-portray/room-portray.vue +0 -56
  56. package/uni-components/chat-control/calling/calling.vue +0 -91
  57. package/uni-components/chat-control/calling/phone-fill.svg +0 -1
  58. package/uni-components/chat-control/calling/vidicon-fill.svg +0 -1
  59. package/uni-components/chat-control/channel-video/channel-video.vue +0 -89
  60. package/uni-components/chat-control/channel-video-card/channel-video-card.vue +0 -105
  61. package/uni-components/chat-control/channel-video-live/channel-video-live.vue +0 -92
  62. package/uni-components/chat-control/chat-control-config-item/chat-control-config-item.vue +0 -20
  63. package/uni-components/chat-control/chat-control-config-item/index.js +0 -3
  64. package/uni-components/chat-control/chat-control-config-msg/chat-control-config-msg-app.vue +0 -25
  65. package/uni-components/chat-control/chat-control-config-msg/chat-control-config-msg-h5.vue +0 -21
  66. package/uni-components/chat-control/chat-control.vue +0 -218
  67. package/uni-components/chat-control/company-card/company-card.vue +0 -123
  68. package/uni-components/chat-control/const.js +0 -28
  69. package/uni-components/chat-control/expression/expression.vue +0 -41
  70. package/uni-components/chat-control/image/image.vue +0 -68
  71. package/uni-components/chat-control/index.js +0 -89
  72. package/uni-components/chat-control/location/location.vue +0 -110
  73. package/uni-components/chat-control/member-change/member-change.vue +0 -32
  74. package/uni-components/chat-control/quote-message/quote-message.vue +0 -216
  75. package/uni-components/chat-control/real-time-position/real-time-position.vue +0 -62
  76. package/uni-components/chat-control/redpacket/red-envelope.svg +0 -1
  77. package/uni-components/chat-control/redpacket/redpacket.vue +0 -75
  78. package/uni-components/chat-control/share-card/share-card.vue +0 -101
  79. package/uni-components/chat-control/system/system.vue +0 -69
  80. package/uni-components/chat-control/system-batch-message/system-batch-message.vue +0 -30
  81. package/uni-components/chat-control/system-text/system-text.vue +0 -32
  82. package/uni-components/chat-control/text/text.vue +0 -67
  83. package/uni-components/chat-control/text-with-at/text-with-at.vue +0 -51
  84. package/uni-components/chat-control/transfer/red-transfer.svg +0 -1
  85. package/uni-components/chat-control/transfer/transfer.vue +0 -80
  86. package/uni-components/chat-control/unkonw/unkonw.vue +0 -37
  87. package/uni-components/chat-control/url/icons/file-excel-line.svg +0 -1
  88. package/uni-components/chat-control/url/icons/file-info-line.svg +0 -1
  89. package/uni-components/chat-control/url/icons/file-music-line.svg +0 -1
  90. package/uni-components/chat-control/url/icons/file-pdf-line.svg +0 -1
  91. package/uni-components/chat-control/url/icons/file-ppt-line.svg +0 -1
  92. package/uni-components/chat-control/url/icons/file-settings-line.svg +0 -1
  93. package/uni-components/chat-control/url/icons/file-text-line.svg +0 -1
  94. package/uni-components/chat-control/url/icons/file-unknow-line.svg +0 -1
  95. package/uni-components/chat-control/url/icons/file-word-line.svg +0 -1
  96. package/uni-components/chat-control/url/icons/file-zip-line.svg +0 -1
  97. package/uni-components/chat-control/url/icons/index.js +0 -24
  98. package/uni-components/chat-control/url/miniprogram.svg +0 -1
  99. package/uni-components/chat-control/url/url-miniprogram.vue +0 -116
  100. package/uni-components/chat-control/url/url.vue +0 -306
  101. package/uni-components/chat-control/url-new/icons/file-excel-line.svg +0 -1
  102. package/uni-components/chat-control/url-new/icons/file-info-line.svg +0 -1
  103. package/uni-components/chat-control/url-new/icons/file-music-line.svg +0 -1
  104. package/uni-components/chat-control/url-new/icons/file-pdf-line.svg +0 -1
  105. package/uni-components/chat-control/url-new/icons/file-ppt-line.svg +0 -1
  106. package/uni-components/chat-control/url-new/icons/file-settings-line.svg +0 -1
  107. package/uni-components/chat-control/url-new/icons/file-text-line.svg +0 -1
  108. package/uni-components/chat-control/url-new/icons/file-unknow-line.svg +0 -1
  109. package/uni-components/chat-control/url-new/icons/file-word-line.svg +0 -1
  110. package/uni-components/chat-control/url-new/icons/file-zip-line.svg +0 -1
  111. package/uni-components/chat-control/url-new/icons/index.js +0 -24
  112. package/uni-components/chat-control/url-new/url-new.vue +0 -110
  113. package/uni-components/chat-control/utils.js +0 -12
  114. package/uni-components/chat-control/video/video.vue +0 -156
  115. package/uni-components/chat-control/voice/voice.vue +0 -166
  116. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet-collect.vue +0 -84
  117. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet-system.vue +0 -28
  118. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet.vue +0 -85
  119. package/uni-components/chat-editor/chat-editor-func/chat-editor-func.vue +0 -157
  120. package/uni-components/chat-editor/chat-editor-func-at/chat-editor-func-at-panel.vue +0 -158
  121. package/uni-components/chat-editor/chat-editor-func-at/chat-editor-func-at.vue +0 -61
  122. package/uni-components/chat-editor/chat-editor-func-button/chat-editor-func-button.vue +0 -58
  123. package/uni-components/chat-editor/chat-editor-func-file/chat-editor-func-file.vue +0 -54
  124. package/uni-components/chat-editor/chat-editor-func-image/chat-editor-func-image.vue +0 -42
  125. package/uni-components/chat-editor/chat-editor-func-video/chat-editor-func-video.vue +0 -42
  126. package/uni-components/chat-editor/chat-editor-func-voice/chat-editor-func-voice.vue +0 -25
  127. package/uni-components/chat-editor/chat-editor-message-send/chat-editor-message-send.vue +0 -158
  128. package/uni-components/chat-editor/chat-editor-quote/chat-editor-quote.vue +0 -75
  129. package/uni-components/chat-editor/chat-editor.vue +0 -257
  130. package/uni-components/chat-editor/index.js +0 -10
  131. package/uni-components/chat-editor/util.js +0 -65
  132. package/uni-components/chat-panel/chat-panel-chats-box.vue +0 -238
  133. package/uni-components/chat-panel/chat-panel-chats-forward/chat-panel-chats-forward.vue +0 -273
  134. package/uni-components/chat-panel/chat-panel-chats-item.vue +0 -578
  135. package/uni-components/chat-panel/chat-panel-chats-status/chat-panel-chats-status.vue +0 -71
  136. package/uni-components/chat-panel/chat-panel-chats.vue +0 -368
  137. package/uni-components/chat-panel/chat-panel.vue +0 -227
  138. package/uni-components/contacts-group-select/contacts-group-select-item.vue +0 -85
  139. package/uni-components/contacts-group-select/contacts-group-select-panel.vue +0 -119
  140. package/uni-components/contacts-group-select/contacts-group-select.vue +0 -150
@@ -15,7 +15,7 @@ const CONNECT_STATUS = {
15
15
  Normal: 'normal',
16
16
  Loading: 'loading',
17
17
  Complete: 'complete'
18
- }
18
+ }
19
19
 
20
20
  function getAtMessageContent (data) {
21
21
  if (!data || data.isSend || !data.content) {
@@ -43,136 +43,6 @@ function appendLastAtMsgContent (lastAtMsgContent, atMessage) {
43
43
  return messages.concat(atMessage)
44
44
  }
45
45
 
46
- const ASSIGN_SESSION_LOG_PREFIX = '[client-chat][assign-session]'
47
-
48
- function getAccountUnreadSnapshot (account, accountIds) {
49
- const accountIdMap = accountIds && accountIds.reduce((result, accountId) => {
50
- result[accountId] = true
51
- return result
52
- }, {})
53
- return (account.accountUnreadMessageNumData || []).filter(item => {
54
- return !accountIdMap || accountIdMap[item.id]
55
- }).map(item => ({
56
- wechatAccountId: item.id,
57
- unread: item.num || 0,
58
- muteUnread: item.muteNum || 0
59
- }))
60
- }
61
-
62
- function getAssignAccountIds (sessions) {
63
- return Object.keys((sessions || []).reduce((result, session) => {
64
- if (session && session.wechatAccountId) {
65
- result[session.wechatAccountId] = true
66
- }
67
- return result
68
- }, {}))
69
- }
70
-
71
- function getSessionUnreadSnapshot (sessionInstance) {
72
- return Object.keys(sessionInstance.sessionMap || {}).reduce((result, conversationId) => {
73
- const session = sessionInstance.sessionMap[conversationId]
74
- result[conversationId] = {
75
- wechatAccountId: session.wechatAccountId,
76
- unread: session.unreadMsgCount || 0,
77
- mute: !!session.mute
78
- }
79
- return result
80
- }, {})
81
- }
82
-
83
- function getAssignUnreadChanges (clientChat, sessions, sessionUnreadBefore, accountIdBeforeMap, taskId) {
84
- const sessionMap = {}
85
- const sessionData = sessions || []
86
- sessionData.forEach(session => {
87
- if (!session || !session.conversationId) {
88
- return
89
- }
90
- if (sessionMap[session.conversationId]) {
91
- console.warn(ASSIGN_SESSION_LOG_PREFIX, 'duplicate-session', {
92
- taskId,
93
- conversationId: session.conversationId,
94
- wechatAccountId: session.wechatAccountId
95
- })
96
- }
97
- sessionMap[session.conversationId] = session
98
- })
99
- const accountChangeMap = {}
100
- Object.keys(sessionMap).forEach(conversationId => {
101
- const serverSession = sessionMap[conversationId]
102
- const localSession = clientChat.session.sessionMap[conversationId] || serverSession
103
- const before = sessionUnreadBefore[conversationId]
104
- const beforeUnread = before ? before.unread : 0
105
- const beforeMute = before ? before.mute : false
106
- const afterUnread = localSession.unreadMsgCount || 0
107
- const afterMute = !!localSession.mute
108
- const wechatAccountId = localSession.wechatAccountId
109
- if (!accountChangeMap[wechatAccountId]) {
110
- accountChangeMap[wechatAccountId] = {
111
- wechatAccountId,
112
- unreadDelta: 0,
113
- muteDelta: 0,
114
- isNewAccount: !accountIdBeforeMap[wechatAccountId],
115
- sessionCount: 0
116
- }
117
- }
118
- accountChangeMap[wechatAccountId].unreadDelta += afterUnread - beforeUnread
119
- accountChangeMap[wechatAccountId].muteDelta += (afterMute ? afterUnread : 0) - (beforeMute ? beforeUnread : 0)
120
- accountChangeMap[wechatAccountId].sessionCount += 1
121
- })
122
- return Object.keys(accountChangeMap).map(accountId => accountChangeMap[accountId])
123
- }
124
-
125
- function updateAssignAccountUnread (clientChat, changes, taskId, eventType) {
126
- return Promise.all(changes.map(change => {
127
- const accountUnreadBefore = getAccountUnreadSnapshot(clientChat.account, [change.wechatAccountId])[0] || {
128
- wechatAccountId: change.wechatAccountId,
129
- unread: 0,
130
- muteUnread: 0
131
- }
132
- let promise
133
- let strategy
134
- if (change.isNewAccount) {
135
- strategy = 'server-refresh'
136
- promise = clientChat.account.refreshAccountUnreadMessageNum({
137
- wechatAccountId: change.wechatAccountId
138
- })
139
- } else if (change.unreadDelta || change.muteDelta) {
140
- strategy = 'delta'
141
- promise = clientChat.account.updateAccountUnreadMessageNum(change.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => ({
142
- num: Math.max(0, (unreadMesasgeNum || 0) + change.unreadDelta),
143
- muteNum: Math.max(0, (unreadMessageMuteNum || 0) + change.muteDelta)
144
- }))
145
- } else {
146
- strategy = 'no-change'
147
- promise = Promise.resolve()
148
- }
149
- return promise.then(() => {
150
- console.info(ASSIGN_SESSION_LOG_PREFIX, 'account-unread-updated', {
151
- eventType,
152
- taskId,
153
- wechatAccountId: change.wechatAccountId,
154
- sessionCount: change.sessionCount,
155
- unreadDelta: change.unreadDelta,
156
- muteDelta: change.muteDelta,
157
- strategy,
158
- before: accountUnreadBefore,
159
- after: getAccountUnreadSnapshot(clientChat.account, [change.wechatAccountId])[0] || null
160
- })
161
- }).catch(error => {
162
- console.error(ASSIGN_SESSION_LOG_PREFIX, 'account-unread-update-error', {
163
- eventType,
164
- taskId,
165
- wechatAccountId: change.wechatAccountId,
166
- unreadDelta: change.unreadDelta,
167
- muteDelta: change.muteDelta,
168
- strategy,
169
- message: error && error.message ? error.message : String(error)
170
- })
171
- throw error
172
- })
173
- }))
174
- }
175
-
176
46
  class ClientChat {
177
47
  data = Vue.observable({
178
48
  connectStatus: CONNECT_STATUS.Normal
@@ -553,22 +423,45 @@ class ClientChat {
553
423
  rs.data.lastUpdateTime = data.updateDate
554
424
  }
555
425
  return rs
556
- }).then((rs) => {
426
+ }, ({ session }) => {
557
427
  // 更新账号未读消息数量
558
- this.account.updateAccountUnreadMessageNum(rs.data.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => {
559
- if (rs.data.mute) {
428
+ this.account.updateAccountUnreadMessageNum(session.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => {
429
+ if (session.mute) {
560
430
  return {
561
- num: (unreadMesasgeNum || 0) + (rs.data.unreadMsgCount || 0),
562
- muteNum: (unreadMessageMuteNum || 0) + (rs.data.unreadMsgCount || 0)
431
+ num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
432
+ muteNum: (unreadMessageMuteNum || 0) + (session.unreadMsgCount || 0)
563
433
  }
564
434
  } else {
565
435
  return {
566
- num: (unreadMesasgeNum || 0) + (rs.data.unreadMsgCount || 0),
436
+ num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
567
437
  muteNum: unreadMessageMuteNum
568
438
  }
569
439
  }
570
440
  })
571
- }, (error) => {
441
+ }, false).then((rs => {
442
+ // 前面更新未读消息数量只是处理会话的时候,因为getSession是异步的,会导致addMessage多次执行到这里,不会倒下面更新会话的逻辑
443
+ // 比如连续发了3条消息,然后getSession后端返回可能只会返回2条未读数,所以这里还需要补偿一下
444
+ const session = rs.data || {}
445
+ const isNewerMessage = data.wechatTime > (session.lastMsgTime || 0)
446
+ if (!data.isSend && isNewerMessage) {
447
+ if (!(this.sessionManage.currentSession && this.sessionManage.currentSession.conversationId === sessionId && this.shouldMarkCurrentSessionRead(sessionId, data))) {
448
+ // 更新账号未读消息数量
449
+ this.account.updateAccountUnreadMessageNum(session.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => {
450
+ if (session.mute) {
451
+ return {
452
+ num: (unreadMesasgeNum || 0) + 1,
453
+ muteNum: (unreadMessageMuteNum || 0) + 1
454
+ }
455
+ } else {
456
+ return {
457
+ num: (unreadMesasgeNum || 0) + 1,
458
+ muteNum: unreadMessageMuteNum
459
+ }
460
+ }
461
+ })
462
+ }
463
+ }
464
+ }), (error) => {
572
465
  this.socket.addLog({
573
466
  group: 'client-chat-message:onAddMessageSuccess',
574
467
  content: {
@@ -598,7 +491,7 @@ class ClientChat {
598
491
  lastUpdateTime: data.updateDate,
599
492
  unreadMsgCount: session.unreadMsgCount
600
493
  }
601
- if (!data.isSend && isNewerMessage) {
494
+ if (!data.isSend && isNewerMessage) {
602
495
  if (this.sessionManage.currentSession && this.sessionManage.currentSession.conversationId === sessionId && this.shouldMarkCurrentSessionRead(sessionId, data)) {
603
496
  // 标记已读
604
497
  this.session.setSessionRead(sessionId)
@@ -701,21 +594,44 @@ class ClientChat {
701
594
  rs.data.lastAtMsgContent = appendLastAtMsgContent(rs.data.lastAtMsgContent, atMessage)
702
595
  }
703
596
  return rs
704
- }).then((rs) => {
597
+ }, ({ session }) => {
705
598
  // 更新账号未读消息数量
706
- this.account.updateAccountUnreadMessageNum(rs.data.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => {
707
- if (rs.data.mute) {
599
+ this.account.updateAccountUnreadMessageNum(session.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => {
600
+ if (session.mute) {
708
601
  return {
709
- num: (unreadMesasgeNum || 0) + (rs.data.unreadMsgCount || 0),
710
- muteNum: (unreadMessageMuteNum || 0) + (rs.data.unreadMsgCount || 0)
602
+ num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
603
+ muteNum: (unreadMessageMuteNum || 0) + (session.unreadMsgCount || 0)
711
604
  }
712
605
  } else {
713
606
  return {
714
- num: (unreadMesasgeNum || 0) + (rs.data.unreadMsgCount || 0),
607
+ num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
715
608
  muteNum: unreadMessageMuteNum
716
609
  }
717
610
  }
718
611
  })
612
+ }, false).then(rs => {
613
+ // 前面更新未读消息数量只是处理会话的时候,因为getSession是异步的,会导致addMessage多次执行到这里,不会倒下面更新会话的逻辑
614
+ // 比如连续发了3条消息,然后getSession后端返回可能只会返回2条未读数,所以这里还需要补偿一下
615
+ const session = rs.data || {}
616
+ const isNewerMessage = data.wechatTime > (session.lastMsgTime || 0)
617
+ if (!data.isSend && isNewerMessage) {
618
+ if (!(this.sessionManage.currentSession && this.sessionManage.currentSession.conversationId === sessionId && this.shouldMarkCurrentSessionRead(sessionId, data))) {
619
+ // 更新账号未读消息数量
620
+ this.account.updateAccountUnreadMessageNum(session.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => {
621
+ if (session.mute) {
622
+ return {
623
+ num: (unreadMesasgeNum || 0) + 1,
624
+ muteNum: (unreadMessageMuteNum || 0) + 1
625
+ }
626
+ } else {
627
+ return {
628
+ num: (unreadMesasgeNum || 0) + 1,
629
+ muteNum: unreadMessageMuteNum
630
+ }
631
+ }
632
+ })
633
+ }
634
+ }
719
635
  }, (error) => {
720
636
  this.socket.addLog({
721
637
  group: 'client-chat-message:onAddMessageSuccess',
@@ -996,16 +912,6 @@ class ClientChat {
996
912
  },
997
913
  // 好友有变化,如分配的情况
998
914
  onCmdFriendInfoChanged: ({ data }) => {
999
- const assignAccountUnreadBefore = data.changeType === 4 ? getAccountUnreadSnapshot(this.account) : null
1000
- if (data.changeType === 4) {
1001
- console.info(ASSIGN_SESSION_LOG_PREFIX, 'socket-event', {
1002
- eventType: 'friend-info-changed',
1003
- taskId: data.taskId,
1004
- changeType: data.changeType,
1005
- itemCount: Array.isArray(data.friends) ? data.friends.length : 0,
1006
- accountUnreadBefore: assignAccountUnreadBefore
1007
- })
1008
- }
1009
915
  if (!this.socketFriendInfoChangedSerialQueue) {
1010
916
  this.socketFriendInfoChangedSerialQueue = createSerialQueue()
1011
917
  }
@@ -1019,19 +925,14 @@ class ClientChat {
1019
925
  accountIds: (this.account.accountData || []).map(v => v.id)
1020
926
  })
1021
927
  } else {
1022
- const sessionUnreadBefore = getSessionUnreadSnapshot(this.session)
1023
- const accountIdBeforeMap = Object.keys(this.account.accountMap || {}).reduce((result, accountId) => {
1024
- result[accountId] = true
1025
- return result
1026
- }, {})
1027
928
  // 增量拉取分配产生的会话
1028
929
  return this.session.loadAssignTaskSessionData({
1029
930
  taskId: data.taskId
1030
931
  }).then((rs) => {
1031
- const wechatAccountIds = getAssignAccountIds(rs)
1032
- const accountUnreadBefore = assignAccountUnreadBefore.filter(item => wechatAccountIds.indexOf(item.wechatAccountId) >= 0)
1033
- const accountUnreadChanges = getAssignUnreadChanges(this, rs, sessionUnreadBefore, accountIdBeforeMap, data.taskId)
1034
- let accountUnreadUpdated = false
932
+ const wechatAccountIds = Object.keys((rs || []).reduce((rs, v) => {
933
+ rs[v.wechatAccountId] = true
934
+ return rs
935
+ }, {}))
1035
936
  const changeFriendMap = {}
1036
937
  // 删除changeType为3移除的好友,例如转移的场景
1037
938
  if (data.friends && data.friends.length) {
@@ -1064,27 +965,25 @@ class ClientChat {
1064
965
  return this.contacts.getFriend(sessionFriendId, true)
1065
966
  })
1066
967
  }
1067
- ps = ps.then(() => updateAssignAccountUnread(this, accountUnreadChanges, data.taskId, 'friend-info-changed')).then(() => {
1068
- accountUnreadUpdated = true
1069
- }).catch(error => {
1070
- console.error(ASSIGN_SESSION_LOG_PREFIX, 'socket-process-error', {
1071
- eventType: 'friend-info-changed',
1072
- taskId: data.taskId,
1073
- message: error && error.message ? error.message : String(error)
968
+ // 刷新工作微信号未读消息数量
969
+ if (rs && rs.length) {
970
+ rs.forEach(session => {
971
+ this.account.updateAccountUnreadMessageNum(session.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => {
972
+ if (session.mute) {
973
+ return {
974
+ num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
975
+ muteNum: (unreadMessageMuteNum || 0) + (session.unreadMsgCount || 0)
976
+ }
977
+ } else {
978
+ return {
979
+ num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
980
+ muteNum: unreadMessageMuteNum
981
+ }
982
+ }
983
+ })
1074
984
  })
1075
- throw error
1076
- })
985
+ }
1077
986
  return ps.finally(() => {
1078
- console.info(ASSIGN_SESSION_LOG_PREFIX, 'socket-complete', {
1079
- eventType: 'friend-info-changed',
1080
- taskId: data.taskId,
1081
- sessionCount: rs ? rs.length : 0,
1082
- wechatAccountIds,
1083
- accountUnreadChanges,
1084
- accountUnreadBefore,
1085
- accountUnreadAfter: getAccountUnreadSnapshot(this.account, wechatAccountIds),
1086
- accountUnreadUpdated
1087
- })
1088
987
  // 这里应该标记那些工作微信号的通讯录修改了,后面要在界面打个提示,告诉用户通讯录变化了,让手动刷新一下
1089
988
  // 同时也将缓存都清理一下,例如工作微信号分组统计数量等
1090
989
  this.contacts.markModify() // 标记通讯录修改
@@ -1123,31 +1022,16 @@ class ClientChat {
1123
1022
  },
1124
1023
  // 群聊有变化,如分配的情况
1125
1024
  onCmdChatroomInfoChanged: ({ data }) => {
1126
- const assignAccountUnreadBefore = data.changeType === 4 ? getAccountUnreadSnapshot(this.account) : null
1127
- if (data.changeType === 4) {
1128
- console.info(ASSIGN_SESSION_LOG_PREFIX, 'socket-event', {
1129
- eventType: 'chatroom-info-changed',
1130
- taskId: data.taskId,
1131
- changeType: data.changeType,
1132
- itemCount: Array.isArray(data.chatrooms) ? data.chatrooms.length : 0,
1133
- accountUnreadBefore: assignAccountUnreadBefore
1134
- })
1135
- }
1136
1025
  // 配分群聊
1137
1026
  if (data.changeType === 4) {
1138
- const sessionUnreadBefore = getSessionUnreadSnapshot(this.session)
1139
- const accountIdBeforeMap = Object.keys(this.account.accountMap || {}).reduce((result, accountId) => {
1140
- result[accountId] = true
1141
- return result
1142
- }, {})
1143
1027
  // 增量拉取分配产生的会话
1144
1028
  return this.session.loadAssignTaskSessionData({
1145
1029
  taskId: data.taskId
1146
1030
  }).then((rs) => {
1147
- const wechatAccountIds = getAssignAccountIds(rs)
1148
- const accountUnreadBefore = assignAccountUnreadBefore.filter(item => wechatAccountIds.indexOf(item.wechatAccountId) >= 0)
1149
- const accountUnreadChanges = getAssignUnreadChanges(this, rs, sessionUnreadBefore, accountIdBeforeMap, data.taskId)
1150
- let accountUnreadUpdated = false
1031
+ const wechatAccountIds = Object.keys((rs || []).reduce((rs, v) => {
1032
+ rs[v.wechatAccountId] = true
1033
+ return rs
1034
+ }, {}))
1151
1035
  // 删除changeType为3移除的群聊,例如转移的场景
1152
1036
  if (data.chatrooms && data.chatrooms.length) {
1153
1037
  data.chatrooms.forEach(room => {
@@ -1163,27 +1047,25 @@ class ClientChat {
1163
1047
  ps = this.account.reloadData()
1164
1048
  }
1165
1049
  }
1166
- ps = ps.then(() => updateAssignAccountUnread(this, accountUnreadChanges, data.taskId, 'chatroom-info-changed')).then(() => {
1167
- accountUnreadUpdated = true
1168
- }).catch(error => {
1169
- console.error(ASSIGN_SESSION_LOG_PREFIX, 'socket-process-error', {
1170
- eventType: 'chatroom-info-changed',
1171
- taskId: data.taskId,
1172
- message: error && error.message ? error.message : String(error)
1050
+ // 刷新工作微信号未读消息数量
1051
+ if (rs && rs.length) {
1052
+ rs.forEach(session => {
1053
+ this.account.updateAccountUnreadMessageNum(session.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => {
1054
+ if (session.mute) {
1055
+ return {
1056
+ num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
1057
+ muteNum: (unreadMessageMuteNum || 0) + (session.unreadMsgCount || 0)
1058
+ }
1059
+ } else {
1060
+ return {
1061
+ num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
1062
+ muteNum: unreadMessageMuteNum
1063
+ }
1064
+ }
1065
+ })
1173
1066
  })
1174
- throw error
1175
- })
1067
+ }
1176
1068
  return ps.finally(() => {
1177
- console.info(ASSIGN_SESSION_LOG_PREFIX, 'socket-complete', {
1178
- eventType: 'chatroom-info-changed',
1179
- taskId: data.taskId,
1180
- sessionCount: rs ? rs.length : 0,
1181
- wechatAccountIds,
1182
- accountUnreadChanges,
1183
- accountUnreadBefore,
1184
- accountUnreadAfter: getAccountUnreadSnapshot(this.account, wechatAccountIds),
1185
- accountUnreadUpdated
1186
- })
1187
1069
  // 这里应该标记那些工作微信号的通讯录修改了,后面要在界面打个提示,告诉用户通讯录变化了,让手动刷新一下
1188
1070
  // 同时也将缓存都清理一下,例如工作微信号分组统计数量等
1189
1071
  this.contacts.markModify() // 标记通讯录修改
@@ -1258,9 +1140,13 @@ class ClientChat {
1258
1140
  onCmdFriendAccepted: ({ data }) => {
1259
1141
  // 刷新指定微信号请求数量
1260
1142
  if (data.wechatAccountId) {
1261
- this.account.getAccountGreetingUnreadMsgCount({
1262
- wechatAccountId: data.wechatAccountId
1263
- })
1143
+ if (!this.account.accountMap[data.wechatAccountId]) {
1144
+ this.account.reloadData()
1145
+ } else {
1146
+ this.account.getAccountGreetingUnreadMsgCount({
1147
+ wechatAccountId: data.wechatAccountId
1148
+ })
1149
+ }
1264
1150
  }
1265
1151
  // 刷新所有微信号请求数量
1266
1152
  this.account.getAccountGreetingUnreadMsgCount()
@@ -126,11 +126,7 @@ export default class ClientChatContacts {
126
126
  */
127
127
  roomBindMemberMap: {},
128
128
 
129
- /**
130
- * 标记通讯录是否修改了
131
- * 如果修改了,比如接收到了分配好友的会话时,一定通讯录变了,变了的时候界面需要根据这个状态刷新通讯录
132
- */
133
- isModify: false
129
+ modifiedAccountMap: {}
134
130
  })
135
131
 
136
132
  friendMap = {}
@@ -237,10 +233,6 @@ export default class ClientChatContacts {
237
233
  return this.data.roomGroupData
238
234
  }
239
235
 
240
- get isModify () {
241
- return this.data.isModify
242
- }
243
-
244
236
  setRoomGroup (data) {
245
237
  this.data.roomGroupData = []
246
238
  if (data && data.length) {
@@ -491,10 +483,10 @@ export default class ClientChatContacts {
491
483
  }
492
484
  }
493
485
  const qwAccountId = this.roomMap[id].qwAccountId
494
- if (qwAccountId && this.data.accountBindFriendMap[qwAccountId] && this.data.accountBindFriendMap[qwAccountId][groupId]) {
495
- const bindIndex = this.data.accountBindFriendMap[qwAccountId][groupId].indexOf(this.roomMap[id])
486
+ if (qwAccountId && this.data.accountBindRoomMap[qwAccountId] && this.data.accountBindRoomMap[qwAccountId][groupId]) {
487
+ const bindIndex = this.data.accountBindRoomMap[qwAccountId][groupId].indexOf(this.roomMap[id])
496
488
  if (bindIndex >= 0) {
497
- this.data.accountBindFriendMap[qwAccountId][groupId].splice(bindIndex, 1)
489
+ this.data.accountBindRoomMap[qwAccountId][groupId].splice(bindIndex, 1)
498
490
  }
499
491
  }
500
492
  })
@@ -628,6 +620,37 @@ export default class ClientChatContacts {
628
620
  return rs
629
621
  })
630
622
  }
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
+ }
631
654
 
632
655
  setRoomMemberData (roomId, data) {
633
656
  if (!roomId) {
@@ -738,12 +761,52 @@ export default class ClientChatContacts {
738
761
  })
739
762
  }
740
763
 
741
- markModify () {
742
- this.data.isModify = true
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
+ })
743
804
  }
744
805
 
745
- unmarkModify () {
746
- this.data.isModify = false
806
+ unmarkModify (qwAccountId) {
807
+ if (qwAccountId) {
808
+ Vue.delete(this.data.modifiedAccountMap, qwAccountId)
809
+ }
747
810
  }
748
811
 
749
812
  reset () {
@@ -758,6 +821,7 @@ export default class ClientChatContacts {
758
821
  this.data.groupBindRoomMap = {}
759
822
  this.data.accountBindFriendMap = {}
760
823
  this.data.accountBindRoomMap = {}
824
+ this.data.modifiedAccountMap = {}
761
825
  this._cacheFriendGroupCountMap = null
762
826
  this._cacheRoomGroupCountMap = null
763
827
  if (this.cancelConnectRequest) {
@@ -769,4 +833,4 @@ export default class ClientChatContacts {
769
833
  this.cancelRefreshRequest = null
770
834
  }
771
835
  }
772
- }
836
+ }