@aochuang/client-sdk 1.0.341 → 1.0.343

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.341",
3
+ "version": "1.0.343",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -229,14 +229,14 @@ export default class ClientChatSession {
229
229
  }
230
230
 
231
231
  getSession (sessionId, serializeMethod) {
232
- if (this.sessionMap[sessionId]) {
232
+ if (this.sessionMap[sessionId]) {
233
233
  return Promise.resolve({
234
234
  data: this.sessionMap[sessionId]
235
235
  })
236
236
  }
237
237
  // 这里需要轮询从后端获取会话,后端会话更新和创建是异步的,所以要多轮训请求几次
238
238
  if (this.pollRequestMap[sessionId]) {
239
- this.pollRequestMap[sessionId].stop()
239
+ return this.pollRequestMap[sessionId].ps
240
240
  }
241
241
  const pollRequest = createPollRequest(({ done, fail }) => {
242
242
  return this.getSessionMethod({
@@ -248,7 +248,7 @@ export default class ClientChatSession {
248
248
  })
249
249
  })
250
250
  this.pollRequestMap[sessionId] = pollRequest
251
- return pollRequest.start().then(rs => {
251
+ this.pollRequestMap[sessionId].ps = pollRequest.start().then(rs => {
252
252
  if (serializeMethod) {
253
253
  rs = serializeMethod(rs)
254
254
  }
@@ -263,6 +263,7 @@ export default class ClientChatSession {
263
263
  delete this.pollRequestMap[sessionId]
264
264
  }
265
265
  })
266
+ return this.pollRequestMap[sessionId].ps
266
267
  }
267
268
 
268
269
  findSession (findFn) {
@@ -452,9 +452,15 @@ class ClientChat {
452
452
  }
453
453
  })
454
454
  })
455
- } else {
456
- this.session.updateSession(sessionId, ({ session }) => {
457
- const nextSession = {
455
+ } else {
456
+ this.session.updateSession(sessionId, ({ session }) => {
457
+ // listChange/getSession may already include this message in unreadMsgCount.
458
+ // Only count messages newer than the session watermark.
459
+ const isNewerMessage = data.wechatTime > (session.lastMsgTime || 0)
460
+ if (!isNewerMessage) {
461
+ return {}
462
+ }
463
+ const nextSession = {
458
464
  lastMsgContent: data.content,
459
465
  lastMsgType: data.msgType,
460
466
  lastMsgTime: data.wechatTime,
@@ -462,7 +468,7 @@ class ClientChat {
462
468
  lastUpdateTime: data.updateDate,
463
469
  unreadMsgCount: session.unreadMsgCount
464
470
  }
465
- if (!data.isSend) {
471
+ if (!data.isSend && isNewerMessage) {
466
472
  if (this.sessionManage.currentSession && this.sessionManage.currentSession.conversationId === sessionId && this.shouldMarkCurrentSessionRead(sessionId, data)) {
467
473
  // 标记已读
468
474
  this.session.setSessionRead(sessionId)
@@ -594,9 +600,15 @@ class ClientChat {
594
600
  }
595
601
  })
596
602
  })
597
- } else {
598
- this.session.updateSession(sessionId, ({ session }) => {
599
- const nextSession = {
603
+ } else {
604
+ this.session.updateSession(sessionId, ({ session }) => {
605
+ // listChange/getSession may already include this message in unreadMsgCount.
606
+ // Only count messages newer than the session watermark.
607
+ const isNewerMessage = data.wechatTime > (session.lastMsgTime || 0)
608
+ if (!isNewerMessage) {
609
+ return {}
610
+ }
611
+ const nextSession = {
600
612
  lastMsgContent: data.content,
601
613
  lastMsgType: data.msgType,
602
614
  lastMsgTime: data.wechatTime,
@@ -604,7 +616,7 @@ class ClientChat {
604
616
  lastUpdateTime: data.updateDate,
605
617
  unreadMsgCount: session.unreadMsgCount
606
618
  }
607
- if (!data.isSend) {
619
+ if (!data.isSend && isNewerMessage) {
608
620
  if (this.sessionManage.currentSession && this.sessionManage.currentSession.conversationId === sessionId && this.shouldMarkCurrentSessionRead(sessionId, data)) {
609
621
  // 标记已读
610
622
  this.session.setSessionRead(sessionId)