@aochuang/client-sdk 1.0.402 → 1.0.403

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.402",
3
+ "version": "1.0.403",
4
4
  "description": "",
5
5
  "files": [
6
6
  "common",
@@ -1048,17 +1048,18 @@ export default class ClientChatSession {
1048
1048
  if (typeof dto.unreadMsgCount !== 'number') {
1049
1049
  throw new Error('标记未读返回的未读数无效')
1050
1050
  }
1051
+ const beforeUnreadMsgCount = session.unreadMsgCount || 0
1051
1052
  const localLastMsgTime = session.lastMsgTime || 0
1052
1053
  const serverLastMsgTime = dto.lastMsgTime || 0
1053
- if (serverLastMsgTime < localLastMsgTime) {
1054
- return {
1055
- applied: false,
1056
- reason: 'stale-last-message'
1057
- }
1058
- }
1059
- const beforeUnreadMsgCount = session.unreadMsgCount || 0
1054
+ const isSameLastMessage = Boolean(
1055
+ session.lastMsgId && dto.lastMsgId && session.lastMsgId === dto.lastMsgId
1056
+ )
1057
+ const shouldApplyLastMessage = isSameLastMessage || serverLastMsgTime >= localLastMsgTime
1058
+ const afterUnreadMsgCount = shouldApplyLastMessage
1059
+ ? dto.unreadMsgCount
1060
+ : Math.max(beforeUnreadMsgCount, dto.unreadMsgCount)
1060
1061
  const patch = {
1061
- unreadMsgCount: dto.unreadMsgCount
1062
+ unreadMsgCount: afterUnreadMsgCount
1062
1063
  }
1063
1064
  const lastMessageFields = [
1064
1065
  'lastMsgId',
@@ -1067,22 +1068,24 @@ export default class ClientChatSession {
1067
1068
  'lastMsgContent',
1068
1069
  'senderWechatIdHash'
1069
1070
  ]
1070
- lastMessageFields.forEach(field => {
1071
- if (typeof dto[field] !== 'undefined' && dto[field] !== null) {
1072
- patch[field] = dto[field]
1073
- }
1074
- })
1071
+ if (shouldApplyLastMessage) {
1072
+ lastMessageFields.forEach(field => {
1073
+ if (typeof dto[field] !== 'undefined' && dto[field] !== null) {
1074
+ patch[field] = dto[field]
1075
+ }
1076
+ })
1077
+ }
1075
1078
  this.updateSession(sessionId, patch)
1076
1079
  const unreadChangeResult = this.onSessionUnreadChange && this.onSessionUnreadChange({
1077
1080
  session,
1078
1081
  beforeUnreadMsgCount,
1079
- afterUnreadMsgCount: dto.unreadMsgCount
1082
+ afterUnreadMsgCount
1080
1083
  })
1081
1084
  const result = {
1082
1085
  applied: true,
1083
1086
  session,
1084
1087
  beforeUnreadMsgCount,
1085
- afterUnreadMsgCount: dto.unreadMsgCount
1088
+ afterUnreadMsgCount
1086
1089
  }
1087
1090
  if (unreadChangeResult && typeof unreadChangeResult.then === 'function') {
1088
1091
  return unreadChangeResult.then(() => result)