@aochuang/client-sdk 1.0.378 → 1.0.379-wework

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/common/.DS_Store +0 -0
  2. package/components/.DS_Store +0 -0
  3. package/components/chat-editor/chat-editor-suggestions/chat-editor-suggestions.vue +4 -40
  4. package/components/chat-editor/chat-editor.vue +5 -75
  5. package/components/index.js +6 -1
  6. package/components/session-select/session-select-item.vue +8 -9
  7. package/components/wechat-chat-control/.DS_Store +0 -0
  8. package/components/wechat-chat-control/location/location.vue +3 -3
  9. package/components/wechat-chat-control/transfer/.DS_Store +0 -0
  10. package/components/wechat-chat-control/url/.DS_Store +0 -0
  11. package/components/wechat-chat-control/voice/.DS_Store +0 -0
  12. package/components/wework-chat-control/channel-card/channel-card.vue +144 -0
  13. package/components/wework-chat-control/channel-live/channel-live.vue +7 -2
  14. package/components/wework-chat-control/company-card/company-card.vue +1 -1
  15. package/components/wework-chat-control/custom-expression/custom-expression.vue +2 -1
  16. package/components/wework-chat-control/file-url/file-url.vue +34 -16
  17. package/components/wework-chat-control/image/image.vue +137 -2
  18. package/components/wework-chat-control/index.js +15 -7
  19. package/components/wework-chat-control/link/.DS_Store +0 -0
  20. package/components/wework-chat-control/location/location.vue +3 -3
  21. package/components/wework-chat-control/merge-message/merge-message-panel.vue +63 -0
  22. package/components/wework-chat-control/merge-message/merge-message.vue +84 -0
  23. package/components/wework-chat-control/merge-message/util.js +59 -0
  24. package/components/wework-chat-control/metting/enterprise-wechat.png +0 -0
  25. package/components/wework-chat-control/metting/meeting-video.svg +4 -0
  26. package/components/wework-chat-control/metting/metting.vue +181 -0
  27. package/components/wework-chat-control/red-envelopes/red-envelopes.vue +3 -2
  28. package/components/wework-chat-control/text/text-default.vue +99 -0
  29. package/components/wework-chat-control/text/text-quote.vue +138 -0
  30. package/components/wework-chat-control/text/text.vue +27 -143
  31. package/components/wework-chat-control/url/url-channel-live.vue +53 -0
  32. package/components/wework-chat-control/url/url-miniprogram.vue +6 -7
  33. package/components/wework-chat-control/url/url.vue +26 -2
  34. package/components/wework-chat-control/util.js +26 -17
  35. package/components/wework-chat-control/video/.DS_Store +0 -0
  36. package/components/wework-chat-control/video/video.vue +10 -2
  37. package/components/wework-chat-control/voice/voice.vue +9 -2
  38. package/components/wework-chat-control/wework-chat-control-config-item.vue +24 -0
  39. package/components/wework-chat-control/wework-chat-control-config-msg.vue +25 -0
  40. package/{uni-components/chat-control/chat-control-config.vue → components/wework-chat-control/wework-chat-control-config.vue} +16 -13
  41. package/components/wework-chat-panel/chat-panel-chat-status/chat-panel-chat-status.vue +73 -0
  42. package/components/wework-chat-panel/chat-panel-item.vue +56 -25
  43. package/components/wework-chat-panel/chat-panel.vue +96 -13
  44. package/package.json +10 -3
  45. package/services/.DS_Store +0 -0
  46. package/services/client-chat/client-chat-wework/client-chat-account.js +84 -1
  47. package/services/client-chat/client-chat-wework/client-chat-concats.js +81 -17
  48. package/services/client-chat/client-chat-wework/client-chat-message.js +121 -11
  49. package/services/client-chat/client-chat-wework/client-chat-session.js +271 -191
  50. package/services/client-chat/client-chat-wework/client-chat-socket.js +13 -1
  51. package/services/client-chat/client-chat-wework/client-chat.js +404 -84
  52. package/services/client-chat/client-chat-wework/utils.js +5 -5
  53. package/services/socket/socket.js +14 -4
  54. package/components/wework-chat-panel/chat-panel-controls/company-card/company-card.vue +0 -35
  55. package/components/wework-chat-panel/chat-panel-controls/expression/expression.vue +0 -36
  56. package/components/wework-chat-panel/chat-panel-controls/file-url/file-url.vue +0 -35
  57. package/components/wework-chat-panel/chat-panel-controls/image/image.vue +0 -36
  58. package/components/wework-chat-panel/chat-panel-controls/index.js +0 -35
  59. package/components/wework-chat-panel/chat-panel-controls/jx-sys-text/jx-sys-text.vue +0 -28
  60. package/components/wework-chat-panel/chat-panel-controls/link/link.vue +0 -35
  61. package/components/wework-chat-panel/chat-panel-controls/location/location.vue +0 -35
  62. package/components/wework-chat-panel/chat-panel-controls/text/text.vue +0 -43
  63. package/components/wework-chat-panel/chat-panel-controls/unkonw/unkonw.vue +0 -39
  64. package/components/wework-chat-panel/chat-panel-controls/video/video.vue +0 -37
  65. package/components/wework-chat-panel/chat-panel-controls/voice/voice.vue +0 -35
  66. package/uni-common/account-portray/account-portray.vue +0 -51
  67. package/uni-common/account-select/account-select-item.vue +0 -172
  68. package/uni-common/account-select/account-select.vue +0 -252
  69. package/uni-common/all-friend-avatar/all-friend-avatar.vue +0 -49
  70. package/uni-common/friend-avatar/default.svg +0 -1
  71. package/uni-common/friend-avatar/friend-avatar.vue +0 -27
  72. package/uni-common/friend-avatar/index.js +0 -3
  73. package/uni-common/friend-loader/friend-loader.vue +0 -53
  74. package/uni-common/friend-portray/friend-portray.vue +0 -56
  75. package/uni-common/group-avatar/default.svg +0 -1
  76. package/uni-common/group-avatar/group-avatar.vue +0 -18
  77. package/uni-common/group-avatar/index.js +0 -3
  78. package/uni-common/room-avatar/default.svg +0 -6
  79. package/uni-common/room-avatar/index.js +0 -3
  80. package/uni-common/room-avatar/room-avatar.vue +0 -27
  81. package/uni-common/room-loader/room-loader.vue +0 -53
  82. package/uni-common/room-portray/room-portray.vue +0 -56
  83. package/uni-components/chat-control/calling/calling.vue +0 -91
  84. package/uni-components/chat-control/calling/phone-fill.svg +0 -1
  85. package/uni-components/chat-control/calling/vidicon-fill.svg +0 -1
  86. package/uni-components/chat-control/channel-video/channel-video.vue +0 -89
  87. package/uni-components/chat-control/channel-video-card/channel-video-card.vue +0 -105
  88. package/uni-components/chat-control/channel-video-live/channel-video-live.vue +0 -92
  89. package/uni-components/chat-control/chat-control-config-item/chat-control-config-item.vue +0 -20
  90. package/uni-components/chat-control/chat-control-config-item/index.js +0 -3
  91. package/uni-components/chat-control/chat-control-config-msg/chat-control-config-msg-app.vue +0 -25
  92. package/uni-components/chat-control/chat-control-config-msg/chat-control-config-msg-h5.vue +0 -21
  93. package/uni-components/chat-control/chat-control.vue +0 -218
  94. package/uni-components/chat-control/company-card/company-card.vue +0 -123
  95. package/uni-components/chat-control/const.js +0 -28
  96. package/uni-components/chat-control/expression/expression.vue +0 -41
  97. package/uni-components/chat-control/image/image.vue +0 -68
  98. package/uni-components/chat-control/index.js +0 -89
  99. package/uni-components/chat-control/location/location.vue +0 -110
  100. package/uni-components/chat-control/member-change/member-change.vue +0 -32
  101. package/uni-components/chat-control/quote-message/quote-message.vue +0 -216
  102. package/uni-components/chat-control/real-time-position/real-time-position.vue +0 -62
  103. package/uni-components/chat-control/redpacket/red-envelope.svg +0 -1
  104. package/uni-components/chat-control/redpacket/redpacket.vue +0 -75
  105. package/uni-components/chat-control/share-card/share-card.vue +0 -101
  106. package/uni-components/chat-control/system/system.vue +0 -69
  107. package/uni-components/chat-control/system-batch-message/system-batch-message.vue +0 -30
  108. package/uni-components/chat-control/system-text/system-text.vue +0 -32
  109. package/uni-components/chat-control/text/text.vue +0 -67
  110. package/uni-components/chat-control/text-with-at/text-with-at.vue +0 -51
  111. package/uni-components/chat-control/transfer/red-transfer.svg +0 -1
  112. package/uni-components/chat-control/transfer/transfer.vue +0 -80
  113. package/uni-components/chat-control/unkonw/unkonw.vue +0 -37
  114. package/uni-components/chat-control/url/icons/file-excel-line.svg +0 -1
  115. package/uni-components/chat-control/url/icons/file-info-line.svg +0 -1
  116. package/uni-components/chat-control/url/icons/file-music-line.svg +0 -1
  117. package/uni-components/chat-control/url/icons/file-pdf-line.svg +0 -1
  118. package/uni-components/chat-control/url/icons/file-ppt-line.svg +0 -1
  119. package/uni-components/chat-control/url/icons/file-settings-line.svg +0 -1
  120. package/uni-components/chat-control/url/icons/file-text-line.svg +0 -1
  121. package/uni-components/chat-control/url/icons/file-unknow-line.svg +0 -1
  122. package/uni-components/chat-control/url/icons/file-word-line.svg +0 -1
  123. package/uni-components/chat-control/url/icons/file-zip-line.svg +0 -1
  124. package/uni-components/chat-control/url/icons/index.js +0 -24
  125. package/uni-components/chat-control/url/miniprogram.svg +0 -1
  126. package/uni-components/chat-control/url/url-miniprogram.vue +0 -116
  127. package/uni-components/chat-control/url/url.vue +0 -306
  128. package/uni-components/chat-control/url-new/icons/file-excel-line.svg +0 -1
  129. package/uni-components/chat-control/url-new/icons/file-info-line.svg +0 -1
  130. package/uni-components/chat-control/url-new/icons/file-music-line.svg +0 -1
  131. package/uni-components/chat-control/url-new/icons/file-pdf-line.svg +0 -1
  132. package/uni-components/chat-control/url-new/icons/file-ppt-line.svg +0 -1
  133. package/uni-components/chat-control/url-new/icons/file-settings-line.svg +0 -1
  134. package/uni-components/chat-control/url-new/icons/file-text-line.svg +0 -1
  135. package/uni-components/chat-control/url-new/icons/file-unknow-line.svg +0 -1
  136. package/uni-components/chat-control/url-new/icons/file-word-line.svg +0 -1
  137. package/uni-components/chat-control/url-new/icons/file-zip-line.svg +0 -1
  138. package/uni-components/chat-control/url-new/icons/index.js +0 -24
  139. package/uni-components/chat-control/url-new/url-new.vue +0 -110
  140. package/uni-components/chat-control/utils.js +0 -12
  141. package/uni-components/chat-control/video/video.vue +0 -156
  142. package/uni-components/chat-control/voice/voice.vue +0 -166
  143. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet-collect.vue +0 -84
  144. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet-system.vue +0 -28
  145. package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet.vue +0 -85
  146. package/uni-components/chat-editor/chat-editor-func/chat-editor-func.vue +0 -157
  147. package/uni-components/chat-editor/chat-editor-func-at/chat-editor-func-at-panel.vue +0 -158
  148. package/uni-components/chat-editor/chat-editor-func-at/chat-editor-func-at.vue +0 -61
  149. package/uni-components/chat-editor/chat-editor-func-button/chat-editor-func-button.vue +0 -58
  150. package/uni-components/chat-editor/chat-editor-func-file/chat-editor-func-file.vue +0 -54
  151. package/uni-components/chat-editor/chat-editor-func-image/chat-editor-func-image.vue +0 -42
  152. package/uni-components/chat-editor/chat-editor-func-video/chat-editor-func-video.vue +0 -42
  153. package/uni-components/chat-editor/chat-editor-func-voice/chat-editor-func-voice.vue +0 -25
  154. package/uni-components/chat-editor/chat-editor-message-send/chat-editor-message-send.vue +0 -158
  155. package/uni-components/chat-editor/chat-editor-quote/chat-editor-quote.vue +0 -75
  156. package/uni-components/chat-editor/chat-editor.vue +0 -257
  157. package/uni-components/chat-editor/index.js +0 -10
  158. package/uni-components/chat-editor/util.js +0 -65
  159. package/uni-components/chat-panel/chat-panel-chats-box.vue +0 -238
  160. package/uni-components/chat-panel/chat-panel-chats-forward/chat-panel-chats-forward.vue +0 -273
  161. package/uni-components/chat-panel/chat-panel-chats-item.vue +0 -578
  162. package/uni-components/chat-panel/chat-panel-chats-status/chat-panel-chats-status.vue +0 -71
  163. package/uni-components/chat-panel/chat-panel-chats.vue +0 -368
  164. package/uni-components/chat-panel/chat-panel.vue +0 -227
  165. package/uni-components/contacts-group-select/contacts-group-select-item.vue +0 -85
  166. package/uni-components/contacts-group-select/contacts-group-select-panel.vue +0 -119
  167. package/uni-components/contacts-group-select/contacts-group-select.vue +0 -150
@@ -1,5 +1,5 @@
1
1
  import Vue from 'vue'
2
- import { isEmptyObject } from '../../../utils/util.js'
2
+ import { createPollRequest, isEmptyObject } from '../../../utils/util.js'
3
3
 
4
4
  const loopLoadAssignSessionData = (fetchFn, params) => {
5
5
  let lastPs = null
@@ -82,10 +82,13 @@ export default class ClientChatSession {
82
82
  /**
83
83
  * 删除会话
84
84
  */
85
- deleteSessionMethod: null
85
+ deleteSessionMethod: null,
86
+ modifiedAccountMap: {}
86
87
  })
87
88
 
88
89
  accountIds = []
90
+
91
+ pollRequestMap = {}
89
92
 
90
93
  sessionMap = {}
91
94
 
@@ -119,6 +122,23 @@ export default class ClientChatSession {
119
122
  return this.data.loading
120
123
  }
121
124
 
125
+ isModify (qwAccountId) {
126
+ return !!(qwAccountId && this.data.modifiedAccountMap[qwAccountId])
127
+ }
128
+
129
+ markModify (qwAccountIds) {
130
+ const ids = Array.isArray(qwAccountIds) ? qwAccountIds : [qwAccountIds]
131
+ ids.filter(Boolean).forEach(id => {
132
+ Vue.set(this.data.modifiedAccountMap, id, true)
133
+ })
134
+ }
135
+
136
+ unmarkModify (qwAccountId) {
137
+ if (qwAccountId) {
138
+ Vue.delete(this.data.modifiedAccountMap, qwAccountId)
139
+ }
140
+ }
141
+
122
142
  get loadAssignTaskSessioning () {
123
143
  return this.data.loadAssignTaskSessioning
124
144
  }
@@ -128,6 +148,7 @@ export default class ClientChatSession {
128
148
  groupField: null,
129
149
  sortField: null,
130
150
  onBeforeAddSession: null,
151
+ onAddSession: null,
131
152
  loadSessionDataMethod: null,
132
153
  loadAssignTaskSessionDataMethod: null,
133
154
  stickyTopSessionMethod: null,
@@ -152,6 +173,7 @@ export default class ClientChatSession {
152
173
  throw new Error('缺少getSessionMethod配置')
153
174
  }
154
175
  this.onBeforeAddSession = options.onBeforeAddSession
176
+ this.onAddSession = options.onAddSession
155
177
  this.loadSessionData = options.loadSessionDataMethod
156
178
  this.updateSessionRead = options.updateSessionReadMethod
157
179
  this.getSessionMethod = options.getSessionMethod
@@ -169,6 +191,8 @@ export default class ClientChatSession {
169
191
  this.sessionMap = {}
170
192
  this.data.sessionData = {}
171
193
  this.data.sessionGroupData = {}
194
+ this._lastUpdateSessionMap = {}
195
+ this._reverseLastUpdateSessionMap = {}
172
196
  // this.data.sessionUnreadCountMap = {}
173
197
  this.data.sessionMuteMap = {}
174
198
  }
@@ -184,27 +208,96 @@ export default class ClientChatSession {
184
208
  this.checkAndUpdateLastUpdateSession()
185
209
  }
186
210
 
187
- getSession (sessionId) {
211
+ getSession (sessionId, serializeMethod) {
188
212
  if (this.sessionMap[sessionId]) {
189
213
  return Promise.resolve({
190
214
  data: this.sessionMap[sessionId]
191
215
  })
192
216
  }
193
- return this.getSessionMethod({
194
- id: sessionId
195
- }).then(rs => {
196
- if (rs.data) {
197
- this.addSession(rs.data)
198
- return rs
199
- } else {
217
+ let pollRequest = this.pollRequestMap[sessionId]
218
+ if (pollRequest && pollRequest.promise) {
219
+ if (serializeMethod) {
220
+ pollRequest.serializeMethods.push(serializeMethod)
221
+ }
222
+ return pollRequest.promise
223
+ }
224
+ pollRequest = createPollRequest(({ done }) => {
225
+ return this.getSessionMethod({
226
+ id: sessionId
227
+ }).then(rs => {
228
+ if (rs && rs.data) {
229
+ done(Object.assign({}, rs, {
230
+ data: Object.assign({}, rs.data, {
231
+ id: sessionId
232
+ })
233
+ }))
234
+ }
235
+ })
236
+ })
237
+ pollRequest.serializeMethods = serializeMethod ? [serializeMethod] : []
238
+ this.pollRequestMap[sessionId] = pollRequest
239
+ pollRequest.promise = pollRequest.start().then(rs => {
240
+ if (!rs || !rs.data) {
200
241
  return Promise.reject('未找到会话' + sessionId)
201
242
  }
243
+ const context = {
244
+ baseLastMsgTime: rs.data.lastMsgTime || 0,
245
+ accountUnreadDelta: 0
246
+ }
247
+ pollRequest.serializeMethods.forEach(method => {
248
+ rs = method(rs, context) || rs
249
+ })
250
+ this.addSession(rs.data, {
251
+ unreadDelta: context.accountUnreadDelta
252
+ })
253
+ return rs
254
+ }).finally(() => {
255
+ if (this.pollRequestMap[sessionId] === pollRequest) {
256
+ delete this.pollRequestMap[sessionId]
257
+ }
258
+ })
259
+ return pollRequest.promise
260
+ }
261
+
262
+ stopGetSessionPollRequests () {
263
+ Object.keys(this.pollRequestMap).forEach(sessionId => {
264
+ this.pollRequestMap[sessionId].stop()
202
265
  })
266
+ this.pollRequestMap = {}
203
267
  }
204
268
 
205
269
  getSessionByLocal (sessionId) {
206
270
  return this.sessionMap[sessionId]
207
271
  }
272
+
273
+ /**
274
+ * 强制从服务端刷新会话,绕过本地缓存。
275
+ */
276
+ refreshSession (sessionId) {
277
+ if (!sessionId) {
278
+ return Promise.reject('缺少会话id')
279
+ }
280
+ return this.getSessionMethod({
281
+ id: sessionId
282
+ }).then(rs => {
283
+ if (!rs || !rs.data) {
284
+ return Promise.reject('未找到会话' + sessionId)
285
+ }
286
+ // 事件计算出的 sessionId 是本地索引,始终保持与服务端返回对象一致。
287
+ const serverSession = Object.assign({}, rs.data, {
288
+ id: sessionId
289
+ })
290
+ const localSession = this.getSessionByLocal(sessionId)
291
+ if (localSession) {
292
+ this.updateSession(sessionId, serverSession)
293
+ } else {
294
+ this.addSession(serverSession)
295
+ }
296
+ return Object.assign({}, rs, {
297
+ data: serverSession
298
+ })
299
+ })
300
+ }
208
301
 
209
302
  findSession (findFn) {
210
303
  let result
@@ -228,7 +321,98 @@ export default class ClientChatSession {
228
321
  milliseconds: Math.abs(milliseconds - 86400000) // 排序,由大到小
229
322
  }
230
323
  }
231
-
324
+
325
+ _removeSessionFromBuckets (buckets, sessionId) {
326
+ if (!buckets) {
327
+ return
328
+ }
329
+ Object.keys(buckets).forEach(topField => {
330
+ const dayBuckets = buckets[topField]
331
+ Object.keys(dayBuckets || {}).forEach(day => {
332
+ const timeBuckets = dayBuckets[day]
333
+ Object.keys(timeBuckets || {}).forEach(milliseconds => {
334
+ const items = timeBuckets[milliseconds]
335
+ if (!Array.isArray(items)) {
336
+ return
337
+ }
338
+ for (let index = items.length - 1; index >= 0; index -= 1) {
339
+ if (items[index] && items[index].id === sessionId) {
340
+ items.splice(index, 1)
341
+ }
342
+ }
343
+ if (!items.length) {
344
+ Vue.delete(timeBuckets, milliseconds)
345
+ }
346
+ })
347
+ if (isEmptyObject(timeBuckets)) {
348
+ Vue.delete(dayBuckets, day)
349
+ }
350
+ })
351
+ if (isEmptyObject(dayBuckets)) {
352
+ Vue.delete(buckets, topField)
353
+ }
354
+ })
355
+ }
356
+
357
+ _removeSessionFromDisplayData (sessionId) {
358
+ this._removeSessionFromBuckets(this.data.sessionData, sessionId)
359
+ Object.keys(this.data.sessionGroupData).forEach(groupField => {
360
+ this._removeSessionFromBuckets(this.data.sessionGroupData[groupField], sessionId)
361
+ if (isEmptyObject(this.data.sessionGroupData[groupField])) {
362
+ Vue.delete(this.data.sessionGroupData, groupField)
363
+ }
364
+ })
365
+ }
366
+
367
+ _removeSessionFromTimeMap (timeMap, sessionId) {
368
+ Object.keys(timeMap || {}).forEach(day => {
369
+ Object.keys(timeMap[day] || {}).forEach(milliseconds => {
370
+ const items = timeMap[day][milliseconds]
371
+ if (!Array.isArray(items)) {
372
+ return
373
+ }
374
+ for (let index = items.length - 1; index >= 0; index -= 1) {
375
+ if (items[index] && items[index].id === sessionId) {
376
+ items.splice(index, 1)
377
+ }
378
+ }
379
+ if (!items.length) {
380
+ delete timeMap[day][milliseconds]
381
+ }
382
+ })
383
+ if (isEmptyObject(timeMap[day])) {
384
+ delete timeMap[day]
385
+ }
386
+ })
387
+ }
388
+
389
+ _insertSessionIntoBuckets (buckets, session, topField, sortFields) {
390
+ if (!buckets[topField]) {
391
+ Vue.set(buckets, topField, {})
392
+ }
393
+ if (!buckets[topField][sortFields.day]) {
394
+ Vue.set(buckets[topField], sortFields.day, {})
395
+ }
396
+ if (!buckets[topField][sortFields.day][sortFields.milliseconds]) {
397
+ Vue.set(buckets[topField][sortFields.day], sortFields.milliseconds, [])
398
+ }
399
+ const items = buckets[topField][sortFields.day][sortFields.milliseconds]
400
+ if (!items.some(item => item.id === session.id)) {
401
+ items.push(session)
402
+ }
403
+ }
404
+
405
+ _insertSessionIntoDisplayData (session) {
406
+ const topField = session.stickyOnTop ? 0 : 1
407
+ const sortFields = this.getSortField(session[this.sortField])
408
+ this._insertSessionIntoBuckets(this.data.sessionData, session, topField, sortFields)
409
+ const groupField = session[this.groupField] || 'unkonw'
410
+ if (!this.data.sessionGroupData[groupField]) {
411
+ Vue.set(this.data.sessionGroupData, groupField, {})
412
+ }
413
+ this._insertSessionIntoBuckets(this.data.sessionGroupData[groupField], session, topField, sortFields)
414
+ }
415
+
232
416
  /**
233
417
  * {
234
418
  * "id": "3d5398c24f1ae633047202fe17276571ef5e537e",
@@ -245,7 +429,7 @@ export default class ClientChatSession {
245
429
  * "wechatAccountId": "2a39a725814acf07502299ab2285fff8d44377f5"
246
430
  * }
247
431
  */
248
- addSession (data) {
432
+ addSession (data, options = {}) {
249
433
  if (!data || !data.id) {
250
434
  throw new Error('缺少必须参数id')
251
435
  }
@@ -254,22 +438,20 @@ export default class ClientChatSession {
254
438
  }) === false) {
255
439
  return
256
440
  }
257
- if (this.sessionMap[data.id]) {
258
- return
259
- }
260
- const topField = data.stickyOnTop ? 0 : 1 // 置顶
261
- if (!this.data.sessionData[topField]) {
262
- Vue.set(this.data.sessionData, topField, {})
263
- }
264
- // 所有的
265
- const sortFields = this.getSortField(data[this.sortField])
266
- if (!this.data.sessionData[topField][sortFields.day]) {
267
- Vue.set(this.data.sessionData[topField], sortFields.day, {})
268
- }
269
- if (!this.data.sessionData[topField][sortFields.day][sortFields.milliseconds]) {
270
- Vue.set(this.data.sessionData[topField][sortFields.day], sortFields.milliseconds, [])
441
+ const oldSession = this.sessionMap[data.id]
442
+ if (oldSession) {
443
+ if (oldSession.lastMsgTime && data.lastMsgTime && oldSession.lastMsgTime > data.lastMsgTime) {
444
+ return oldSession
445
+ }
446
+ this._removeSessionFromDisplayData(data.id)
447
+ this._removeSessionFromTimeMap(this._lastUpdateSessionMap, data.id)
448
+ this._removeSessionFromTimeMap(this._reverseLastUpdateSessionMap, data.id)
449
+ Object.keys(data).forEach(key => {
450
+ Vue.set(oldSession, key, data[key])
451
+ })
452
+ data = oldSession
271
453
  }
272
- this.data.sessionData[topField][sortFields.day][sortFields.milliseconds].push(data)
454
+ this._insertSessionIntoDisplayData(data)
273
455
  // 记录lastUpdateSession的顺序,因为后续分页加载会话数据的时候,加载的参数需要获取目前会话数据中最久远的一条会话记录,作为下载加载会话的参考数据
274
456
  const lastUpdateSortFields = this.getSortField(data.lastUpdateTime)
275
457
  if (!this._lastUpdateSessionMap) {
@@ -294,21 +476,7 @@ export default class ClientChatSession {
294
476
  this._reverseLastUpdateSessionMap[reverseLastUpdateSortFields.day][reverseLastUpdateSortFields.milliseconds] = []
295
477
  }
296
478
  this._reverseLastUpdateSessionMap[reverseLastUpdateSortFields.day][reverseLastUpdateSortFields.milliseconds].push(data)
297
- // 分组的
298
479
  const groupField = data[this.groupField] || 'unkonw'
299
- if (!this.data.sessionGroupData[groupField]) {
300
- Vue.set(this.data.sessionGroupData, groupField, {})
301
- }
302
- if (!this.data.sessionGroupData[groupField][topField]) {
303
- Vue.set(this.data.sessionGroupData[groupField], topField, {})
304
- }
305
- if (!this.data.sessionGroupData[groupField][topField][sortFields.day]) {
306
- Vue.set(this.data.sessionGroupData[groupField][topField], sortFields.day, {})
307
- }
308
- if (!this.data.sessionGroupData[groupField][topField][sortFields.day][sortFields.milliseconds]) {
309
- Vue.set(this.data.sessionGroupData[groupField][topField][sortFields.day], sortFields.milliseconds, [])
310
- }
311
- this.data.sessionGroupData[groupField][topField][sortFields.day][sortFields.milliseconds].push(data)
312
480
  this.sessionMap[data.id] = data
313
481
  // if (typeof this.data.sessionUnreadCountMap[groupField] !== 'number') {
314
482
  // Vue.set(this.data.sessionUnreadCountMap, groupField, 0)
@@ -335,6 +503,11 @@ export default class ClientChatSession {
335
503
  if (data.lastMsgTime && (!this.lastSession || data.lastMsgTime < this.lastSession.lastMsgTime)) {
336
504
  this.lastSession = data
337
505
  }
506
+ this.onAddSession && this.onAddSession({
507
+ session: data,
508
+ unreadDelta: options.unreadDelta
509
+ })
510
+ return data
338
511
  }
339
512
 
340
513
  removeSession (id, checkLastUpdateSession) {
@@ -345,6 +518,9 @@ export default class ClientChatSession {
345
518
  if (!session) {
346
519
  return
347
520
  }
521
+ this._removeSessionFromDisplayData(id)
522
+ this._removeSessionFromTimeMap(this._lastUpdateSessionMap, id)
523
+ this._removeSessionFromTimeMap(this._reverseLastUpdateSessionMap, id)
348
524
  const topField = session.stickyOnTop ? 0 : 1 // 置顶
349
525
  const sortFields = this.getSortField(session[this.sortField])
350
526
  if (this.data.sessionData[topField] && this.data.sessionData[topField][sortFields.day] && this.data.sessionData[topField][sortFields.day][sortFields.milliseconds]) {
@@ -418,6 +594,9 @@ export default class ClientChatSession {
418
594
  }
419
595
  }
420
596
  delete this.sessionMap[id]
597
+ if (this.data.currentSessionId === id) {
598
+ this.data.currentSessionId = null
599
+ }
421
600
  if (checkLastUpdateSession !== false) {
422
601
  // todo 后面可能会删掉这块的逻辑,因为后端排序逻辑变了
423
602
  this.checkAndUpdateLastUpdateSession()
@@ -439,7 +618,15 @@ export default class ClientChatSession {
439
618
  }
440
619
  // lastSession是最小的时间,就是更早的,因为加载更多是从现在的加载历史的
441
620
  const dayKeys = Object.keys(this._lastUpdateSessionMap)
621
+ if (!dayKeys.length) {
622
+ this.lastUpdateSession = null
623
+ this.lastUpdateTime = null
624
+ return
625
+ }
442
626
  const millisecondsKeys = Object.keys(this._lastUpdateSessionMap[dayKeys[dayKeys.length - 1]])
627
+ if (!millisecondsKeys.length) {
628
+ return
629
+ }
443
630
  const lastSessionSort = (this._lastUpdateSessionMap[dayKeys[dayKeys.length - 1]][millisecondsKeys[millisecondsKeys.length - 1]] || []).sort((a, b) => {
444
631
  return a.lastUpdateTime - b.lastUpdateTime
445
632
  })
@@ -459,7 +646,15 @@ export default class ClientChatSession {
459
646
  }
460
647
  // lastSession是最小的时间,就是更早的,因为加载更多是从现在的加载历史的
461
648
  const dayKeys = Object.keys(this._reverseLastUpdateSessionMap)
649
+ if (!dayKeys.length) {
650
+ this.reverseLastUpdateSession = null
651
+ this.reverseLastUpdateTime = null
652
+ return
653
+ }
462
654
  const millisecondsKeys = Object.keys(this._reverseLastUpdateSessionMap[dayKeys[dayKeys.length - 1]])
655
+ if (!millisecondsKeys.length) {
656
+ return
657
+ }
463
658
  const lastSessionSort = (this._reverseLastUpdateSessionMap[dayKeys[dayKeys.length - 1]][millisecondsKeys[millisecondsKeys.length - 1]] || []).sort((a, b) => {
464
659
  return b.lastUpdateTime - a.lastUpdateTime
465
660
  })
@@ -528,159 +723,40 @@ export default class ClientChatSession {
528
723
  } else {
529
724
  nextProps = callback
530
725
  }
531
- if (nextProps) {
532
- // 分组的
533
- const groupField = session[this.groupField] || 'unkonw'
534
- const { unreadMsgCount, stickyOnTop, mute, lastMsgTime, ...nextUpdateProps } = nextProps
535
- Object.keys(nextUpdateProps).forEach(k => {
536
- Vue.set(session, k, nextUpdateProps[k])
537
- })
538
- // 处理会话时间
539
- if (typeof lastMsgTime !== 'undefined') {
540
- const oldSortFields = this.getSortField(session.lastMsgTime)
541
- // 把老的清空
542
- // 重置一下数据
543
- const topFields = [0, 1]
544
- topFields.forEach(topField => {
545
- if (this.data.sessionData[topField] && this.data.sessionData[topField][oldSortFields.day] && this.data.sessionData[topField][oldSortFields.day][oldSortFields.milliseconds]) {
546
- let index = -1
547
- this.data.sessionData[topField][oldSortFields.day][oldSortFields.milliseconds].some((v, i) => {
548
- if (v === session) {
549
- index = i
550
- return true
551
- }
552
- })
553
- if (index >= 0) {
554
- this.data.sessionData[topField][oldSortFields.day][oldSortFields.milliseconds].splice(index, 1)
555
- }
556
- }
557
- if (this.data.sessionGroupData[groupField] && this.data.sessionGroupData[groupField][topField] && this.data.sessionGroupData[groupField][topField][oldSortFields.day] && this.data.sessionGroupData[groupField][topField][oldSortFields.day][oldSortFields.milliseconds]) {
558
- let index = -1
559
- this.data.sessionGroupData[groupField][topField][oldSortFields.day][oldSortFields.milliseconds].some((v, i) => {
560
- if (v === session) {
561
- index = i
562
- return true
563
- }
564
- })
565
- this.data.sessionGroupData[groupField][topField][oldSortFields.day][oldSortFields.milliseconds].splice(index, 1)
566
- }
567
- })
568
- // 按照新的时间来分组排序
569
- Vue.set(session, 'lastMsgTime', lastMsgTime)
570
- const topField = session.stickyOnTop ? 0 : 1 // 0置顶
571
- const sortFields = this.getSortField(session.lastMsgTime)
572
- // 所有的
573
- if (!this.data.sessionData[topField]) {
574
- Vue.set(this.data.sessionData, topField, {})
575
- }
576
- if (!this.data.sessionData[topField][sortFields.day]) {
577
- Vue.set(this.data.sessionData[topField], sortFields.day, {})
578
- }
579
- if (!this.data.sessionData[topField][sortFields.day][sortFields.milliseconds]) {
580
- Vue.set(this.data.sessionData[topField][sortFields.day], sortFields.milliseconds, [])
581
- }
582
- this.data.sessionData[topField][sortFields.day][sortFields.milliseconds].push(session)
583
- // 分组的
584
- if (!this.data.sessionGroupData[groupField]) {
585
- Vue.set(this.data.sessionGroupData, groupField, {})
586
- }
587
- if (!this.data.sessionGroupData[groupField][topField]) {
588
- Vue.set(this.data.sessionGroupData[groupField], topField, {})
589
- }
590
- if (!this.data.sessionGroupData[groupField][topField][sortFields.day]) {
591
- Vue.set(this.data.sessionGroupData[groupField][topField], sortFields.day, {})
592
- }
593
- if (!this.data.sessionGroupData[groupField][topField][sortFields.day][sortFields.milliseconds]) {
594
- Vue.set(this.data.sessionGroupData[groupField][topField][sortFields.day], sortFields.milliseconds, [])
595
- }
596
- this.data.sessionGroupData[groupField][topField][sortFields.day][sortFields.milliseconds].push(session)
597
- }
598
- // 处理未读数量逻辑
599
- if (typeof unreadMsgCount !== 'undefined') {
600
- const origUnreadMsgCount = session.unreadMsgCount || 0
601
- Vue.set(session, 'unreadMsgCount', unreadMsgCount)
602
- // let nowUnreadMsgCount = session.unreadMsgCount || 0
603
- // let diffUnreadMsgCount = nowUnreadMsgCount - origUnreadMsgCount
604
- // if (diffUnreadMsgCount) {
605
- // this.data.sessionUnreadCountMap[groupField] += diffUnreadMsgCount
606
- // }
607
- }
608
- // 处理置顶会话逻辑
609
- if (typeof stickyOnTop !== 'undefined') {
610
- Vue.set(session, 'stickyOnTop', stickyOnTop)
611
- const topField = nextProps.stickyOnTop ? 0 : 1 // 0置顶
612
- // 把已经存在的剔除,先删后插
613
- // 所有的
614
- const sortFields = this.getSortField(session[this.sortField])
615
- // 重置一下数据
616
- const topFields = [0, 1]
617
- topFields.forEach(topField => {
618
- if (this.data.sessionData[topField] && this.data.sessionData[topField][sortFields.day] && this.data.sessionData[topField][sortFields.day][sortFields.milliseconds]) {
619
- let index = -1
620
- this.data.sessionData[topField][sortFields.day][sortFields.milliseconds].some((v, i) => {
621
- if (v === session) {
622
- index = i
623
- return true
624
- }
625
- })
626
- if (index >= 0) {
627
- this.data.sessionData[topField][sortFields.day][sortFields.milliseconds].splice(index, 1)
628
- }
629
- }
630
- if (this.data.sessionGroupData[groupField] && this.data.sessionGroupData[groupField][topField] && this.data.sessionGroupData[groupField][topField][sortFields.day] && this.data.sessionGroupData[groupField][topField][sortFields.day][sortFields.milliseconds]) {
631
- let index = -1
632
- this.data.sessionGroupData[groupField][topField][sortFields.day][sortFields.milliseconds].some((v, i) => {
633
- if (v === session) {
634
- index = i
635
- return true
636
- }
637
- })
638
- this.data.sessionGroupData[groupField][topField][sortFields.day][sortFields.milliseconds].splice(index, 1)
639
- }
640
- })
641
- // 所有的
642
- if (!this.data.sessionData[topField]) {
643
- Vue.set(this.data.sessionData, topField, {})
644
- }
645
- if (!this.data.sessionData[topField][sortFields.day]) {
646
- Vue.set(this.data.sessionData[topField], sortFields.day, {})
726
+ if (!nextProps) {
727
+ return session
728
+ }
729
+ const oldGroupField = session[this.groupField] || 'unkonw'
730
+ const nextGroupField = typeof nextProps[this.groupField] === 'undefined' ? oldGroupField : (nextProps[this.groupField] || 'unkonw')
731
+ const shouldReindex = (typeof nextProps.lastMsgTime !== 'undefined' && nextProps.lastMsgTime !== session.lastMsgTime) ||
732
+ (typeof nextProps.stickyOnTop !== 'undefined' && nextProps.stickyOnTop !== session.stickyOnTop) ||
733
+ nextGroupField !== oldGroupField
734
+ if (shouldReindex) {
735
+ this._removeSessionFromDisplayData(sessionId)
736
+ }
737
+ if (typeof nextProps.mute !== 'undefined' || nextGroupField !== oldGroupField) {
738
+ Object.keys(this.data.sessionMuteMap).forEach(groupField => {
739
+ if (this.data.sessionMuteMap[groupField]) {
740
+ Vue.delete(this.data.sessionMuteMap[groupField], sessionId)
647
741
  }
648
- if (!this.data.sessionData[topField][sortFields.day][sortFields.milliseconds]) {
649
- Vue.set(this.data.sessionData[topField][sortFields.day], sortFields.milliseconds, [])
650
- }
651
- this.data.sessionData[topField][sortFields.day][sortFields.milliseconds].push(session)
652
- // 分组的
653
- if (!this.data.sessionGroupData[groupField]) {
654
- Vue.set(this.data.sessionGroupData, groupField, {})
655
- }
656
- if (!this.data.sessionGroupData[groupField][topField]) {
657
- Vue.set(this.data.sessionGroupData[groupField], topField, {})
658
- }
659
- if (!this.data.sessionGroupData[groupField][topField][sortFields.day]) {
660
- Vue.set(this.data.sessionGroupData[groupField][topField], sortFields.day, {})
661
- }
662
- if (!this.data.sessionGroupData[groupField][topField][sortFields.day][sortFields.milliseconds]) {
663
- Vue.set(this.data.sessionGroupData[groupField][topField][sortFields.day], sortFields.milliseconds, [])
664
- }
665
- this.data.sessionGroupData[groupField][topField][sortFields.day][sortFields.milliseconds].push(session)
742
+ })
743
+ }
744
+ Object.keys(nextProps).forEach(key => {
745
+ if (session[key] !== nextProps[key]) {
746
+ Vue.set(session, key, nextProps[key])
666
747
  }
667
- // 处理免打扰
668
- if (typeof mute !== 'undefined') {
669
- Vue.set(session, 'mute', mute)
670
- if (mute) {
671
- if (!this.data.sessionMuteMap[groupField]) {
672
- Vue.set(this.data.sessionMuteMap, groupField, {})
673
- }
674
- if (!this.data.sessionMuteMap[groupField][session.id]) {
675
- Vue.set(this.data.sessionMuteMap[groupField], session.id, session)
676
- }
677
- } else {
678
- if (this.data.sessionMuteMap[groupField]) {
679
- Vue.delete(this.data.sessionMuteMap[groupField], session.id)
680
- }
681
- }
748
+ })
749
+ if (shouldReindex) {
750
+ this._insertSessionIntoDisplayData(session)
751
+ }
752
+ const groupField = session[this.groupField] || 'unkonw'
753
+ if (session.mute) {
754
+ if (!this.data.sessionMuteMap[groupField]) {
755
+ Vue.set(this.data.sessionMuteMap, groupField, {})
682
756
  }
757
+ Vue.set(this.data.sessionMuteMap[groupField], session.id, session)
683
758
  }
759
+ return session
684
760
  }
685
761
 
686
762
  /**
@@ -909,12 +985,16 @@ export default class ClientChatSession {
909
985
  }
910
986
 
911
987
  reset () {
988
+ this.stopGetSessionPollRequests()
912
989
  this.lastUpdateTime = null
913
990
  this.lastUpdateSession = null
914
991
  this.lastSession = null
992
+ this._lastUpdateSessionMap = {}
993
+ this._reverseLastUpdateSessionMap = {}
915
994
  this.data.sessionData = {}
916
995
  this.data.sessionGroupData = {}
917
996
  this.data.sessionMuteMap = {}
997
+ this.data.modifiedAccountMap = {}
918
998
  // this.data.sessionUnreadCountMap = {}
919
999
  this.sessionMap = {}
920
1000
  if (this.cancelLoadDataRequest) {
@@ -926,4 +1006,4 @@ export default class ClientChatSession {
926
1006
  this.cancelRefreshRequest = null
927
1007
  }
928
1008
  }
929
- }
1009
+ }
@@ -15,11 +15,16 @@ export default class ClietChatSocket {
15
15
  // 执行回调事件前的方法
16
16
  beforeFireCallback: null,
17
17
  onCmdQwNewMessage: null,
18
+ onCmdQwContactInfoChanged: null,
19
+ onCmdQwContactRequestChanged: null,
20
+ onCmdQwAcceptContactRequest: null,
21
+ onCmdQwRoomInfoChanged: null,
18
22
  onCmdSendMessageResult: null,
19
23
  onCmdFriendInfoChanged: null,
20
24
  onCmdDownloadVideoResult: null,
21
25
  onCmdChatroomInfoChanged: null,
22
26
  onCmdChatroomInfoChangedBatch: null,
27
+ onHeartbeatSuccess: null,
23
28
  onHeartbeatCheck: null
24
29
  }, options)
25
30
  if (!options.socket) {
@@ -27,6 +32,13 @@ export default class ClietChatSocket {
27
32
  }
28
33
  this.socket = options.socket
29
34
  this.socket.event.on('onCmdQwNewMessage', options.onCmdQwNewMessage)
35
+ this.socket.event.on('onCmdQwContactInfoChanged', options.onCmdQwContactInfoChanged)
36
+ this.socket.event.on('onCmdQwContactRequestChanged', options.onCmdQwContactRequestChanged)
37
+ this.socket.event.on('onCmdQwAcceptContactRequest', options.onCmdQwAcceptContactRequest)
38
+ this.socket.event.on('onCmdQwRoomInfoChanged', options.onCmdQwRoomInfoChanged)
39
+ this.socket.event.on('onHeartbeatSuccess', (evt) => {
40
+ options.onHeartbeatSuccess && options.onHeartbeatSuccess(evt)
41
+ })
30
42
  this.socket.event.on('onHeartbeatCheck', ({ mergeParams }) => {
31
43
  options.onHeartbeatCheck && options.onHeartbeatCheck({
32
44
  mergeParams
@@ -62,4 +74,4 @@ export default class ClietChatSocket {
62
74
  setUrl (url) {
63
75
  this.socket.setUrl(url)
64
76
  }
65
- }
77
+ }