@aochuang/client-sdk 1.0.350 → 1.0.351

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.350",
3
+ "version": "1.0.351",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -228,50 +228,40 @@ export default class ClientChatSession {
228
228
  })
229
229
  }
230
230
 
231
- getSession (sessionId, serializeMethod, callback = null, isCache = true) {
232
- if (typeof callback === 'boolean') {
233
- isCache = callback
234
- callback = null
235
- }
231
+ getSession (sessionId, serializeMethod) {
236
232
  if (this.sessionMap[sessionId]) {
237
233
  return Promise.resolve({
238
234
  data: this.sessionMap[sessionId]
239
235
  })
240
236
  }
241
237
  // 这里需要轮询从后端获取会话,后端会话更新和创建是异步的,所以要多轮训请求几次
242
- if (this.pollRequestMap[sessionId]) {
243
- // 因为有的地方要复用缓存,有的地方不能缓存,比如onAddMessagSuccess的时候不能缓存
244
- if (isCache) {
245
- return this.pollRequestMap[sessionId].ps
246
- } else {
247
- this.pollRequestMap[sessionId].stop()
248
- }
249
- }
250
- const pollRequest = createPollRequest(({ done, fail }) => {
251
- return this.getSessionMethod({
252
- id: sessionId
253
- }).then((rs) => {
238
+ if (!this.pollRequestMap[sessionId] || !this.pollRequestMap[sessionId].ps) {
239
+ const pollRequest = createPollRequest(({ done, fail }) => {
240
+ return this.getSessionMethod({
241
+ id: sessionId
242
+ }).then((rs) => {
243
+ if (rs.data) {
244
+ done(rs)
245
+ }
246
+ })
247
+ })
248
+ this.pollRequestMap[sessionId] = pollRequest
249
+ this.pollRequestMap[sessionId].ps = pollRequest.start().then(rs => {
250
+ if (serializeMethod) {
251
+ rs = serializeMethod(rs)
252
+ }
254
253
  if (rs.data) {
255
- done(rs)
254
+ this.addSession(rs.data, null)
255
+ return rs
256
+ } else {
257
+ return Promise.reject('未找到会话' + sessionId)
258
+ }
259
+ }).finally(() => {
260
+ if (this.pollRequestMap[sessionId] === pollRequest) {
261
+ delete this.pollRequestMap[sessionId]
256
262
  }
257
263
  })
258
- })
259
- this.pollRequestMap[sessionId] = pollRequest
260
- this.pollRequestMap[sessionId].ps = pollRequest.start().then(rs => {
261
- if (serializeMethod) {
262
- rs = serializeMethod(rs)
263
- }
264
- if (rs.data) {
265
- this.addSession(rs.data, null, callback)
266
- return rs
267
- } else {
268
- return Promise.reject('未找到会话' + sessionId)
269
- }
270
- }).finally(() => {
271
- if (this.pollRequestMap[sessionId] === pollRequest) {
272
- delete this.pollRequestMap[sessionId]
273
- }
274
- })
264
+ }
275
265
  return this.pollRequestMap[sessionId].ps
276
266
  }
277
267
 
@@ -397,7 +387,7 @@ export default class ClientChatSession {
397
387
  * "wechatAccountId": "2a39a725814acf07502299ab2285fff8d44377f5"
398
388
  * }
399
389
  */
400
- addSession (data, wechatAccountId, callback) {
390
+ addSession (data, wechatAccountId) {
401
391
  if (!data || !data.conversationId) {
402
392
  throw new Error('缺少必须参数conversationId')
403
393
  }
@@ -499,10 +489,8 @@ export default class ClientChatSession {
499
489
  if (virtualSessionIndex > -1) {
500
490
  this.data.virtualSessionData.splice(virtualSessionIndex, 1)
501
491
  }
502
- callback && callback({
503
- session: nextData
504
- })
505
492
  this.onAddSession && this.onAddSession({
493
+ wechatAccountId,
506
494
  session: nextData
507
495
  })
508
496
  }
@@ -115,7 +115,24 @@ class ClientChat {
115
115
  const mergeSessionCommonOptions = (options, instance) => {
116
116
  let updateSessioning = false
117
117
  let removeSessioning = false
118
- options.onAddSession = ({ session }) => {
118
+ options.onAddSession = ({ session, wechatAccountId }) => {
119
+ // 不是来源于分页的时候,没有wechatAccountId就是代表不是走的分页增加的会话,一般为获取新消息或则分配的会话
120
+ if (!wechatAccountId && instance === this.session) {
121
+ // 更新账号未读消息数量
122
+ this.account.updateAccountUnreadMessageNum(session.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => {
123
+ if (session.mute) {
124
+ return {
125
+ num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
126
+ muteNum: (unreadMessageMuteNum || 0) + (session.unreadMsgCount || 0)
127
+ }
128
+ } else {
129
+ return {
130
+ num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
131
+ muteNum: unreadMessageMuteNum
132
+ }
133
+ }
134
+ })
135
+ }
119
136
  // 同步未读会话
120
137
  if (instance !== this.sessionUnread && session.unreadMsgCount > 0) {
121
138
  const localSession = this.sessionUnread.findSession((localSession) => localSession.conversationId === session.conversationId)
@@ -423,22 +440,7 @@ class ClientChat {
423
440
  rs.data.lastUpdateTime = data.updateDate
424
441
  }
425
442
  return rs
426
- }, ({ session }) => {
427
- // 更新账号未读消息数量
428
- this.account.updateAccountUnreadMessageNum(session.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => {
429
- if (session.mute) {
430
- return {
431
- num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
432
- muteNum: (unreadMessageMuteNum || 0) + (session.unreadMsgCount || 0)
433
- }
434
- } else {
435
- return {
436
- num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
437
- muteNum: unreadMessageMuteNum
438
- }
439
- }
440
- })
441
- }, false).then((rs => {
443
+ }).then((rs => {
442
444
  // 前面更新未读消息数量只是处理会话的时候,因为getSession是异步的,会导致addMessage多次执行到这里,不会倒下面更新会话的逻辑
443
445
  // 比如连续发了3条消息,然后getSession后端返回可能只会返回2条未读数,所以这里还需要补偿一下
444
446
  const session = rs.data || {}
@@ -594,22 +596,7 @@ class ClientChat {
594
596
  rs.data.lastAtMsgContent = appendLastAtMsgContent(rs.data.lastAtMsgContent, atMessage)
595
597
  }
596
598
  return rs
597
- }, ({ session }) => {
598
- // 更新账号未读消息数量
599
- this.account.updateAccountUnreadMessageNum(session.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => {
600
- if (session.mute) {
601
- return {
602
- num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
603
- muteNum: (unreadMessageMuteNum || 0) + (session.unreadMsgCount || 0)
604
- }
605
- } else {
606
- return {
607
- num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
608
- muteNum: unreadMessageMuteNum
609
- }
610
- }
611
- })
612
- }, false).then(rs => {
599
+ }).then(rs => {
613
600
  // 前面更新未读消息数量只是处理会话的时候,因为getSession是异步的,会导致addMessage多次执行到这里,不会倒下面更新会话的逻辑
614
601
  // 比如连续发了3条消息,然后getSession后端返回可能只会返回2条未读数,所以这里还需要补偿一下
615
602
  const session = rs.data || {}