@aochuang/client-sdk 1.0.321 → 1.0.323
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 +1 -1
- package/services/client-chat/client-chat-wechat/client-chat-concats.js +39 -34
- package/services/client-chat/client-chat-wechat/client-chat-message.js +8 -3
- package/services/client-chat/client-chat-wechat/client-chat.js +3 -32
- package/services/client-chat/client-chat-wechat/utils.js +38 -0
package/package.json
CHANGED
|
@@ -150,10 +150,6 @@ export default class ClientChatContacts {
|
|
|
150
150
|
friendMap = {}
|
|
151
151
|
|
|
152
152
|
roomMap = {}
|
|
153
|
-
|
|
154
|
-
_cacheFriendGroupCountMap = {}
|
|
155
|
-
|
|
156
|
-
_cacheRoomGroupCountMap = {}
|
|
157
153
|
|
|
158
154
|
loadContactsRoomGroupDataMethod = null
|
|
159
155
|
|
|
@@ -730,6 +726,19 @@ export default class ClientChatContacts {
|
|
|
730
726
|
this.onLoadFriendGroupData && this.onLoadFriendGroupData()
|
|
731
727
|
return rs
|
|
732
728
|
})
|
|
729
|
+
if (!this.data.cacheFriendGroupCountMap) {
|
|
730
|
+
this.data.cacheFriendGroupCountMap = Vue.observable({})
|
|
731
|
+
}
|
|
732
|
+
Vue.set(this.data.cacheFriendGroupCountMap, 'all', this._cacheLoadFriendGroupPromise.then(rs => {
|
|
733
|
+
return {
|
|
734
|
+
data: (rs.data || []).map(v => {
|
|
735
|
+
return {
|
|
736
|
+
id: v.id,
|
|
737
|
+
num: v.num
|
|
738
|
+
}
|
|
739
|
+
})
|
|
740
|
+
}
|
|
741
|
+
}))
|
|
733
742
|
return this._cacheLoadFriendGroupPromise
|
|
734
743
|
}
|
|
735
744
|
|
|
@@ -750,27 +759,24 @@ export default class ClientChatContacts {
|
|
|
750
759
|
}, params)
|
|
751
760
|
const cacheKey = wechatAccountId || 'all'
|
|
752
761
|
if (!this.data.cacheFriendGroupCountMap) {
|
|
753
|
-
this.data.cacheFriendGroupCountMap = {}
|
|
762
|
+
this.data.cacheFriendGroupCountMap = Vue.observable({})
|
|
754
763
|
}
|
|
755
|
-
if (!this.
|
|
756
|
-
this._cacheFriendGroupCountMap = {}
|
|
757
|
-
}
|
|
758
|
-
if (!this._cacheFriendGroupCountMap[cacheKey]) {
|
|
764
|
+
if (!this.data.cacheFriendGroupCountMap[cacheKey]) {
|
|
759
765
|
const groupIds = (this.data.friendGroupData || []).map(v => v.id)
|
|
760
766
|
groupIds.forEach(id => {
|
|
761
767
|
Vue.set(this.data.refreshFriendGroupCountLoadingMap, id, true)
|
|
762
768
|
})
|
|
763
|
-
Vue.set(this.data.cacheFriendGroupCountMap, cacheKey,
|
|
764
|
-
this._cacheFriendGroupCountMap[cacheKey] = this.getContactsFriendGroupCountMethod(Object.assign({}, nextParams, {
|
|
769
|
+
Vue.set(this.data.cacheFriendGroupCountMap, cacheKey, this.getContactsFriendGroupCountMethod(Object.assign({}, nextParams, {
|
|
765
770
|
wechatAccountIds: wechatAccountId ? [wechatAccountId] : null,
|
|
766
771
|
groupIds
|
|
767
772
|
})).finally(() => {
|
|
768
773
|
groupIds.forEach(id => {
|
|
769
774
|
Vue.set(this.data.refreshFriendGroupCountLoadingMap, id, false)
|
|
770
775
|
})
|
|
771
|
-
})
|
|
776
|
+
}))
|
|
777
|
+
|
|
772
778
|
}
|
|
773
|
-
this.
|
|
779
|
+
this.data.cacheFriendGroupCountMap[cacheKey].then(rs => {
|
|
774
780
|
if (!rs || !rs.data || !rs.data.length) {
|
|
775
781
|
return
|
|
776
782
|
}
|
|
@@ -780,7 +786,7 @@ export default class ClientChatContacts {
|
|
|
780
786
|
})
|
|
781
787
|
})
|
|
782
788
|
})
|
|
783
|
-
return this.
|
|
789
|
+
return this.data.cacheFriendGroupCountMap[cacheKey]
|
|
784
790
|
}
|
|
785
791
|
|
|
786
792
|
// 标记所有好友分组修改
|
|
@@ -789,10 +795,6 @@ export default class ClientChatContacts {
|
|
|
789
795
|
if (!this.data.cacheFriendGroupCountMap) {
|
|
790
796
|
return
|
|
791
797
|
}
|
|
792
|
-
if (this._cacheFriendGroupCountMap) {
|
|
793
|
-
delete this._cacheFriendGroupCountMap[wechatAccountId]
|
|
794
|
-
delete this._cacheFriendGroupCountMap.all
|
|
795
|
-
}
|
|
796
798
|
Vue.delete(this.data.cacheFriendGroupCountMap, wechatAccountId)
|
|
797
799
|
Vue.delete(this.data.cacheFriendGroupCountMap, 'all')
|
|
798
800
|
}
|
|
@@ -806,6 +808,19 @@ export default class ClientChatContacts {
|
|
|
806
808
|
this.onLoadRoomGroupData && this.onLoadRoomGroupData()
|
|
807
809
|
return rs
|
|
808
810
|
})
|
|
811
|
+
if (!this.data.cacheRoomGroupCountMap) {
|
|
812
|
+
this.data.cacheRoomGroupCountMap = Vue.observable({})
|
|
813
|
+
}
|
|
814
|
+
Vue.set(this.data.cacheRoomGroupCountMap, 'all', this._cacheLoadRoomGroupPromise.then(rs => {
|
|
815
|
+
return {
|
|
816
|
+
data: (rs.data || []).map(v => {
|
|
817
|
+
return {
|
|
818
|
+
id: v.id,
|
|
819
|
+
num: v.num
|
|
820
|
+
}
|
|
821
|
+
})
|
|
822
|
+
}
|
|
823
|
+
}))
|
|
809
824
|
return this._cacheLoadRoomGroupPromise
|
|
810
825
|
}
|
|
811
826
|
|
|
@@ -821,28 +836,24 @@ export default class ClientChatContacts {
|
|
|
821
836
|
wechatAccountId: null
|
|
822
837
|
}, params)
|
|
823
838
|
if (!this.data.cacheRoomGroupCountMap) {
|
|
824
|
-
this.data.cacheRoomGroupCountMap = {}
|
|
825
|
-
}
|
|
826
|
-
if (!this._cacheRoomGroupCountMap) {
|
|
827
|
-
this._cacheRoomGroupCountMap = {}
|
|
839
|
+
this.data.cacheRoomGroupCountMap = Vue.observable({})
|
|
828
840
|
}
|
|
829
841
|
const cacheKey = wechatAccountId || 'all'
|
|
830
|
-
if (!this.
|
|
842
|
+
if (!this.data.cacheRoomGroupCountMap[cacheKey] || refresh === true) {
|
|
831
843
|
const groupIds = (this.data.roomGroupData || []).map(v => v.id)
|
|
832
844
|
groupIds.forEach(id => {
|
|
833
845
|
Vue.set(this.data.refreshRoomGroupCountLoadingMap, id, true)
|
|
834
846
|
})
|
|
835
|
-
Vue.set(this.data.cacheRoomGroupCountMap, cacheKey,
|
|
836
|
-
this._cacheRoomGroupCountMap[cacheKey] = this.getContactsRoomGroupCountMethod(Object.assign({}, nextParams, {
|
|
847
|
+
Vue.set(this.data.cacheRoomGroupCountMap, cacheKey, this.getContactsRoomGroupCountMethod(Object.assign({}, nextParams, {
|
|
837
848
|
wechatAccountIds: wechatAccountId ? [wechatAccountId] : null,
|
|
838
849
|
groupIds
|
|
839
850
|
})).finally(() => {
|
|
840
851
|
groupIds.forEach(id => {
|
|
841
852
|
Vue.set(this.data.refreshRoomGroupCountLoadingMap, id, false)
|
|
842
853
|
})
|
|
843
|
-
})
|
|
854
|
+
}))
|
|
844
855
|
}
|
|
845
|
-
this.
|
|
856
|
+
this.data.cacheRoomGroupCountMap[cacheKey].then(rs => {
|
|
846
857
|
if (!rs || !rs.data || !rs.data.length) {
|
|
847
858
|
return
|
|
848
859
|
}
|
|
@@ -852,17 +863,13 @@ export default class ClientChatContacts {
|
|
|
852
863
|
})
|
|
853
864
|
})
|
|
854
865
|
})
|
|
855
|
-
return this.
|
|
866
|
+
return this.data.cacheRoomGroupCountMap[cacheKey]
|
|
856
867
|
}
|
|
857
868
|
|
|
858
869
|
clearAllRoomGroupCountCache (wechatAccountId) {
|
|
859
870
|
if (!this.data.cacheRoomGroupCountMap) {
|
|
860
871
|
return
|
|
861
872
|
}
|
|
862
|
-
if (this._cacheRoomGroupCountMap) {
|
|
863
|
-
delete this._cacheRoomGroupCountMap[wechatAccountId]
|
|
864
|
-
delete this._cacheRoomGroupCountMap.all
|
|
865
|
-
}
|
|
866
873
|
Vue.delete(this.data.cacheRoomGroupCountMap, wechatAccountId)
|
|
867
874
|
Vue.delete(this.data.cacheRoomGroupCountMap, 'all')
|
|
868
875
|
}
|
|
@@ -1090,8 +1097,6 @@ export default class ClientChatContacts {
|
|
|
1090
1097
|
this.data.refreshFriendGroupCountLoadingMap = {}
|
|
1091
1098
|
this.data.cacheFriendGroupCountMap = null
|
|
1092
1099
|
this.data.cacheRoomGroupCountMap = null
|
|
1093
|
-
this._cacheFriendGroupCountMap = null
|
|
1094
|
-
this._cacheRoomGroupCountMap = null
|
|
1095
1100
|
if (this.cancelConnectRequest) {
|
|
1096
1101
|
this.cancelConnectRequest()
|
|
1097
1102
|
this.cancelConnectRequest = null
|
|
@@ -3,6 +3,7 @@ import Event from '../../../utils/event.js'
|
|
|
3
3
|
import { unique } from '../../../utils/string.js'
|
|
4
4
|
import { formatDate } from '../../../utils/date.js'
|
|
5
5
|
import { createPromise } from '../../../utils/util'
|
|
6
|
+
import { isAutoReadMessage, shouldIgnoreSessionByMessage, isDeletedMsg, isBlockedMsg } from './utils.js'
|
|
6
7
|
import { encodeHtmlEntities } from '@aochuang/common/utils/string.js'
|
|
7
8
|
|
|
8
9
|
export default class ClientChatMessage {
|
|
@@ -140,9 +141,13 @@ export default class ClientChatMessage {
|
|
|
140
141
|
}
|
|
141
142
|
}
|
|
142
143
|
if (fireEvent !== false) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
144
|
+
// 如果消息包含这种情况,就不能往外发送add-message事件
|
|
145
|
+
// 因为例如群发的消息,他没有会话,导致前端在处理来了新消息通知铃声提醒,获取会话一直获取不到,然后会总是发送请求
|
|
146
|
+
if (!isAutoReadMessage(data) && !shouldIgnoreSessionByMessage(data) && !isDeletedMsg(data) && !isBlockedMsg(data)) {
|
|
147
|
+
this.event && this.event.emit('add-message', {
|
|
148
|
+
data
|
|
149
|
+
})
|
|
150
|
+
}
|
|
146
151
|
this.onAddMessageSuccess && this.onAddMessageSuccess({
|
|
147
152
|
data
|
|
148
153
|
})
|
|
@@ -9,6 +9,7 @@ import { createSessionId } from '../../../utils/string.js'
|
|
|
9
9
|
import Event from '../../../utils/event.js'
|
|
10
10
|
import { createSerialQueue } from '../../../utils/queue'
|
|
11
11
|
import ClientChatSessionManage from './client-chat-session-manage.js'
|
|
12
|
+
import { shouldIgnoreSessionByMessage, isAutoReadMessage, isDeletedMsg, isBlockedMsg } from './utils.js'
|
|
12
13
|
|
|
13
14
|
const CONNECT_STATUS = {
|
|
14
15
|
Normal: 'normal',
|
|
@@ -16,36 +17,6 @@ const CONNECT_STATUS = {
|
|
|
16
17
|
Complete: 'complete'
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
function shouldIgnoreSessionByMessage (data) {
|
|
20
|
-
// 群发消息的不处理会话
|
|
21
|
-
// public enum MsgSubTypeEnum {
|
|
22
|
-
// /*0:普通的聊天*/
|
|
23
|
-
// COMMON,
|
|
24
|
-
// /*1:分配记录消息*/
|
|
25
|
-
// ALLOT_MSG,
|
|
26
|
-
// /*2:批量发送*/
|
|
27
|
-
// BATCH_SEND,
|
|
28
|
-
// /*3:通过好友恢复*/
|
|
29
|
-
// ACCEPT_REPLY,
|
|
30
|
-
// /*4:自动回复*/
|
|
31
|
-
// AUTO_REPLY,
|
|
32
|
-
// // 5:入群欢迎语
|
|
33
|
-
// CHATROOM_WELCOME,
|
|
34
|
-
// //6:指定时间段内自动回复消息
|
|
35
|
-
// AUTO_REPLY_INTIME,
|
|
36
|
-
// //7:群自动回复
|
|
37
|
-
// CHATROOM_REPLY
|
|
38
|
-
// }
|
|
39
|
-
if (data.msgSubType === 2) {
|
|
40
|
-
return true
|
|
41
|
-
}
|
|
42
|
-
return data && data.msgType === 10000 && data.content && ['消息已发出,但被对方拒收了', '请先发送朋友验证请求,对方验证通过后,才能聊天'].some(v => data.content.indexOf(v) >= 0)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function isAutoReadMessage (data) {
|
|
46
|
-
return !!(data && data.id && data.id.indexOf('AUTO-READ-') === 0)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
20
|
function getAtMessageContent (data) {
|
|
50
21
|
if (!data || data.isSend || !data.content) {
|
|
51
22
|
return null
|
|
@@ -419,7 +390,7 @@ class ClientChat {
|
|
|
419
390
|
return this.handleAutoReadMessageSession(sessionId)
|
|
420
391
|
}
|
|
421
392
|
// 如果消息包含这种情况,就不加入会话列表
|
|
422
|
-
if (shouldIgnoreSessionByMessage(data)) {
|
|
393
|
+
if (shouldIgnoreSessionByMessage(data) || isDeletedMsg(data) || isBlockedMsg(data)) {
|
|
423
394
|
return
|
|
424
395
|
}
|
|
425
396
|
const localSession = this.session.findSession(({ session }) => session.conversationId === sessionId)
|
|
@@ -554,7 +525,7 @@ class ClientChat {
|
|
|
554
525
|
return this.handleAutoReadMessageSession(sessionId)
|
|
555
526
|
}
|
|
556
527
|
// 如果消息包含这种情况,就不加入会话列表
|
|
557
|
-
if (shouldIgnoreSessionByMessage(data)) {
|
|
528
|
+
if (shouldIgnoreSessionByMessage(data) || isDeletedMsg(data) || isBlockedMsg(data)) {
|
|
558
529
|
return
|
|
559
530
|
}
|
|
560
531
|
// 更新会话未读消息数量
|
|
@@ -20,6 +20,44 @@ export function createSessionId (accountId, targetId) {
|
|
|
20
20
|
return shajs('sha1').update(`${accountId}${targetId}`).digest('hex')
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
export function isDeletedMsg (data) {
|
|
24
|
+
return data && data.deletedMsg === true
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function isBlockedMsg (data) {
|
|
28
|
+
return data && data.blockedMsg === true
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function shouldIgnoreSessionByMessage (data) {
|
|
32
|
+
// 群发消息的不处理会话
|
|
33
|
+
// public enum MsgSubTypeEnum {
|
|
34
|
+
// /*0:普通的聊天*/
|
|
35
|
+
// COMMON,
|
|
36
|
+
// /*1:分配记录消息*/
|
|
37
|
+
// ALLOT_MSG,
|
|
38
|
+
// /*2:批量发送*/
|
|
39
|
+
// BATCH_SEND,
|
|
40
|
+
// /*3:通过好友恢复*/
|
|
41
|
+
// ACCEPT_REPLY,
|
|
42
|
+
// /*4:自动回复*/
|
|
43
|
+
// AUTO_REPLY,
|
|
44
|
+
// // 5:入群欢迎语
|
|
45
|
+
// CHATROOM_WELCOME,
|
|
46
|
+
// //6:指定时间段内自动回复消息
|
|
47
|
+
// AUTO_REPLY_INTIME,
|
|
48
|
+
// //7:群自动回复
|
|
49
|
+
// CHATROOM_REPLY
|
|
50
|
+
// }
|
|
51
|
+
if (data.msgSubType === 2) {
|
|
52
|
+
return true
|
|
53
|
+
}
|
|
54
|
+
return data && data.msgType === 10000 && data.content && ['消息已发出,但被对方拒收了', '请先发送朋友验证请求,对方验证通过后,才能聊天'].some(v => data.content.indexOf(v) >= 0)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function isAutoReadMessage (data) {
|
|
58
|
+
return !!(data && data.id && data.id.indexOf('AUTO-READ-') === 0)
|
|
59
|
+
}
|
|
60
|
+
|
|
23
61
|
/**
|
|
24
62
|
* 根据消息创建会话
|
|
25
63
|
* 有两种情况,一种是从客户发过来的消息,另一种是客服发送的消息
|