@aochuang/client-sdk 1.0.376 → 1.0.378

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 (170) hide show
  1. package/components/chat-editor/chat-editor-suggestions/chat-editor-suggestions.vue +40 -4
  2. package/components/chat-editor/chat-editor.vue +75 -5
  3. package/components/index.js +1 -6
  4. package/components/session-select/session-select-item.vue +9 -8
  5. package/components/wechat-chat-control/location/location.vue +3 -3
  6. package/components/wework-chat-control/channel-live/channel-live.vue +2 -7
  7. package/components/wework-chat-control/company-card/company-card.vue +1 -1
  8. package/components/wework-chat-control/custom-expression/custom-expression.vue +1 -2
  9. package/components/wework-chat-control/file-url/file-url.vue +16 -34
  10. package/components/wework-chat-control/image/image.vue +2 -137
  11. package/components/wework-chat-control/index.js +7 -15
  12. package/components/wework-chat-control/location/location.vue +3 -3
  13. package/components/wework-chat-control/red-envelopes/red-envelopes.vue +2 -3
  14. package/components/wework-chat-control/text/text.vue +144 -24
  15. package/components/wework-chat-control/url/url-miniprogram.vue +7 -6
  16. package/components/wework-chat-control/url/url.vue +2 -26
  17. package/components/wework-chat-control/util.js +17 -26
  18. package/components/wework-chat-control/video/video.vue +2 -10
  19. package/components/wework-chat-control/voice/voice.vue +2 -9
  20. package/components/wework-chat-panel/chat-panel-controls/company-card/company-card.vue +35 -0
  21. package/components/wework-chat-panel/chat-panel-controls/expression/expression.vue +36 -0
  22. package/components/wework-chat-panel/chat-panel-controls/file-url/file-url.vue +35 -0
  23. package/components/wework-chat-panel/chat-panel-controls/image/image.vue +36 -0
  24. package/components/wework-chat-panel/chat-panel-controls/index.js +35 -0
  25. package/components/wework-chat-panel/chat-panel-controls/jx-sys-text/jx-sys-text.vue +28 -0
  26. package/components/wework-chat-panel/chat-panel-controls/link/link.vue +35 -0
  27. package/components/wework-chat-panel/chat-panel-controls/location/location.vue +35 -0
  28. package/components/wework-chat-panel/chat-panel-controls/text/text.vue +43 -0
  29. package/components/wework-chat-panel/chat-panel-controls/unkonw/unkonw.vue +39 -0
  30. package/components/wework-chat-panel/chat-panel-controls/video/video.vue +37 -0
  31. package/components/wework-chat-panel/chat-panel-controls/voice/voice.vue +35 -0
  32. package/components/wework-chat-panel/chat-panel-item.vue +25 -56
  33. package/components/wework-chat-panel/chat-panel.vue +13 -96
  34. package/package.json +3 -10
  35. package/services/client-chat/client-chat-wechat/client-chat-message.js +15 -5
  36. package/services/client-chat/client-chat-wechat/client-chat-session.js +13 -50
  37. package/services/client-chat/client-chat-wechat/client-chat.js +4 -48
  38. package/services/client-chat/client-chat-wechat/docs//350/264/246/345/217/267/346/234/252/350/257/273/346/225/260/351/207/217/344/270/216/344/274/232/350/257/235/346/234/252/350/257/273/346/225/260/351/207/217/344/270/215/344/270/200/350/207/264/351/227/256/351/242/230/344/277/256/345/244/215.md +4 -2
  39. package/services/client-chat/client-chat-wework/client-chat-account.js +1 -84
  40. package/services/client-chat/client-chat-wework/client-chat-concats.js +17 -81
  41. package/services/client-chat/client-chat-wework/client-chat-message.js +5 -45
  42. package/services/client-chat/client-chat-wework/client-chat-session.js +4 -59
  43. package/services/client-chat/client-chat-wework/client-chat-socket.js +1 -13
  44. package/services/client-chat/client-chat-wework/client-chat.js +11 -320
  45. package/services/client-chat/client-chat-wework/utils.js +5 -5
  46. package/uni-common/account-portray/account-portray.vue +51 -0
  47. package/uni-common/account-select/account-select-item.vue +172 -0
  48. package/uni-common/account-select/account-select.vue +252 -0
  49. package/uni-common/all-friend-avatar/all-friend-avatar.vue +49 -0
  50. package/uni-common/friend-avatar/default.svg +1 -0
  51. package/uni-common/friend-avatar/friend-avatar.vue +27 -0
  52. package/uni-common/friend-avatar/index.js +3 -0
  53. package/uni-common/friend-loader/friend-loader.vue +53 -0
  54. package/uni-common/friend-portray/friend-portray.vue +56 -0
  55. package/uni-common/group-avatar/default.svg +1 -0
  56. package/uni-common/group-avatar/group-avatar.vue +18 -0
  57. package/uni-common/group-avatar/index.js +3 -0
  58. package/uni-common/room-avatar/default.svg +6 -0
  59. package/uni-common/room-avatar/index.js +3 -0
  60. package/uni-common/room-avatar/room-avatar.vue +27 -0
  61. package/uni-common/room-loader/room-loader.vue +53 -0
  62. package/uni-common/room-portray/room-portray.vue +56 -0
  63. package/uni-components/chat-control/calling/calling.vue +91 -0
  64. package/uni-components/chat-control/calling/phone-fill.svg +1 -0
  65. package/uni-components/chat-control/calling/vidicon-fill.svg +1 -0
  66. package/uni-components/chat-control/channel-video/channel-video.vue +89 -0
  67. package/uni-components/chat-control/channel-video-card/channel-video-card.vue +105 -0
  68. package/uni-components/chat-control/channel-video-live/channel-video-live.vue +92 -0
  69. package/uni-components/chat-control/chat-control-config-item/chat-control-config-item.vue +20 -0
  70. package/uni-components/chat-control/chat-control-config-item/index.js +3 -0
  71. package/uni-components/chat-control/chat-control-config-msg/chat-control-config-msg-app.vue +25 -0
  72. package/uni-components/chat-control/chat-control-config-msg/chat-control-config-msg-h5.vue +21 -0
  73. package/{components/wework-chat-control/wework-chat-control-config.vue → uni-components/chat-control/chat-control-config.vue} +13 -16
  74. package/uni-components/chat-control/chat-control.vue +218 -0
  75. package/uni-components/chat-control/company-card/company-card.vue +123 -0
  76. package/uni-components/chat-control/const.js +28 -0
  77. package/uni-components/chat-control/expression/expression.vue +41 -0
  78. package/uni-components/chat-control/image/image.vue +68 -0
  79. package/uni-components/chat-control/index.js +89 -0
  80. package/uni-components/chat-control/location/location.vue +110 -0
  81. package/uni-components/chat-control/member-change/member-change.vue +32 -0
  82. package/uni-components/chat-control/quote-message/quote-message.vue +216 -0
  83. package/uni-components/chat-control/real-time-position/real-time-position.vue +62 -0
  84. package/uni-components/chat-control/redpacket/red-envelope.svg +1 -0
  85. package/uni-components/chat-control/redpacket/redpacket.vue +75 -0
  86. package/uni-components/chat-control/share-card/share-card.vue +101 -0
  87. package/uni-components/chat-control/system/system.vue +69 -0
  88. package/uni-components/chat-control/system-batch-message/system-batch-message.vue +30 -0
  89. package/uni-components/chat-control/system-text/system-text.vue +32 -0
  90. package/uni-components/chat-control/text/text.vue +67 -0
  91. package/uni-components/chat-control/text-with-at/text-with-at.vue +51 -0
  92. package/uni-components/chat-control/transfer/red-transfer.svg +1 -0
  93. package/uni-components/chat-control/transfer/transfer.vue +80 -0
  94. package/uni-components/chat-control/unkonw/unkonw.vue +37 -0
  95. package/uni-components/chat-control/url/icons/file-excel-line.svg +1 -0
  96. package/uni-components/chat-control/url/icons/file-info-line.svg +1 -0
  97. package/uni-components/chat-control/url/icons/file-music-line.svg +1 -0
  98. package/uni-components/chat-control/url/icons/file-pdf-line.svg +1 -0
  99. package/uni-components/chat-control/url/icons/file-ppt-line.svg +1 -0
  100. package/uni-components/chat-control/url/icons/file-settings-line.svg +1 -0
  101. package/uni-components/chat-control/url/icons/file-text-line.svg +1 -0
  102. package/uni-components/chat-control/url/icons/file-unknow-line.svg +1 -0
  103. package/uni-components/chat-control/url/icons/file-word-line.svg +1 -0
  104. package/uni-components/chat-control/url/icons/file-zip-line.svg +1 -0
  105. package/uni-components/chat-control/url/icons/index.js +24 -0
  106. package/uni-components/chat-control/url/miniprogram.svg +1 -0
  107. package/uni-components/chat-control/url/url-miniprogram.vue +116 -0
  108. package/uni-components/chat-control/url/url.vue +306 -0
  109. package/uni-components/chat-control/url-new/icons/file-excel-line.svg +1 -0
  110. package/uni-components/chat-control/url-new/icons/file-info-line.svg +1 -0
  111. package/uni-components/chat-control/url-new/icons/file-music-line.svg +1 -0
  112. package/uni-components/chat-control/url-new/icons/file-pdf-line.svg +1 -0
  113. package/uni-components/chat-control/url-new/icons/file-ppt-line.svg +1 -0
  114. package/uni-components/chat-control/url-new/icons/file-settings-line.svg +1 -0
  115. package/uni-components/chat-control/url-new/icons/file-text-line.svg +1 -0
  116. package/uni-components/chat-control/url-new/icons/file-unknow-line.svg +1 -0
  117. package/uni-components/chat-control/url-new/icons/file-word-line.svg +1 -0
  118. package/uni-components/chat-control/url-new/icons/file-zip-line.svg +1 -0
  119. package/uni-components/chat-control/url-new/icons/index.js +24 -0
  120. package/uni-components/chat-control/url-new/url-new.vue +110 -0
  121. package/uni-components/chat-control/utils.js +12 -0
  122. package/uni-components/chat-control/video/video.vue +156 -0
  123. package/uni-components/chat-control/voice/voice.vue +166 -0
  124. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet-collect.vue +84 -0
  125. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet-system.vue +28 -0
  126. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet.vue +85 -0
  127. package/uni-components/chat-editor/chat-editor-func/chat-editor-func.vue +157 -0
  128. package/uni-components/chat-editor/chat-editor-func-at/chat-editor-func-at-panel.vue +158 -0
  129. package/uni-components/chat-editor/chat-editor-func-at/chat-editor-func-at.vue +61 -0
  130. package/uni-components/chat-editor/chat-editor-func-button/chat-editor-func-button.vue +58 -0
  131. package/uni-components/chat-editor/chat-editor-func-file/chat-editor-func-file.vue +54 -0
  132. package/uni-components/chat-editor/chat-editor-func-image/chat-editor-func-image.vue +42 -0
  133. package/uni-components/chat-editor/chat-editor-func-video/chat-editor-func-video.vue +42 -0
  134. package/uni-components/chat-editor/chat-editor-func-voice/chat-editor-func-voice.vue +25 -0
  135. package/uni-components/chat-editor/chat-editor-message-send/chat-editor-message-send.vue +158 -0
  136. package/uni-components/chat-editor/chat-editor-quote/chat-editor-quote.vue +75 -0
  137. package/uni-components/chat-editor/chat-editor.vue +257 -0
  138. package/uni-components/chat-editor/index.js +10 -0
  139. package/uni-components/chat-editor/util.js +65 -0
  140. package/uni-components/chat-panel/chat-panel-chats-box.vue +238 -0
  141. package/uni-components/chat-panel/chat-panel-chats-forward/chat-panel-chats-forward.vue +273 -0
  142. package/uni-components/chat-panel/chat-panel-chats-item.vue +578 -0
  143. package/uni-components/chat-panel/chat-panel-chats-status/chat-panel-chats-status.vue +71 -0
  144. package/uni-components/chat-panel/chat-panel-chats.vue +368 -0
  145. package/uni-components/chat-panel/chat-panel.vue +227 -0
  146. package/uni-components/contacts-group-select/contacts-group-select-item.vue +85 -0
  147. package/uni-components/contacts-group-select/contacts-group-select-panel.vue +119 -0
  148. package/uni-components/contacts-group-select/contacts-group-select.vue +150 -0
  149. package/common/.DS_Store +0 -0
  150. package/components/.DS_Store +0 -0
  151. package/components/wechat-chat-control/.DS_Store +0 -0
  152. package/components/wechat-chat-control/transfer/.DS_Store +0 -0
  153. package/components/wechat-chat-control/url/.DS_Store +0 -0
  154. package/components/wechat-chat-control/voice/.DS_Store +0 -0
  155. package/components/wework-chat-control/channel-card/channel-card.vue +0 -144
  156. package/components/wework-chat-control/link/.DS_Store +0 -0
  157. package/components/wework-chat-control/merge-message/merge-message-panel.vue +0 -63
  158. package/components/wework-chat-control/merge-message/merge-message.vue +0 -84
  159. package/components/wework-chat-control/merge-message/util.js +0 -59
  160. package/components/wework-chat-control/metting/enterprise-wechat.png +0 -0
  161. package/components/wework-chat-control/metting/meeting-video.svg +0 -4
  162. package/components/wework-chat-control/metting/metting.vue +0 -181
  163. package/components/wework-chat-control/text/text-default.vue +0 -99
  164. package/components/wework-chat-control/text/text-quote.vue +0 -105
  165. package/components/wework-chat-control/url/url-channel-live.vue +0 -53
  166. package/components/wework-chat-control/video/.DS_Store +0 -0
  167. package/components/wework-chat-control/wework-chat-control-config-item.vue +0 -24
  168. package/components/wework-chat-control/wework-chat-control-config-msg.vue +0 -25
  169. package/components/wework-chat-panel/chat-panel-chat-status/chat-panel-chat-status.vue +0 -73
  170. package/services/.DS_Store +0 -0
package/package.json CHANGED
@@ -1,16 +1,9 @@
1
1
  {
2
2
  "name": "@aochuang/client-sdk",
3
- "version": "1.0.376",
3
+ "version": "1.0.378",
4
4
  "description": "",
5
- "files": [
6
- "common",
7
- "components",
8
- "services",
9
- "utils",
10
- "dist"
11
- ],
12
- "exports": {
13
- ".": "./components/index.js"
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1"
14
7
  },
15
8
  "repository": {
16
9
  "type": "git",
@@ -146,6 +146,21 @@ export default class ClientChatMessage {
146
146
  }
147
147
  }
148
148
  if (fireEvent !== false) {
149
+ // 先执行onAddMessageSuccess再发add-message事件,保证会话的getSession轮询先由这里发起、更新会话的回调排在最前面,
150
+ // 外部监听add-message后再调getSession只是复用同一个轮询
151
+ // try/catch是为了避免回调里的异常把add-message事件吞掉(外部的新消息提醒、本地消息缓存都依赖这个事件)
152
+ try {
153
+ this.onAddMessageSuccess && this.onAddMessageSuccess({
154
+ data,
155
+ lastMessageTime,
156
+ isBeforeLastMessage
157
+ })
158
+ } catch (error) {
159
+ console.error('[client-chat-message] onAddMessageSuccess error', {
160
+ messageId: data.id,
161
+ error
162
+ })
163
+ }
149
164
  // 如果消息包含这种情况,就不能往外发送add-message事件
150
165
  // 因为例如群发的消息,他没有会话,导致前端在处理来了新消息通知铃声提醒,获取会话一直获取不到,然后会总是发送请求
151
166
  if (!isBeforeLastMessage && !isAutoReadMessage(data) && !shouldIgnoreSessionByMessage(data) && !isDeletedMsg(data) && !isBlockedMsg(data)) {
@@ -153,11 +168,6 @@ export default class ClientChatMessage {
153
168
  data
154
169
  })
155
170
  }
156
- this.onAddMessageSuccess && this.onAddMessageSuccess({
157
- data,
158
- lastMessageTime,
159
- isBeforeLastMessage
160
- })
161
171
  }
162
172
  }
163
173
 
@@ -242,37 +242,19 @@ export default class ClientChatSession {
242
242
  }
243
243
  }
244
244
 
245
- _addGetSessionSerializeTask (pollRequest, serializeMethod, taskOptions = {}) {
246
- if (!serializeMethod) {
247
- return false
248
- }
249
- const messageId = taskOptions.messageId
250
- if (messageId && pollRequest.serializeTaskMap[messageId]) {
251
- return false
252
- }
253
- const task = {
254
- messageId,
255
- wechatTime: taskOptions.wechatTime || 0,
256
- index: pollRequest.serializeTasks.length,
257
- serializeMethod
258
- }
259
- pollRequest.serializeTasks.push(task)
260
- if (messageId) {
261
- pollRequest.serializeTaskMap[messageId] = task
262
- }
263
- return true
264
- }
265
-
266
- getSession (sessionId, serializeMethod, taskOptions = {}) {
245
+ getSession (sessionId, serializeMethod) {
267
246
  if (this.sessionMap[sessionId]) {
268
247
  return Promise.resolve({
269
248
  data: this.sessionMap[sessionId]
270
249
  })
271
250
  }
272
251
  // 这里需要轮询从后端获取会话,后端会话更新和创建是异步的,所以要多轮训请求几次
252
+ // 同一个会话只会有一个轮询,轮询期间再次调用只把serializeMethod挂到这个轮询上,等结果回来后依次执行
273
253
  let pollRequest = this.pollRequestMap[sessionId]
274
254
  if (pollRequest && pollRequest.ps) {
275
- this._addGetSessionSerializeTask(pollRequest, serializeMethod, taskOptions)
255
+ if (serializeMethod) {
256
+ pollRequest.serializeMethods.push(serializeMethod)
257
+ }
276
258
  return pollRequest.ps
277
259
  }
278
260
 
@@ -292,50 +274,33 @@ export default class ClientChatSession {
292
274
  return Promise.reject(error)
293
275
  })
294
276
  })
295
- pollRequest.serializeTasks = []
296
- pollRequest.serializeTaskMap = {}
277
+ pollRequest.serializeMethods = serializeMethod ? [serializeMethod] : []
297
278
  pollRequest.requestCount = 0
298
279
  pollRequest.emptyResponseCount = 0
299
280
  pollRequest.requestErrorCount = 0
300
281
  pollRequest.lastRequestError = null
301
282
  pollRequest.startedAt = Date.now()
302
- this._addGetSessionSerializeTask(pollRequest, serializeMethod, taskOptions)
303
283
  this.pollRequestMap[sessionId] = pollRequest
304
284
  this._addGetSessionLog('创建会话轮询', {
305
- sessionId,
306
- messageId: taskOptions.messageId,
307
- wechatTime: taskOptions.wechatTime,
308
- taskCount: pollRequest.serializeTasks.length
285
+ sessionId
309
286
  })
310
287
  pollRequest.ps = pollRequest.start().then(rs => {
311
288
  if (!rs.data) {
312
289
  return Promise.reject('未找到会话' + sessionId)
313
290
  }
314
291
  /**
315
- * 轮询合并上下文,会依次传给每个 serializeMethod(见 client-chat.js onCmdNewMessage 里 getSession 的回调)
292
+ * 轮询合并上下文,会依次传给每个 serializeMethod(见 client-chat.js onAddMessageSuccess 里 getSession 的回调)
316
293
  * baseLastMsgTime 服务端返回的会话 lastMsgTime,用来判断某条消息服务端是否已经算进 unreadMsgCount
317
- * processedMessageIds 本次轮询期间处理过的所有消息 id
318
- * skippedMessageIds 服务端返回的会话已经包含(wechatTime <= baseLastMsgTime)、本地不再给会话未读 +1 的消息 id
319
- * unreadMessageIds 本地给会话未读 +1 的消息 id
320
294
  * accountUnreadDelta 本次轮询期间需要累加到工作微信号(账号)未读数量上的条数。
321
- * 注意它和 unreadMessageIds.length 不同:账号未读初始值是登录时取的,不包含本次收到的任何消息,
322
- * 所以被 skip 的消息也要算进来;只有"正在看当前会话被直接标记已读"的消息不算
295
+ * 账号未读初始值是登录时取的,不包含本次收到的任何消息,所以服务端已经算进会话 unreadMsgCount 的消息也要算进来;
296
+ * 只有"正在看当前会话被直接标记已读"的消息不算
323
297
  */
324
298
  const context = {
325
299
  baseLastMsgTime: rs.data.lastMsgTime || 0,
326
- processedMessageIds: [],
327
- skippedMessageIds: [],
328
- unreadMessageIds: [],
329
300
  accountUnreadDelta: 0
330
301
  }
331
- const serializeTasks = pollRequest.serializeTasks.slice().sort((a, b) => {
332
- return a.wechatTime - b.wechatTime || a.index - b.index
333
- })
334
- serializeTasks.forEach(task => {
335
- rs = task.serializeMethod(rs, context) || rs
336
- if (task.messageId) {
337
- context.processedMessageIds.push(task.messageId)
338
- }
302
+ pollRequest.serializeMethods.forEach(method => {
303
+ rs = method(rs, context) || rs
339
304
  })
340
305
  // wechatAccountId 传 null 表示非分页来源,onAddSession 会把未读同步到账号;
341
306
  // 同时带上 unreadDelta,让账号只累加本次新增的条数,而不是服务端返回的整个 unreadMsgCount(那里面的存量部分账号初始值已经包含了)
@@ -353,9 +318,7 @@ export default class ClientChatSession {
353
318
  lastMsgTime: rs.data.lastMsgTime,
354
319
  lastMsgId: rs.data.lastMsgId,
355
320
  unreadMsgCount: rs.data.unreadMsgCount,
356
- processedMessageCount: context.processedMessageIds.length,
357
- skippedMessageCount: context.skippedMessageIds.length,
358
- unreadMessageCount: context.unreadMessageIds.length,
321
+ mergedCount: pollRequest.serializeMethods.length,
359
322
  accountUnreadDelta: context.accountUnreadDelta,
360
323
  hasSessionMap: !!this.sessionMap[sessionId],
361
324
  hasAllSessionGroup: !!this._getSessionBySessionGroup(sessionId, ALL_WECHAT_ACCOUNT_ID),
@@ -437,22 +437,6 @@ class ClientChat {
437
437
  }
438
438
  const localSession = this.session.findSession(({ session }) => session.conversationId === sessionId)
439
439
  if (!localSession) {
440
- if (!this.session.pollRequestMap[sessionId]) {
441
- this.socket.addLog({
442
- group: 'client-chat-message:onAddMessageSuccess',
443
- content: {
444
- title: '未获取到会话,开始从服务端获取',
445
- data: {
446
- sessionId,
447
- accountId,
448
- wechatFriendId: data.wechatFriendId,
449
- wechatAccountId: data.wechatAccountId,
450
- messageId: data.id,
451
- wechatTime: data.wechatTime
452
- }
453
- }
454
- })
455
- }
456
440
  return this.session.getSession(sessionId, (rs, context) => {
457
441
  if (rs && rs.data) {
458
442
  const isAfterServerMessage = data.wechatTime > context.baseLastMsgTime
@@ -467,19 +451,16 @@ class ClientChat {
467
451
  // 正在看这个会话并且允许自动标记已读
468
452
  const isCurrentSessionRead = this.sessionManage.currentSession && this.sessionManage.currentSession.conversationId === sessionId && this.shouldMarkCurrentSessionRead(sessionId, data)
469
453
  // 会话未读数量:isAfterServerMessage 为 true 表示这条消息比服务端返回的会话 lastMsgTime 新,
470
- // 服务端返回的 unreadMsgCount 还没算它,需要本地 +1;否则服务端已经算进去了,skip 掉避免重复
454
+ // 服务端返回的 unreadMsgCount 还没算它,需要本地 +1;否则服务端已经算进去了,不再重复 +1
471
455
  if (!data.isSend && isAfterServerMessage) {
472
456
  if (isCurrentSessionRead) {
473
457
  rs.data.unreadMsgCount = 0
474
458
  } else {
475
459
  rs.data.unreadMsgCount = (rs.data.unreadMsgCount || 0) + 1
476
- context.unreadMessageIds.push(data.id)
477
460
  }
478
- } else {
479
- context.skippedMessageIds.push(data.id)
480
461
  }
481
462
  // 账号未读数量:和会话未读数量的判断口径不一样。
482
- // 账号未读初始值是登录时从服务端取的,不包含这条新消息,所以不管这条消息有没有被服务端算进会话的 unreadMsgCount(即不管是否被 skip),
463
+ // 账号未读初始值是登录时从服务端取的,不包含这条新消息,所以不管这条消息有没有被服务端算进会话的 unreadMsgCount,
483
464
  // 账号都要 +1。唯一不加的情况是"正在看当前会话并被直接标记已读"(此时会话未读被置 0,不会再通过 onSessionReadChange 扣减账号)。
484
465
  // 这个累计值会通过 addSession(rs.data, null, { unreadDelta }) 传给 onAddSession,账号只累加这个增量而不是整个 unreadMsgCount
485
466
  if (!data.isSend && !(isAfterServerMessage && isCurrentSessionRead)) {
@@ -487,9 +468,6 @@ class ClientChat {
487
468
  }
488
469
  }
489
470
  return rs
490
- }, {
491
- messageId: data.id,
492
- wechatTime: data.wechatTime
493
471
  }).catch(() => {})
494
472
  } else {
495
473
  this.session.updateSession(sessionId, ({ session }) => {
@@ -584,22 +562,6 @@ class ClientChat {
584
562
  // 更新会话未读消息数量
585
563
  const localSession = this.session.findSession(({ session }) => session.conversationId === sessionId)
586
564
  if (!localSession) {
587
- if (!this.session.pollRequestMap[sessionId]) {
588
- this.socket.addLog({
589
- group: 'client-chat-message:onAddMessageSuccess',
590
- content: {
591
- title: '未获取到会话,开始从服务端获取',
592
- data: {
593
- sessionId,
594
- accountId,
595
- wechatChatroomId: data.wechatChatroomId,
596
- wechatAccountId: data.wechatAccountId,
597
- messageId: data.id,
598
- wechatTime: data.wechatTime
599
- }
600
- }
601
- })
602
- }
603
565
  return this.session.getSession(sessionId, (rs, context) => {
604
566
  if (rs && rs.data) {
605
567
  const isAfterServerMessage = data.wechatTime > context.baseLastMsgTime
@@ -614,22 +576,19 @@ class ClientChat {
614
576
  // 正在看这个会话并且允许自动标记已读
615
577
  const isCurrentSessionRead = this.sessionManage.currentSession && this.sessionManage.currentSession.conversationId === sessionId && this.shouldMarkCurrentSessionRead(sessionId, data)
616
578
  // 会话未读数量:isAfterServerMessage 为 true 表示这条消息比服务端返回的会话 lastMsgTime 新,
617
- // 服务端返回的 unreadMsgCount 还没算它,需要本地 +1;否则服务端已经算进去了,skip 掉避免重复
579
+ // 服务端返回的 unreadMsgCount 还没算它,需要本地 +1;否则服务端已经算进去了,不再重复 +1
618
580
  if (!data.isSend && isAfterServerMessage) {
619
581
  if (isCurrentSessionRead) {
620
582
  rs.data.unreadMsgCount = 0
621
583
  } else {
622
584
  rs.data.unreadMsgCount = (rs.data.unreadMsgCount || 0) + 1
623
- context.unreadMessageIds.push(data.id)
624
585
  if (atMessage) {
625
586
  rs.data.lastAtMsgContent = appendLastAtMsgContent(rs.data.lastAtMsgContent, atMessage)
626
587
  }
627
588
  }
628
- } else {
629
- context.skippedMessageIds.push(data.id)
630
589
  }
631
590
  // 账号未读数量:和会话未读数量的判断口径不一样。
632
- // 账号未读初始值是登录时从服务端取的,不包含这条新消息,所以不管这条消息有没有被服务端算进会话的 unreadMsgCount(即不管是否被 skip),
591
+ // 账号未读初始值是登录时从服务端取的,不包含这条新消息,所以不管这条消息有没有被服务端算进会话的 unreadMsgCount,
633
592
  // 账号都要 +1。唯一不加的情况是"正在看当前会话并被直接标记已读"(此时会话未读被置 0,不会再通过 onSessionReadChange 扣减账号)。
634
593
  // 这个累计值会通过 addSession(rs.data, null, { unreadDelta }) 传给 onAddSession,账号只累加这个增量而不是整个 unreadMsgCount
635
594
  if (!data.isSend && !(isAfterServerMessage && isCurrentSessionRead)) {
@@ -637,9 +596,6 @@ class ClientChat {
637
596
  }
638
597
  }
639
598
  return rs
640
- }, {
641
- messageId: data.id,
642
- wechatTime: data.wechatTime
643
599
  }).catch(() => {})
644
600
  } else {
645
601
  this.session.updateSession(sessionId, ({ session }) => {
@@ -84,13 +84,15 @@ SDK 里维护着两套彼此独立的本地"账本":
84
84
  ```js
85
85
  // 会话未读:只在服务端没算过这条消息时 +1(原逻辑不变)
86
86
  if (!data.isSend && isAfterServerMessage) { ... }
87
- // 账号未读:不管是否被 skip 都 +1,只有"正在看当前会话被直接标记已读"不加
87
+ // 账号未读:不管服务端是否已经算进会话 unreadMsgCount 都 +1,只有"正在看当前会话被直接标记已读"不加
88
88
  if (!data.isSend && !(isAfterServerMessage && isCurrentSessionRead)) {
89
89
  context.accountUnreadDelta += 1
90
90
  }
91
91
  ```
92
92
 
93
- 注意 `accountUnreadDelta` **不等于** `unreadMessageIds.length`:被 skip 的消息表示服务端返回的会话已经把它算进 `unreadMsgCount`,但账号初始值是登录时取的,仍然不含这条,所以账号还是要 +1。
93
+ 注意 `accountUnreadDelta` **不等于** 本次给会话 `unreadMsgCount` +1 的条数:`isAfterServerMessage` 为 false 的消息表示服务端返回的会话已经把它算进 `unreadMsgCount`,但账号初始值是登录时取的,仍然不含这条,所以账号还是要 +1。
94
+
95
+ `getSession(sessionId, serializeMethod)` 只按 `sessionId` 聚合:同一个会话轮询期间的所有回调按调用顺序依次执行,不再依赖消息 id / 时间做去重或排序(消息层 `addMessage` 已按 id 去重)。
94
96
 
95
97
  - `onAddSession`(第 132 行附近):
96
98
 
@@ -5,20 +5,14 @@ export default class ClientChatAccount {
5
5
  data = Vue.observable({
6
6
  accountData: [],
7
7
  accountUnreadMessageNumData: [],
8
- accountGreetingUnreadMsgCountData: {},
9
8
  currentAccount: null
10
9
  })
11
10
 
12
11
  loadAccountDataMethod = null
13
12
 
14
13
  getAccountUnreadMessageNumMethod = null
15
-
16
- getAccountGreetingUnreadMsgCountMethod = null
17
14
 
18
15
  accountMap = {}
19
-
20
- // 好友请求数量请求合并,key为账号id列表
21
- greetingUnreadRequestMap = {}
22
16
 
23
17
  constructor (options) {
24
18
  options = Object.assign({
@@ -27,13 +21,11 @@ export default class ClientChatAccount {
27
21
  getAccountUnreadMessageNumMethod: null,
28
22
  updateAccountMessageReadMethod: null,
29
23
  deleteAccountSessionMethod: null,
30
- getAccountGreetingUnreadMsgCountMethod: null,
31
24
  onCurrentAccountChange: null,
32
25
  onAccountAdded: null,
33
26
  onAccountRemoved: null,
34
27
  onUnreadMessageNumChange: null,
35
- onDeleteAccountSession: null,
36
- onAccountLoaded: null
28
+ onDeleteAccountSession: null
37
29
  }, options)
38
30
  if (!options.loadAccountDataMethod) {
39
31
  throw new Error('缺少loadAccountDataMethod配置')
@@ -46,12 +38,10 @@ export default class ClientChatAccount {
46
38
  this.getAccountUnreadMessageNumMethod = options.getAccountUnreadMessageNumMethod
47
39
  this.updateAccountMessageReadMethod = options.updateAccountMessageReadMethod
48
40
  this.deleteAccountSessionMethod = options.deleteAccountSessionMethod
49
- this.getAccountGreetingUnreadMsgCountMethod = options.getAccountGreetingUnreadMsgCountMethod
50
41
  this.onAccountAdded = options.onAccountAdded
51
42
  this.onAccountRemoved = options.onAccountRemoved,
52
43
  this.onUnreadMessageNumChange = options.onUnreadMessageNumChange
53
44
  this.onDeleteAccountSession = options.onDeleteAccountSession
54
- this.onAccountLoaded = options.onAccountLoaded
55
45
  }
56
46
 
57
47
  get accountData () {
@@ -65,10 +55,6 @@ export default class ClientChatAccount {
65
55
  get currentAccount () {
66
56
  return this.data.currentAccount
67
57
  }
68
-
69
- get accountGreetingUnreadMsgCountData () {
70
- return this.data.accountGreetingUnreadMsgCountData
71
- }
72
58
 
73
59
  setCurrentAccount (accountId) {
74
60
  let account = null
@@ -296,9 +282,6 @@ export default class ClientChatAccount {
296
282
  this._cacheLoadPromise = this.loadAccountDataMethod()
297
283
  this._cacheLoadPromise.then(rs => {
298
284
  this.setAccountData(rs.data)
299
- this.onAccountLoaded && this.onAccountLoaded({
300
- data: rs.data
301
- })
302
285
  })
303
286
  this.cancelConnectRequest = () => {
304
287
  this._cacheLoadPromise.abort()
@@ -315,75 +298,9 @@ export default class ClientChatAccount {
315
298
  return this.loadData()
316
299
  }
317
300
 
318
- /**
319
- * 设置指定企微账号的待处理好友请求数量,并重算all
320
- */
321
- setAccountGreetingUnreadMsgCount (params) {
322
- if (!params || !params.qwAccountId) {
323
- throw new Error('缺少必须参数')
324
- }
325
- Vue.set(this.data.accountGreetingUnreadMsgCountData, params.qwAccountId, params.count || 0)
326
- this.updateAllAccountGreetingUnreadMsgCount()
327
- }
328
-
329
- updateAllAccountGreetingUnreadMsgCount () {
330
- const allCount = Object.keys(this.data.accountGreetingUnreadMsgCountData).reduce((rs, key) => {
331
- return key === 'all' ? rs : rs + (this.data.accountGreetingUnreadMsgCountData[key] || 0)
332
- }, 0)
333
- Vue.set(this.data.accountGreetingUnreadMsgCountData, 'all', allCount)
334
- }
335
-
336
- /**
337
- * 获取待处理好友请求数量
338
- * qwAccountIds不传则刷新所有账号;后端数量为0的账号不返回,所以先置0再覆盖
339
- */
340
- getAccountGreetingUnreadMsgCount (params) {
341
- if (!this.getAccountGreetingUnreadMsgCountMethod) {
342
- return Promise.reject(new Error('getAccountGreetingUnreadMsgCountMethod未定义'))
343
- }
344
- let qwAccountIds = (params || {}).qwAccountIds
345
- if (qwAccountIds && !Array.isArray(qwAccountIds)) {
346
- qwAccountIds = [qwAccountIds]
347
- }
348
- qwAccountIds = (qwAccountIds || []).filter((id, index, data) => id && data.indexOf(id) === index).map(String)
349
- const isAll = !qwAccountIds.length
350
- const requestKey = isAll ? 'all' : qwAccountIds.slice().sort().join(',')
351
- if (this.greetingUnreadRequestMap[requestKey]) {
352
- return this.greetingUnreadRequestMap[requestKey]
353
- }
354
- const request = this.getAccountGreetingUnreadMsgCountMethod({
355
- qwAccountIds: isAll ? undefined : qwAccountIds
356
- }).then(rs => {
357
- const targetIds = isAll ? Object.keys(this.accountMap) : qwAccountIds
358
- targetIds.forEach(id => {
359
- Vue.set(this.data.accountGreetingUnreadMsgCountData, id, 0)
360
- })
361
- ;((rs && rs.data) || []).forEach(item => {
362
- if (item && item.qwAccountId) {
363
- Vue.set(this.data.accountGreetingUnreadMsgCountData, String(item.qwAccountId), item.count || 0)
364
- }
365
- })
366
- this.updateAllAccountGreetingUnreadMsgCount()
367
- return this.data.accountGreetingUnreadMsgCountData
368
- }).finally(() => {
369
- delete this.greetingUnreadRequestMap[requestKey]
370
- })
371
- this.greetingUnreadRequestMap[requestKey] = request
372
- return request
373
- }
374
-
375
- /**
376
- * 刷新所有账号的待处理好友请求数量
377
- */
378
- refreshAllAccountGreetingUnreadMsgCount () {
379
- return this.getAccountGreetingUnreadMsgCount()
380
- }
381
-
382
301
  reset () {
383
302
  this.data.accountData = []
384
303
  this.data.accountUnreadMessageNumData = []
385
- this.data.accountGreetingUnreadMsgCountData = {}
386
- this.greetingUnreadRequestMap = {}
387
304
  if (this.cancelConnectRequest) {
388
305
  this.cancelConnectRequest()
389
306
  }
@@ -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
+ }