@aochuang/client-sdk 1.0.314 → 1.0.316

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aochuang/client-sdk",
3
- "version": "1.0.314",
3
+ "version": "1.0.316",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -23,6 +23,7 @@ export default class ClientChatAccount {
23
23
  updateAccountMessageReadMethod: null,
24
24
  deleteAccountSessionMethod: null,
25
25
  getAccountGreetingUnreadMsgCountMethod: null,
26
+ batchGetAccountGreetingUnreadMsgCountMethod: null,
26
27
  clearAccountGreetingUnreadMsgCountMethod: null,
27
28
  onCurrentAccountChange: null,
28
29
  onAccountAdded: null,
@@ -43,6 +44,7 @@ export default class ClientChatAccount {
43
44
  this.updateAccountMessageReadMethod = options.updateAccountMessageReadMethod
44
45
  this.deleteAccountSessionMethod = options.deleteAccountSessionMethod
45
46
  this.getAccountGreetingUnreadMsgCountMethod = options.getAccountGreetingUnreadMsgCountMethod
47
+ this.batchGetAccountGreetingUnreadMsgCountMethod = options.batchGetAccountGreetingUnreadMsgCountMethod
46
48
  this.clearAccountGreetingUnreadMsgCountMethod = options.clearAccountGreetingUnreadMsgCountMethod
47
49
  this.onAccountAdded = options.onAccountAdded
48
50
  this.onAccountRemoved = options.onAccountRemoved,
@@ -394,6 +396,41 @@ export default class ClientChatAccount {
394
396
  })
395
397
  }
396
398
 
399
+ /**
400
+ * 批量获取所有账号的打招呼未读消息总数
401
+ */
402
+ refreshAllAccountGreetingUnreadMsgCount () {
403
+ if (!this.batchGetAccountGreetingUnreadMsgCountMethod) {
404
+ return new Error('batchGetAccountGreetingUnreadMsgCountMethod未定义')
405
+ }
406
+ const wechatAccountIds = this.data.accountData.map(v => v.id).filter((id, index, data) => id && data.indexOf(id) === index)
407
+ const countData = {}
408
+ let requestPromise = Promise.resolve()
409
+ for (let index = 0; index < wechatAccountIds.length; index += 100) {
410
+ const currentWechatAccountIds = wechatAccountIds.slice(index, index + 100)
411
+ requestPromise = requestPromise.then(() => {
412
+ return this.batchGetAccountGreetingUnreadMsgCountMethod({
413
+ wechatAccountIds: currentWechatAccountIds
414
+ })
415
+ }).then(rs => {
416
+ ;(rs && rs.data || []).forEach(item => {
417
+ if (item && item.wechatAccountId) {
418
+ countData[item.wechatAccountId] = item.count || 0
419
+ }
420
+ })
421
+ })
422
+ }
423
+ return requestPromise.then(() => {
424
+ let allCount = 0
425
+ wechatAccountIds.forEach(wechatAccountId => {
426
+ const count = countData[wechatAccountId] || 0
427
+ Vue.set(this.accountGreetingUnreadMsgCountData, wechatAccountId, count)
428
+ allCount += count
429
+ })
430
+ Vue.set(this.accountGreetingUnreadMsgCountData, 'all', allCount)
431
+ })
432
+ }
433
+
397
434
  /**
398
435
  * 清空打招呼未读消息总数
399
436
  */
@@ -414,10 +451,11 @@ export default class ClientChatAccount {
414
451
  reset () {
415
452
  this.data.accountData = []
416
453
  this.data.accountUnreadMessageNumData = []
454
+ this.data.accountGreetingUnreadMsgCountData = {}
417
455
  if (this.cancelConnectRequest) {
418
456
  this.cancelConnectRequest()
419
457
  }
420
458
  this._cacheLoadPromise = null
421
459
  this.cancelConnectRequest = null
422
460
  }
423
- }
461
+ }
@@ -176,6 +176,7 @@ export default class ClientChatContacts {
176
176
  getContactsRoomMethod: null,
177
177
  getContactsFriendGroupCountMethod: null,
178
178
  getContactsRoomGroupCountMethod: null,
179
+ onContactsFriendRemoved: null,
179
180
  onContactsRoomRemoved: null,
180
181
  onLoadRoomGroupData: null,
181
182
  onLoadFriendGroupData: null,
@@ -218,6 +219,7 @@ export default class ClientChatContacts {
218
219
  this.getContactsRoomMethod = options.getContactsRoomMethod
219
220
  this.getContactsRoomGroupCountMethod = options.getContactsRoomGroupCountMethod
220
221
  this.getContactsFriendGroupCountMethod = options.getContactsFriendGroupCountMethod
222
+ this.onContactsFriendRemoved = options.onContactsFriendRemoved
221
223
  this.onContactsRoomRemoved = options.onContactsRoomRemoved
222
224
  this.onLoadRoomGroupData = options.onLoadRoomGroupData
223
225
  this.onLoadFriendGroupData = options.onLoadFriendGroupData
@@ -436,7 +438,8 @@ export default class ClientChatContacts {
436
438
  if (!this.friendMap[id]) {
437
439
  return
438
440
  }
439
- const index = this.data.friendData.indexOf(this.friendMap[id])
441
+ const friend = this.friendMap[id]
442
+ const index = this.data.friendData.indexOf(friend)
440
443
  if (index >= 0) {
441
444
  this.data.friendData.splice(index, 1)
442
445
  }
@@ -457,6 +460,10 @@ export default class ClientChatContacts {
457
460
  }
458
461
  })
459
462
  delete this.friendMap[id]
463
+ this.onContactsFriendRemoved && this.onContactsFriendRemoved({
464
+ friend
465
+ })
466
+ return friend
460
467
  }
461
468
 
462
469
  updateFriend (id, props) {
@@ -93,6 +93,7 @@ class ClientChat {
93
93
  updateAccountMessageReadMethod: null,
94
94
  deleteAccountSessionMethod: null,
95
95
  getAccountGreetingUnreadMsgCountMethod: null,
96
+ batchGetAccountGreetingUnreadMsgCountMethod: null,
96
97
  clearAccountGreetingUnreadMsgCountMethod: null,
97
98
  loadContactsRoomGroupDataMethod: null,
98
99
  loadContactsFriendGroupDataMethod: null,
@@ -218,7 +219,13 @@ class ClientChat {
218
219
  }
219
220
  }
220
221
  options.onRemoveSession = ({ session }) => {
221
- // 移除不做同步,例如未读会话,前端会自己删除已读的会话,这个时候不能做同步,否则会把最近会话也移除了
222
+ // 未读、星标等实例的局部移除不同步到其他实例,主会话移除时仅同步清理搜索缓存
223
+ if (instance === this.session) {
224
+ this.sessionFilter.removeSession(session.conversationId)
225
+ if (this.sessionManage.currentSession && this.sessionManage.currentSession.conversationId === session.conversationId) {
226
+ this.sessionManage.setCurrentSession(null)
227
+ }
228
+ }
222
229
  }
223
230
  options.onDeleteSession = ({ session }) => {
224
231
  if (!session) {
@@ -686,7 +693,23 @@ class ClientChat {
686
693
  getContactsRoomMethod: options.getContactsRoomMethod,
687
694
  getContactsFriendGroupCountMethod: options.getContactsFriendGroupCountMethod,
688
695
  getContactsRoomGroupCountMethod: options.getContactsRoomGroupCountMethod,
696
+ onContactsFriendRemoved: ({ friend }) => {
697
+ this.contactsFilter.removeFriend(friend.id)
698
+ if (this.sessionManage.currentSession && this.sessionManage.currentSession.type === 0 && this.sessionManage.currentSession.targetId === friend.id) {
699
+ this.sessionManage.setCurrentSession(null)
700
+ }
701
+ const session = this.session.findSession(({ session }) => {
702
+ return session.targetId === friend.id
703
+ })
704
+ if (session) {
705
+ this.session.removeSession(session.conversationId)
706
+ }
707
+ },
689
708
  onContactsRoomRemoved: ({ room }) => {
709
+ this.contactsFilter.removeRoom(room.id)
710
+ if (this.sessionManage.currentSession && this.sessionManage.currentSession.type === 1 && this.sessionManage.currentSession.targetId === room.id) {
711
+ this.sessionManage.setCurrentSession(null)
712
+ }
690
713
  const accountId = options.getLoginAccountIdMethod ? options.getLoginAccountIdMethod() : room.accountId
691
714
  let sessionId = createSessionId(accountId, room.id)
692
715
  if (sessionId) {
@@ -737,6 +760,7 @@ class ClientChat {
737
760
  updateAccountMessageReadMethod: options.updateAccountMessageReadMethod,
738
761
  deleteAccountSessionMethod: options.deleteAccountSessionMethod,
739
762
  getAccountGreetingUnreadMsgCountMethod: options.getAccountGreetingUnreadMsgCountMethod,
763
+ batchGetAccountGreetingUnreadMsgCountMethod: options.batchGetAccountGreetingUnreadMsgCountMethod,
740
764
  clearAccountGreetingUnreadMsgCountMethod: options.clearAccountGreetingUnreadMsgCountMethod,
741
765
  onAccountAdded: ({ account }) => {
742
766
  return this.account.refreshAccountUnreadMessageNum({
@@ -745,6 +769,7 @@ class ClientChat {
745
769
  },
746
770
  onAccountLoaded: () => {
747
771
  this.socket.doHeartbeat()
772
+ this.account.refreshAllAccountGreetingUnreadMsgCount().catch(() => {})
748
773
  },
749
774
  onCurrentAccountChange: ({ currentAccount }) => {
750
775
  // // 如果群分组数据加载了再去刷成员数量,这样可以做到按需
@@ -880,7 +905,15 @@ class ClientChat {
880
905
  if (data.friends && data.friends.length) {
881
906
  data.friends.forEach(friend => {
882
907
  if (friend.changeType === 3) {
883
- this.contacts.removeFriend(friend.wechatFriendId)
908
+ const removedFriend = this.contacts.removeFriend(friend.wechatFriendId)
909
+ if (!removedFriend) {
910
+ const session = this.session.findSession(({ session }) => {
911
+ return session.targetId === friend.wechatFriendId
912
+ })
913
+ if (session) {
914
+ this.session.removeSession(session.conversationId)
915
+ }
916
+ }
884
917
  }
885
918
  })
886
919
  }
@@ -907,15 +940,16 @@ class ClientChat {
907
940
  }
908
941
  // 删除好友
909
942
  else if (data.changeType === 3) {
910
- // 删除会话
911
- const session = this.session.findSession(({ session }) => {
912
- return session.targetId === data.wechatFriendId
913
- })
914
- if (session) {
915
- this.session.removeSession(session.conversationId)
916
- }
917
943
  // 删除好友
918
- this.contacts.removeFriend(data.wechatFriendId)
944
+ const removedFriend = this.contacts.removeFriend(data.wechatFriendId)
945
+ if (!removedFriend) {
946
+ const session = this.session.findSession(({ session }) => {
947
+ return session.targetId === data.wechatFriendId
948
+ })
949
+ if (session) {
950
+ this.session.removeSession(session.conversationId)
951
+ }
952
+ }
919
953
  // todo 刷新一下微信号,如果微信号一个好友都没了,应该要删除掉的
920
954
  this.contacts.markModify() // 标记通讯录修改
921
955
  }