@aochuang/client-sdk 1.0.349 → 1.0.350
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
|
@@ -412,56 +412,53 @@ export default class ClientChatSession {
|
|
|
412
412
|
}) === false) {
|
|
413
413
|
return
|
|
414
414
|
}
|
|
415
|
-
|
|
415
|
+
if (wechatAccountId && wechatAccountId !== ALL_WECHAT_ACCOUNT_ID && data.wechatAccountId !== wechatAccountId) {
|
|
416
|
+
throw new Error('会话的wechatAccount和加载分组的wechatAccountId不一致')
|
|
417
|
+
}
|
|
418
|
+
let nextData = null
|
|
419
|
+
let isRefreshAll = false
|
|
420
|
+
let groupIds = []
|
|
416
421
|
// 如果会话已经存在,那么取已经存在的,以后有需要可以用data更新已经存在的会话,保持引用关系
|
|
422
|
+
// 一般比较容易出现,例如all的时候,分配的时候有可能会出现,例如以前的会话没有正确删除,后面有分配过来了
|
|
417
423
|
if (this.sessionMap[data.conversationId]) {
|
|
424
|
+
// 如果会话比较老,就不更新属性
|
|
425
|
+
if (this.sessionMap[data.conversationId].lastMsgTime && data.lastMsgTime && this.sessionMap[data.conversationId].lastMsgTime <= data.lastMsgTime) {
|
|
426
|
+
// 先删后插
|
|
427
|
+
this._removeSessionBySessionGroup(this.sessionMap[data.conversationId].conversationId)
|
|
428
|
+
// 更新属性
|
|
429
|
+
Object.keys(data).forEach(k => {
|
|
430
|
+
Vue.set(this.sessionMap[data.conversationId], k, data[k])
|
|
431
|
+
})
|
|
432
|
+
}
|
|
418
433
|
nextData = this.sessionMap[data.conversationId]
|
|
434
|
+
isRefreshAll = true
|
|
419
435
|
} else {
|
|
420
|
-
|
|
436
|
+
nextData = data
|
|
421
437
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
throw new Error('会话的wechatAccount和加载分组的wechatAccountId不一致')
|
|
438
|
+
if (!nextData) {
|
|
439
|
+
return
|
|
425
440
|
}
|
|
426
|
-
const groupIds = []
|
|
427
|
-
// 传了wechatAccountId,是分页加载的,这里要保持分页加载数据的链路不受动态加载的影响
|
|
428
441
|
if (wechatAccountId) {
|
|
429
|
-
|
|
430
|
-
//
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
if (!this._lastUpdateSessionMap[groupId]) {
|
|
442
|
-
this._lastUpdateSessionMap[groupId] = {}
|
|
443
|
-
}
|
|
444
|
-
if (!this._lastUpdateSessionMap[groupId][lastField]) {
|
|
445
|
-
this._lastUpdateSessionMap[groupId][lastField] = {}
|
|
446
|
-
}
|
|
447
|
-
if (!this._lastUpdateSessionMap[groupId][lastField][topField]) {
|
|
448
|
-
this._lastUpdateSessionMap[groupId][lastField][topField] = {}
|
|
449
|
-
}
|
|
450
|
-
if (!this._lastUpdateSessionMap[groupId][lastField][topField][lastUpdateSortFields.day]) {
|
|
451
|
-
this._lastUpdateSessionMap[groupId][lastField][topField][lastUpdateSortFields.day] = {}
|
|
452
|
-
}
|
|
453
|
-
if (!this._lastUpdateSessionMap[groupId][lastField][topField][lastUpdateSortFields.day][lastUpdateSortFields.milliseconds]) {
|
|
454
|
-
this._lastUpdateSessionMap[groupId][lastField][topField][lastUpdateSortFields.day][lastUpdateSortFields.milliseconds] = []
|
|
455
|
-
}
|
|
456
|
-
this._lastUpdateSessionMap[groupId][lastField][topField][lastUpdateSortFields.day][lastUpdateSortFields.milliseconds].push(nextData)
|
|
457
|
-
})
|
|
458
|
-
})
|
|
442
|
+
// 传了wechatAccountId,是分页加载的,这里要保持分页加载数据的链路不受动态加载的影响
|
|
443
|
+
// 加载会话是新的在上面,老的在下面,所以一定要记录好上次分页加载的时间点
|
|
444
|
+
if (isRefreshAll) {
|
|
445
|
+
groupIds.push(nextData.wechatAccountId)
|
|
446
|
+
groupIds.push(ALL_WECHAT_ACCOUNT_ID)
|
|
447
|
+
} else {
|
|
448
|
+
groupIds.push(wechatAccountId)
|
|
449
|
+
}
|
|
450
|
+
// 先把老的删除掉
|
|
451
|
+
this._removeLastUpdateSessionMap(nextData.conversationId, wechatAccountId)
|
|
452
|
+
// 再插入新的
|
|
453
|
+
this._updateLastUpdateSessionMap([wechatAccountId], nextData)
|
|
459
454
|
} else {
|
|
460
455
|
groupIds.push(nextData.wechatAccountId)
|
|
461
456
|
groupIds.push(ALL_WECHAT_ACCOUNT_ID)
|
|
462
457
|
}
|
|
458
|
+
this.sessionMap[data.conversationId] = nextData
|
|
463
459
|
// 分组的
|
|
464
460
|
const sortFields = this.getSortField(nextData.lastMsgTime)
|
|
461
|
+
const topField = nextData.stickyOnTop ? 0 : 1 // 置顶
|
|
465
462
|
groupIds.forEach(groupId => {
|
|
466
463
|
// 如果已经在分组里面了,就不新增了,
|
|
467
464
|
if (this._getSessionBySessionGroup(nextData.conversationId, groupId)) {
|
|
@@ -492,6 +489,10 @@ export default class ClientChatSession {
|
|
|
492
489
|
Vue.set(this.data.sessionMuteMap, nextData.wechatAccountId, {})
|
|
493
490
|
}
|
|
494
491
|
Vue.set(this.data.sessionMuteMap[nextData.wechatAccountId], nextData.conversationId, nextData)
|
|
492
|
+
} else {
|
|
493
|
+
if (this.data.sessionMuteMap[nextData.wechatAccountId]) {
|
|
494
|
+
Vue.delete(this.data.sessionMuteMap[nextData.wechatAccountId], nextData.conversationId)
|
|
495
|
+
}
|
|
495
496
|
}
|
|
496
497
|
// 检测一下是不是存在一样的虚拟会话,存在的话就删除
|
|
497
498
|
const virtualSessionIndex = this.data.virtualSessionData.findIndex(v => v.conversationId === nextData.conversationId)
|
|
@@ -499,14 +500,53 @@ export default class ClientChatSession {
|
|
|
499
500
|
this.data.virtualSessionData.splice(virtualSessionIndex, 1)
|
|
500
501
|
}
|
|
501
502
|
callback && callback({
|
|
502
|
-
session:
|
|
503
|
+
session: nextData
|
|
503
504
|
})
|
|
504
505
|
this.onAddSession && this.onAddSession({
|
|
505
|
-
session:
|
|
506
|
+
session: nextData
|
|
506
507
|
})
|
|
507
508
|
}
|
|
508
|
-
|
|
509
|
-
|
|
509
|
+
|
|
510
|
+
_updateLastUpdateSessionMap (groupIds, nextData) {
|
|
511
|
+
if (!groupIds || !groupIds.length || !nextData) {
|
|
512
|
+
return
|
|
513
|
+
}
|
|
514
|
+
// 传了wechatAccountId才记录lastMsgTime
|
|
515
|
+
const lastFields = ['lastMsgTime']
|
|
516
|
+
const topField = nextData.stickyOnTop ? 0 : 1 // 置顶
|
|
517
|
+
groupIds.forEach(groupId => {
|
|
518
|
+
lastFields.forEach(lastField => {
|
|
519
|
+
const lastUpdateSortFields = this.getSortField(nextData[lastField])
|
|
520
|
+
if (!lastUpdateSortFields) {
|
|
521
|
+
return
|
|
522
|
+
}
|
|
523
|
+
if (!this._lastUpdateSessionMap) {
|
|
524
|
+
this._lastUpdateSessionMap = {}
|
|
525
|
+
}
|
|
526
|
+
if (!this._lastUpdateSessionMap[groupId]) {
|
|
527
|
+
this._lastUpdateSessionMap[groupId] = {}
|
|
528
|
+
}
|
|
529
|
+
if (!this._lastUpdateSessionMap[groupId][lastField]) {
|
|
530
|
+
this._lastUpdateSessionMap[groupId][lastField] = {}
|
|
531
|
+
}
|
|
532
|
+
if (!this._lastUpdateSessionMap[groupId][lastField][topField]) {
|
|
533
|
+
this._lastUpdateSessionMap[groupId][lastField][topField] = {}
|
|
534
|
+
}
|
|
535
|
+
if (!this._lastUpdateSessionMap[groupId][lastField][topField][lastUpdateSortFields.day]) {
|
|
536
|
+
this._lastUpdateSessionMap[groupId][lastField][topField][lastUpdateSortFields.day] = {}
|
|
537
|
+
}
|
|
538
|
+
if (!this._lastUpdateSessionMap[groupId][lastField][topField][lastUpdateSortFields.day][lastUpdateSortFields.milliseconds]) {
|
|
539
|
+
this._lastUpdateSessionMap[groupId][lastField][topField][lastUpdateSortFields.day][lastUpdateSortFields.milliseconds] = []
|
|
540
|
+
}
|
|
541
|
+
this._lastUpdateSessionMap[groupId][lastField][topField][lastUpdateSortFields.day][lastUpdateSortFields.milliseconds].push({
|
|
542
|
+
conversationId: nextData.conversationId,
|
|
543
|
+
lastMsgTime: nextData.lastMsgTime
|
|
544
|
+
})
|
|
545
|
+
})
|
|
546
|
+
})
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
_removeSessionBySessionGroup (conversationId, wechatAccountId) {
|
|
510
550
|
if (!this.sessionMap[conversationId]) {
|
|
511
551
|
return
|
|
512
552
|
}
|
|
@@ -515,7 +555,7 @@ export default class ClientChatSession {
|
|
|
515
555
|
return
|
|
516
556
|
}
|
|
517
557
|
const topField = session.stickyOnTop ? 0 : 1 // 置顶
|
|
518
|
-
const groupIds = [session.wechatAccountId, ALL_WECHAT_ACCOUNT_ID]
|
|
558
|
+
const groupIds = wechatAccountId ? [wechatAccountId] : [session.wechatAccountId, ALL_WECHAT_ACCOUNT_ID]
|
|
519
559
|
const sortFields = this.getSortField(session.lastMsgTime)
|
|
520
560
|
groupIds.forEach(groupId => {
|
|
521
561
|
if (!this.data.sessionGroupData[groupId] || !this.data.sessionGroupData[groupId][topField]) {
|
|
@@ -523,7 +563,7 @@ export default class ClientChatSession {
|
|
|
523
563
|
}
|
|
524
564
|
const groupSession = this.data.sessionGroupData[groupId][topField]
|
|
525
565
|
if (groupSession[sortFields.day] && groupSession[sortFields.day][sortFields.milliseconds]) {
|
|
526
|
-
const groupIndex = groupSession[sortFields.day][sortFields.milliseconds].indexOf(
|
|
566
|
+
const groupIndex = groupSession[sortFields.day][sortFields.milliseconds].indexOf(session)
|
|
527
567
|
if (groupIndex >= 0) {
|
|
528
568
|
groupSession[sortFields.day][sortFields.milliseconds].splice(groupIndex, 1)
|
|
529
569
|
}
|
|
@@ -541,10 +581,19 @@ export default class ClientChatSession {
|
|
|
541
581
|
}
|
|
542
582
|
}
|
|
543
583
|
})
|
|
544
|
-
|
|
545
|
-
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
_removeLastUpdateSessionMap (conversationId, wechatAccountId) {
|
|
587
|
+
if (!this.sessionMap[conversationId]) {
|
|
588
|
+
return
|
|
589
|
+
}
|
|
590
|
+
const session = this.sessionMap[conversationId]
|
|
591
|
+
if (!session) {
|
|
592
|
+
return
|
|
546
593
|
}
|
|
547
|
-
|
|
594
|
+
let isDeleted = false
|
|
595
|
+
const lastFields = ['lastMsgTime']
|
|
596
|
+
const groupIds = wechatAccountId ? [wechatAccountId] : [session.wechatAccountId, ALL_WECHAT_ACCOUNT_ID]
|
|
548
597
|
groupIds.forEach(groupId => {
|
|
549
598
|
if (!this._lastUpdateSessionMap || !this._lastUpdateSessionMap[groupId]) {
|
|
550
599
|
return
|
|
@@ -553,26 +602,93 @@ export default class ClientChatSession {
|
|
|
553
602
|
if (!this._lastUpdateSessionMap[groupId][lastField]) {
|
|
554
603
|
return
|
|
555
604
|
}
|
|
605
|
+
const loastUpdateSortFields = this.getSortField(session[lastField])
|
|
556
606
|
Object.keys(this._lastUpdateSessionMap[groupId][lastField]).forEach(topField => {
|
|
557
607
|
if (!this._lastUpdateSessionMap[groupId][lastField][topField]) {
|
|
558
608
|
return
|
|
559
609
|
}
|
|
560
|
-
const loastUpdateSortFields = this.getSortField(session.lastUpdateTime)
|
|
561
610
|
if (this._lastUpdateSessionMap[groupId][lastField][topField][loastUpdateSortFields.day] && this._lastUpdateSessionMap[groupId][lastField][topField][loastUpdateSortFields.day][loastUpdateSortFields.milliseconds]) {
|
|
562
|
-
|
|
611
|
+
let index = -1
|
|
612
|
+
this._lastUpdateSessionMap[groupId][lastField][topField][loastUpdateSortFields.day][loastUpdateSortFields.milliseconds].some((v, i) => {
|
|
613
|
+
if (v.conversationId === session.conversationId) {
|
|
614
|
+
index = i
|
|
615
|
+
return true
|
|
616
|
+
}
|
|
617
|
+
})
|
|
563
618
|
if (index >= 0) {
|
|
564
619
|
this._lastUpdateSessionMap[groupId][lastField][topField][loastUpdateSortFields.day][loastUpdateSortFields.milliseconds].splice(index, 1)
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
620
|
+
if (!this._lastUpdateSessionMap[groupId][lastField][topField][loastUpdateSortFields.day][loastUpdateSortFields.milliseconds].length) {
|
|
621
|
+
Vue.delete(this._lastUpdateSessionMap[groupId][lastField][topField][loastUpdateSortFields.day], loastUpdateSortFields.milliseconds)
|
|
622
|
+
}
|
|
623
|
+
if (isEmptyObject(this._lastUpdateSessionMap[groupId][lastField][topField][loastUpdateSortFields.day])) {
|
|
624
|
+
Vue.delete(this._lastUpdateSessionMap[groupId][lastField][topField], loastUpdateSortFields.day)
|
|
625
|
+
}
|
|
626
|
+
isDeleted = true
|
|
571
627
|
}
|
|
572
628
|
}
|
|
573
629
|
})
|
|
574
630
|
})
|
|
575
631
|
})
|
|
632
|
+
if (!isDeleted) {
|
|
633
|
+
groupIds.some(groupId => {
|
|
634
|
+
if (!this._lastUpdateSessionMap || !this._lastUpdateSessionMap[groupId]) {
|
|
635
|
+
return
|
|
636
|
+
}
|
|
637
|
+
return lastFields.some(lastField => {
|
|
638
|
+
if (!this._lastUpdateSessionMap[groupId][lastField]) {
|
|
639
|
+
return
|
|
640
|
+
}
|
|
641
|
+
return Object.keys(this._lastUpdateSessionMap[groupId][lastField]).some(topField => {
|
|
642
|
+
if (!this._lastUpdateSessionMap[groupId][lastField][topField]) {
|
|
643
|
+
return
|
|
644
|
+
}
|
|
645
|
+
return Object.keys(this._lastUpdateSessionMap[groupId][lastField][topField]).some(day => {
|
|
646
|
+
if (!this._lastUpdateSessionMap[groupId][lastField][topField][day]) {
|
|
647
|
+
return
|
|
648
|
+
}
|
|
649
|
+
return Object.keys(this._lastUpdateSessionMap[groupId][lastField][topField][day]).some(milliseconds => {
|
|
650
|
+
if (!this._lastUpdateSessionMap[groupId][lastField][topField][day][milliseconds]) {
|
|
651
|
+
return
|
|
652
|
+
}
|
|
653
|
+
let index = -1
|
|
654
|
+
this._lastUpdateSessionMap[groupId][lastField][topField][day][milliseconds].some((v, i) => {
|
|
655
|
+
if (v.conversationId === session.conversationId) {
|
|
656
|
+
index = i
|
|
657
|
+
return true
|
|
658
|
+
}
|
|
659
|
+
})
|
|
660
|
+
if (index >= 0) {
|
|
661
|
+
this._lastUpdateSessionMap[groupId][lastField][topField][day][milliseconds].splice(index, 1)
|
|
662
|
+
if (!this._lastUpdateSessionMap[groupId][lastField][topField][day][milliseconds].length) {
|
|
663
|
+
Vue.delete(this._lastUpdateSessionMap[groupId][lastField][topField][day], milliseconds)
|
|
664
|
+
}
|
|
665
|
+
if (isEmptyObject(this._lastUpdateSessionMap[groupId][lastField][topField][day])) {
|
|
666
|
+
Vue.delete(this._lastUpdateSessionMap[groupId][lastField][topField], day)
|
|
667
|
+
}
|
|
668
|
+
isDeleted = true
|
|
669
|
+
return true
|
|
670
|
+
}
|
|
671
|
+
})
|
|
672
|
+
})
|
|
673
|
+
})
|
|
674
|
+
})
|
|
675
|
+
})
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
removeSession (conversationId) {
|
|
680
|
+
if (!this.sessionMap[conversationId]) {
|
|
681
|
+
return
|
|
682
|
+
}
|
|
683
|
+
const session = this.sessionMap[conversationId]
|
|
684
|
+
if (!session) {
|
|
685
|
+
return
|
|
686
|
+
}
|
|
687
|
+
this._removeSessionBySessionGroup(conversationId)
|
|
688
|
+
this._removeLastUpdateSessionMap(conversationId)
|
|
689
|
+
if (this.data.sessionMuteMap[session.wechatAccountId]) {
|
|
690
|
+
delete this.data.sessionMuteMap[session.wechatAccountId][conversationId]
|
|
691
|
+
}
|
|
576
692
|
delete this.sessionMap[conversationId]
|
|
577
693
|
this.onRemoveSession && this.onRemoveSession({
|
|
578
694
|
session
|