@aochuang/client-sdk 1.0.315 → 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.315",
3
+ "version": "1.0.316",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -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) {
@@ -219,7 +219,13 @@ class ClientChat {
219
219
  }
220
220
  }
221
221
  options.onRemoveSession = ({ session }) => {
222
- // 移除不做同步,例如未读会话,前端会自己删除已读的会话,这个时候不能做同步,否则会把最近会话也移除了
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
+ }
223
229
  }
224
230
  options.onDeleteSession = ({ session }) => {
225
231
  if (!session) {
@@ -687,7 +693,23 @@ class ClientChat {
687
693
  getContactsRoomMethod: options.getContactsRoomMethod,
688
694
  getContactsFriendGroupCountMethod: options.getContactsFriendGroupCountMethod,
689
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
+ },
690
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
+ }
691
713
  const accountId = options.getLoginAccountIdMethod ? options.getLoginAccountIdMethod() : room.accountId
692
714
  let sessionId = createSessionId(accountId, room.id)
693
715
  if (sessionId) {
@@ -883,7 +905,15 @@ class ClientChat {
883
905
  if (data.friends && data.friends.length) {
884
906
  data.friends.forEach(friend => {
885
907
  if (friend.changeType === 3) {
886
- 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
+ }
887
917
  }
888
918
  })
889
919
  }
@@ -910,15 +940,16 @@ class ClientChat {
910
940
  }
911
941
  // 删除好友
912
942
  else if (data.changeType === 3) {
913
- // 删除会话
914
- const session = this.session.findSession(({ session }) => {
915
- return session.targetId === data.wechatFriendId
916
- })
917
- if (session) {
918
- this.session.removeSession(session.conversationId)
919
- }
920
943
  // 删除好友
921
- 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
+ }
922
953
  // todo 刷新一下微信号,如果微信号一个好友都没了,应该要删除掉的
923
954
  this.contacts.markModify() // 标记通讯录修改
924
955
  }