@aochuang/client-sdk 1.0.369 → 1.0.371

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.369",
3
+ "version": "1.0.371",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -1279,12 +1279,6 @@ class ClientChat {
1279
1279
  return readPromise.finally(() => {
1280
1280
  if (sessionInstances && sessionInstances.length) {
1281
1281
  sessionInstances[0].markSessionRead(sessionId)
1282
- sessionInstances.forEach(sessionInstance => {
1283
- sessionInstance.removeSession(sessionId)
1284
- })
1285
- }
1286
- if (this.sessionManage.currentSession && this.sessionManage.currentSession.conversationId === sessionId) {
1287
- this.sessionManage.setCurrentSession(null)
1288
1282
  }
1289
1283
  })
1290
1284
  }
package/utils/log.js CHANGED
@@ -21,6 +21,7 @@ const INDEXED_DB_META_STORE_NAME = 'meta'
21
21
  const INDEXED_DB_ORDER_INDEX_NAME = 'order'
22
22
  const INDEXED_DB_MAX_SIZE = 50 * 1024 * 1024
23
23
  const INDEXED_DB_STATS_KEY = 'stats'
24
+ const AUTO_PUBLISH_DELAY = 1000
24
25
 
25
26
  function isUniRuntime () {
26
27
  try {
@@ -208,7 +209,9 @@ export default class Log {
208
209
  this._writePromise = Promise.resolve()
209
210
  this._indexedDbPromise = null
210
211
  this._syncPromise = null
212
+ this._syncCompleted = false
211
213
  this._customStorageKey = null
214
+ this._publishTimer = null
212
215
  options = Object.assign({
213
216
  name: null,
214
217
  console: false, // 是否控制台打印
@@ -245,6 +248,22 @@ export default class Log {
245
248
  return task
246
249
  }
247
250
 
251
+ _clearPublishTimer () {
252
+ if (!this._publishTimer) {
253
+ return
254
+ }
255
+ clearTimeout(this._publishTimer)
256
+ this._publishTimer = null
257
+ }
258
+
259
+ _schedulePublish () {
260
+ this._clearPublishTimer()
261
+ this._publishTimer = setTimeout(() => {
262
+ this._publishTimer = null
263
+ this.publishLogData().catch(() => {})
264
+ }, AUTO_PUBLISH_DELAY)
265
+ }
266
+
248
267
  _closeIndexedDb () {
249
268
  const indexedDbPromise = this._indexedDbPromise
250
269
  this._indexedDbPromise = null
@@ -453,7 +472,7 @@ export default class Log {
453
472
  }
454
473
 
455
474
  checkAndSync () {
456
- if (!this.useIndexedDb) {
475
+ if (!this.useIndexedDb || this._syncCompleted) {
457
476
  return Promise.resolve({
458
477
  synced: false,
459
478
  migratedCount: 0,
@@ -481,9 +500,11 @@ export default class Log {
481
500
  })
482
501
  this._syncPromise = task.then(result => {
483
502
  this._syncPromise = null
503
+ this._syncCompleted = true
484
504
  return result
485
505
  }, () => {
486
506
  this._syncPromise = null
507
+ this._syncCompleted = true
487
508
  return {
488
509
  synced: false,
489
510
  migratedCount: 0,
@@ -512,6 +533,7 @@ export default class Log {
512
533
  data.size = JSON.stringify(data).length
513
534
  this.tempStore.push(data)
514
535
  this.checkAndSync().catch(() => {})
536
+ this._schedulePublish()
515
537
  if (this.tempStore.length > 5) {
516
538
  this.publishLogData().then(null, err => {
517
539
  console.log(err)
@@ -527,6 +549,7 @@ export default class Log {
527
549
  * 清空本地日志
528
550
  */
529
551
  clearLogData () {
552
+ this._clearPublishTimer()
530
553
  this.tempStore = []
531
554
  const task = this._enqueueWrite(() => {
532
555
  if (!this.useIndexedDb) {
@@ -571,6 +594,7 @@ export default class Log {
571
594
  }
572
595
 
573
596
  publishLogData () {
597
+ this._clearPublishTimer()
574
598
  return this.checkAndSync().then(() => {
575
599
  return this._enqueueWrite(() => {
576
600
  if (!this.tempStore.length) {