@aochuang/client-sdk 1.0.319 → 1.0.321

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.319",
3
+ "version": "1.0.321",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -141,7 +141,7 @@ class ClientChat {
141
141
  })
142
142
  const mergeSessionCommonOptions = (options, instance) => {
143
143
  let updateSessioning = false
144
- let deleteSessioning = false
144
+ let removeSessioning = false
145
145
  options.onAddSession = ({ session }) => {
146
146
  // 同步未读会话
147
147
  if (instance !== this.sessionUnread && session.unreadMsgCount > 0) {
@@ -219,23 +219,15 @@ class ClientChat {
219
219
  }
220
220
  }
221
221
  options.onRemoveSession = ({ session }) => {
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
- }
229
- }
230
- options.onDeleteSession = ({ session }) => {
231
- if (!session) {
222
+ if (instance !== this.session) {
232
223
  return
233
224
  }
234
- if (deleteSessioning) {
225
+ if (removeSessioning) {
235
226
  return
236
227
  }
237
- deleteSessioning = true
228
+ removeSessioning = true
238
229
  try {
230
+ // 同步账号未读数量
239
231
  this.account.updateAccountUnreadMessageNum(session.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => {
240
232
  // 如果是免打扰的会话
241
233
  if (session.mute) {
@@ -274,9 +266,12 @@ class ClientChat {
274
266
  })
275
267
  throw error
276
268
  } finally {
277
- deleteSessioning = false
269
+ removeSessioning = false
278
270
  }
279
271
  }
272
+ options.onDeleteSession = ({ session }) => {
273
+ // todo
274
+ }
280
275
  options.onClearVirtualSession = ({ virtualSessionData }) => {
281
276
  const selectedVirtualSession = virtualSessionData.find(v => this.sessionManage.currentSession && v.conversationId === this.sessionManage.currentSession.conversationId)
282
277
  if (selectedVirtualSession) {
@@ -901,9 +896,11 @@ class ClientChat {
901
896
  rs[v.wechatAccountId] = true
902
897
  return rs
903
898
  }, {}))
899
+ const changeFriendMap = {}
904
900
  // 删除changeType为3移除的好友,例如转移的场景
905
901
  if (data.friends && data.friends.length) {
906
902
  data.friends.forEach(friend => {
903
+ changeFriendMap[friend.wechatFriendId] = friend
907
904
  if (friend.changeType === 3) {
908
905
  const removedFriend = this.contacts.removeFriend(friend.wechatFriendId)
909
906
  if (!removedFriend) {
@@ -924,6 +921,31 @@ class ClientChat {
924
921
  ps = this.account.reloadData()
925
922
  }
926
923
  }
924
+ // 这里还需要刷新一下当前会话选中的好友
925
+ if (this.sessionManage.currentSession && changeFriendMap[this.sessionManage.currentSession.targetId]) {
926
+ const sessionFriendId = this.sessionManage.currentSession.targetId
927
+ ps = ps.then(() => {
928
+ return this.contacts.getFriend(sessionFriendId, true)
929
+ })
930
+ }
931
+ // 刷新工作微信号未读消息数量
932
+ if (rs && rs.length) {
933
+ rs.forEach(session => {
934
+ this.account.updateAccountUnreadMessageNum(session.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => {
935
+ if (session.mute) {
936
+ return {
937
+ num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
938
+ muteNum: (unreadMessageMuteNum || 0) + (session.unreadMsgCount || 0)
939
+ }
940
+ } else {
941
+ return {
942
+ num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
943
+ muteNum: unreadMessageMuteNum
944
+ }
945
+ }
946
+ })
947
+ })
948
+ }
927
949
  return ps.finally(() => {
928
950
  // 这里应该标记那些工作微信号的通讯录修改了,后面要在界面打个提示,告诉用户通讯录变化了,让手动刷新一下
929
951
  // 同时也将缓存都清理一下,例如工作微信号分组统计数量等
@@ -988,6 +1010,24 @@ class ClientChat {
988
1010
  ps = this.account.reloadData()
989
1011
  }
990
1012
  }
1013
+ // 刷新工作微信号未读消息数量
1014
+ if (rs && rs.length) {
1015
+ rs.forEach(session => {
1016
+ this.account.updateAccountUnreadMessageNum(session.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => {
1017
+ if (session.mute) {
1018
+ return {
1019
+ num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
1020
+ muteNum: (unreadMessageMuteNum || 0) + (session.unreadMsgCount || 0)
1021
+ }
1022
+ } else {
1023
+ return {
1024
+ num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
1025
+ muteNum: unreadMessageMuteNum
1026
+ }
1027
+ }
1028
+ })
1029
+ })
1030
+ }
991
1031
  return ps.finally(() => {
992
1032
  // 这里应该标记那些工作微信号的通讯录修改了,后面要在界面打个提示,告诉用户通讯录变化了,让手动刷新一下
993
1033
  // 同时也将缓存都清理一下,例如工作微信号分组统计数量等