@aochuang/client-sdk 1.0.343 → 1.0.345
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
|
@@ -203,7 +203,7 @@ export default class ClientChatAccount {
|
|
|
203
203
|
|
|
204
204
|
refreshAccountUnreadMessageNum (params) {
|
|
205
205
|
const { wechatAccountId, ...nextParams } = params
|
|
206
|
-
this.getAccountUnreadMessageNumMethod(Object.assign({
|
|
206
|
+
return this.getAccountUnreadMessageNumMethod(Object.assign({
|
|
207
207
|
wechatAccountIds: [wechatAccountId]
|
|
208
208
|
}, nextParams)).then(rs => {
|
|
209
209
|
if (!rs || !rs.data || !rs.data.length) {
|
|
@@ -5,20 +5,39 @@ import { createPollRequest } from '../../../utils/util.js'
|
|
|
5
5
|
|
|
6
6
|
const ALL_WECHAT_ACCOUNT_ID = 'all'
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const ASSIGN_SESSION_LOG_PREFIX = '[client-chat][assign-session]'
|
|
9
|
+
const ASSIGN_SESSION_MERGE_EXCLUDE_FIELDS = [
|
|
10
|
+
'conversationId',
|
|
11
|
+
'wechatAccountId',
|
|
12
|
+
'lastMsgTime',
|
|
13
|
+
'lastUpdateTime',
|
|
14
|
+
'stickyOnTop',
|
|
15
|
+
'mute',
|
|
16
|
+
'lastAtMsgContent'
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
const loopLoadAssignSessionData = (fetchFn, params, onPageLoaded) => {
|
|
9
20
|
let lastPs = null
|
|
10
21
|
let lastRs = null
|
|
11
22
|
let result = []
|
|
23
|
+
let page = 0
|
|
12
24
|
const loopFn = (params, total) => {
|
|
13
25
|
const { taskId, size, ...nextParams } = params
|
|
26
|
+
page += 1
|
|
14
27
|
lastPs = fetchFn(Object.assign({}, nextParams, {
|
|
15
28
|
size,
|
|
16
29
|
taskId,
|
|
17
30
|
total
|
|
18
31
|
}))
|
|
19
32
|
lastRs = lastPs.then(rs => {
|
|
20
|
-
|
|
21
|
-
|
|
33
|
+
const pageData = rs.data || []
|
|
34
|
+
result = result.concat(pageData)
|
|
35
|
+
onPageLoaded && onPageLoaded({
|
|
36
|
+
page,
|
|
37
|
+
pageSize: pageData.length,
|
|
38
|
+
total: result.length
|
|
39
|
+
})
|
|
40
|
+
if (pageData.length < size) {
|
|
22
41
|
return result
|
|
23
42
|
} else {
|
|
24
43
|
return loopFn(params, result.length)
|
|
@@ -188,7 +207,7 @@ export default class ClientChatSession {
|
|
|
188
207
|
* @params { Object } data - 会话数据集合
|
|
189
208
|
* @params { String } wechatAccountId - 如果传wechatAccountId那么后面addSession的时候如果传wechatAccountId那么才会更新lastUpdateTime或者lastMsgTime,本质的意思是只有通过reload和loadData才刷新lastUpdateTime或者lastMsgTime,避免这个时间乱套了
|
|
190
209
|
*/
|
|
191
|
-
setSessionData (data, wechatAccountId, reset = true) {
|
|
210
|
+
setSessionData (data, wechatAccountId, reset = true, context) {
|
|
192
211
|
if (reset) {
|
|
193
212
|
this.sessionMap = {}
|
|
194
213
|
this.data.sessionGroupData = {}
|
|
@@ -200,7 +219,7 @@ export default class ClientChatSession {
|
|
|
200
219
|
if (item.isDeleted) {
|
|
201
220
|
this.removeSession(item.conversationId)
|
|
202
221
|
} else {
|
|
203
|
-
this.addSession(item, wechatAccountId)
|
|
222
|
+
this.addSession(item, wechatAccountId, context)
|
|
204
223
|
}
|
|
205
224
|
})
|
|
206
225
|
}
|
|
@@ -388,7 +407,7 @@ export default class ClientChatSession {
|
|
|
388
407
|
* "wechatAccountId": "2a39a725814acf07502299ab2285fff8d44377f5"
|
|
389
408
|
* }
|
|
390
409
|
*/
|
|
391
|
-
addSession (data, wechatAccountId) {
|
|
410
|
+
addSession (data, wechatAccountId, context) {
|
|
392
411
|
if (!data || !data.conversationId) {
|
|
393
412
|
throw new Error('缺少必须参数conversationId')
|
|
394
413
|
}
|
|
@@ -404,11 +423,54 @@ export default class ClientChatSession {
|
|
|
404
423
|
return
|
|
405
424
|
}
|
|
406
425
|
let nextData = data
|
|
426
|
+
let assignMergeLog = null
|
|
407
427
|
// 如果会话已经存在,那么取已经存在的,以后有需要可以用data更新已经存在的会话,保持引用关系
|
|
408
428
|
if (this.sessionMap[data.conversationId]) {
|
|
409
429
|
nextData = this.sessionMap[data.conversationId]
|
|
430
|
+
const unreadBefore = nextData.unreadMsgCount || 0
|
|
431
|
+
const muteBefore = !!nextData.mute
|
|
432
|
+
const changedFields = []
|
|
433
|
+
Object.keys(data).forEach(key => {
|
|
434
|
+
if (ASSIGN_SESSION_MERGE_EXCLUDE_FIELDS.indexOf(key) >= 0 || nextData[key] === data[key]) {
|
|
435
|
+
return
|
|
436
|
+
}
|
|
437
|
+
changedFields.push(key)
|
|
438
|
+
Vue.set(nextData, key, data[key])
|
|
439
|
+
})
|
|
440
|
+
if (context && context.source === 'assign-task') {
|
|
441
|
+
assignMergeLog = {
|
|
442
|
+
taskId: context.taskId,
|
|
443
|
+
conversationId: data.conversationId,
|
|
444
|
+
wechatAccountId: data.wechatAccountId,
|
|
445
|
+
existed: true,
|
|
446
|
+
changedFields,
|
|
447
|
+
unreadBefore,
|
|
448
|
+
unreadFromServer: data.unreadMsgCount || 0,
|
|
449
|
+
unreadAfter: nextData.unreadMsgCount || 0,
|
|
450
|
+
muteBefore,
|
|
451
|
+
muteFromServer: !!data.mute,
|
|
452
|
+
muteAfter: !!nextData.mute,
|
|
453
|
+
preservedFields: ASSIGN_SESSION_MERGE_EXCLUDE_FIELDS.slice()
|
|
454
|
+
}
|
|
455
|
+
}
|
|
410
456
|
} else {
|
|
411
457
|
this.sessionMap[data.conversationId] = nextData
|
|
458
|
+
if (context && context.source === 'assign-task') {
|
|
459
|
+
assignMergeLog = {
|
|
460
|
+
taskId: context.taskId,
|
|
461
|
+
conversationId: data.conversationId,
|
|
462
|
+
wechatAccountId: data.wechatAccountId,
|
|
463
|
+
existed: false,
|
|
464
|
+
changedFields: [],
|
|
465
|
+
unreadBefore: null,
|
|
466
|
+
unreadFromServer: data.unreadMsgCount || 0,
|
|
467
|
+
unreadAfter: data.unreadMsgCount || 0,
|
|
468
|
+
muteBefore: null,
|
|
469
|
+
muteFromServer: !!data.mute,
|
|
470
|
+
muteAfter: !!data.mute,
|
|
471
|
+
preservedFields: []
|
|
472
|
+
}
|
|
473
|
+
}
|
|
412
474
|
}
|
|
413
475
|
const topField = nextData.stickyOnTop ? 0 : 1 // 置顶
|
|
414
476
|
if (wechatAccountId && wechatAccountId !== ALL_WECHAT_ACCOUNT_ID && nextData.wechatAccountId !== wechatAccountId) {
|
|
@@ -490,8 +552,11 @@ export default class ClientChatSession {
|
|
|
490
552
|
this.data.virtualSessionData.splice(virtualSessionIndex, 1)
|
|
491
553
|
}
|
|
492
554
|
this.onAddSession && this.onAddSession({
|
|
493
|
-
session:
|
|
555
|
+
session: nextData
|
|
494
556
|
})
|
|
557
|
+
if (assignMergeLog) {
|
|
558
|
+
console.info(ASSIGN_SESSION_LOG_PREFIX, 'merge', assignMergeLog)
|
|
559
|
+
}
|
|
495
560
|
}
|
|
496
561
|
|
|
497
562
|
removeSession (conversationId) {
|
|
@@ -625,7 +690,9 @@ export default class ClientChatSession {
|
|
|
625
690
|
return true
|
|
626
691
|
}
|
|
627
692
|
})
|
|
628
|
-
|
|
693
|
+
if (index >= 0) {
|
|
694
|
+
this.data.sessionGroupData[groupId][topField][oldSortFields.day][oldSortFields.milliseconds].splice(index, 1)
|
|
695
|
+
}
|
|
629
696
|
}
|
|
630
697
|
})
|
|
631
698
|
})
|
|
@@ -685,7 +752,9 @@ export default class ClientChatSession {
|
|
|
685
752
|
return true
|
|
686
753
|
}
|
|
687
754
|
})
|
|
688
|
-
|
|
755
|
+
if (index >= 0) {
|
|
756
|
+
this.data.sessionGroupData[groupId][topField][sortFields.day][sortFields.milliseconds].splice(index, 1)
|
|
757
|
+
}
|
|
689
758
|
}
|
|
690
759
|
})
|
|
691
760
|
})
|
|
@@ -830,14 +899,36 @@ export default class ClientChatSession {
|
|
|
830
899
|
total: 0 , // 已获取总数
|
|
831
900
|
size: 50 // 每次获取数量
|
|
832
901
|
}, params)
|
|
902
|
+
const taskId = params.taskId
|
|
903
|
+
console.info(ASSIGN_SESSION_LOG_PREFIX, 'load-start', {
|
|
904
|
+
taskId,
|
|
905
|
+
total: params.total,
|
|
906
|
+
size: params.size
|
|
907
|
+
})
|
|
833
908
|
this.data.loadAssignTaskSessioning = true
|
|
834
909
|
return loopLoadAssignSessionData((nextParams) => {
|
|
835
910
|
return this.loadAssignTaskSessionDataMethod(nextParams)
|
|
836
|
-
}, params
|
|
911
|
+
}, params, pageInfo => {
|
|
912
|
+
console.info(ASSIGN_SESSION_LOG_PREFIX, 'page-loaded', Object.assign({ taskId }, pageInfo))
|
|
913
|
+
}).then(rs => {
|
|
837
914
|
if (rs && rs.length) {
|
|
838
|
-
this.setSessionData(rs, null, false
|
|
915
|
+
this.setSessionData(rs, null, false, {
|
|
916
|
+
source: 'assign-task',
|
|
917
|
+
taskId
|
|
918
|
+
})
|
|
839
919
|
}
|
|
920
|
+
console.info(ASSIGN_SESSION_LOG_PREFIX, 'load-complete', {
|
|
921
|
+
taskId,
|
|
922
|
+
sessionCount: rs ? rs.length : 0,
|
|
923
|
+
wechatAccountIds: Array.from(new Set((rs || []).map(session => session.wechatAccountId)))
|
|
924
|
+
})
|
|
840
925
|
return rs
|
|
926
|
+
}).catch(error => {
|
|
927
|
+
console.error(ASSIGN_SESSION_LOG_PREFIX, 'load-error', {
|
|
928
|
+
taskId,
|
|
929
|
+
message: error && error.message ? error.message : String(error)
|
|
930
|
+
})
|
|
931
|
+
throw error
|
|
841
932
|
}).finally(() => {
|
|
842
933
|
this.data.loadAssignTaskSessioning = false
|
|
843
934
|
})
|
|
@@ -43,6 +43,136 @@ function appendLastAtMsgContent (lastAtMsgContent, atMessage) {
|
|
|
43
43
|
return messages.concat(atMessage)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
const ASSIGN_SESSION_LOG_PREFIX = '[client-chat][assign-session]'
|
|
47
|
+
|
|
48
|
+
function getAccountUnreadSnapshot (account, accountIds) {
|
|
49
|
+
const accountIdMap = accountIds && accountIds.reduce((result, accountId) => {
|
|
50
|
+
result[accountId] = true
|
|
51
|
+
return result
|
|
52
|
+
}, {})
|
|
53
|
+
return (account.accountUnreadMessageNumData || []).filter(item => {
|
|
54
|
+
return !accountIdMap || accountIdMap[item.id]
|
|
55
|
+
}).map(item => ({
|
|
56
|
+
wechatAccountId: item.id,
|
|
57
|
+
unread: item.num || 0,
|
|
58
|
+
muteUnread: item.muteNum || 0
|
|
59
|
+
}))
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function getAssignAccountIds (sessions) {
|
|
63
|
+
return Object.keys((sessions || []).reduce((result, session) => {
|
|
64
|
+
if (session && session.wechatAccountId) {
|
|
65
|
+
result[session.wechatAccountId] = true
|
|
66
|
+
}
|
|
67
|
+
return result
|
|
68
|
+
}, {}))
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function getSessionUnreadSnapshot (sessionInstance) {
|
|
72
|
+
return Object.keys(sessionInstance.sessionMap || {}).reduce((result, conversationId) => {
|
|
73
|
+
const session = sessionInstance.sessionMap[conversationId]
|
|
74
|
+
result[conversationId] = {
|
|
75
|
+
wechatAccountId: session.wechatAccountId,
|
|
76
|
+
unread: session.unreadMsgCount || 0,
|
|
77
|
+
mute: !!session.mute
|
|
78
|
+
}
|
|
79
|
+
return result
|
|
80
|
+
}, {})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function getAssignUnreadChanges (clientChat, sessions, sessionUnreadBefore, accountIdBeforeMap, taskId) {
|
|
84
|
+
const sessionMap = {}
|
|
85
|
+
const sessionData = sessions || []
|
|
86
|
+
sessionData.forEach(session => {
|
|
87
|
+
if (!session || !session.conversationId) {
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
if (sessionMap[session.conversationId]) {
|
|
91
|
+
console.warn(ASSIGN_SESSION_LOG_PREFIX, 'duplicate-session', {
|
|
92
|
+
taskId,
|
|
93
|
+
conversationId: session.conversationId,
|
|
94
|
+
wechatAccountId: session.wechatAccountId
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
sessionMap[session.conversationId] = session
|
|
98
|
+
})
|
|
99
|
+
const accountChangeMap = {}
|
|
100
|
+
Object.keys(sessionMap).forEach(conversationId => {
|
|
101
|
+
const serverSession = sessionMap[conversationId]
|
|
102
|
+
const localSession = clientChat.session.sessionMap[conversationId] || serverSession
|
|
103
|
+
const before = sessionUnreadBefore[conversationId]
|
|
104
|
+
const beforeUnread = before ? before.unread : 0
|
|
105
|
+
const beforeMute = before ? before.mute : false
|
|
106
|
+
const afterUnread = localSession.unreadMsgCount || 0
|
|
107
|
+
const afterMute = !!localSession.mute
|
|
108
|
+
const wechatAccountId = localSession.wechatAccountId
|
|
109
|
+
if (!accountChangeMap[wechatAccountId]) {
|
|
110
|
+
accountChangeMap[wechatAccountId] = {
|
|
111
|
+
wechatAccountId,
|
|
112
|
+
unreadDelta: 0,
|
|
113
|
+
muteDelta: 0,
|
|
114
|
+
isNewAccount: !accountIdBeforeMap[wechatAccountId],
|
|
115
|
+
sessionCount: 0
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
accountChangeMap[wechatAccountId].unreadDelta += afterUnread - beforeUnread
|
|
119
|
+
accountChangeMap[wechatAccountId].muteDelta += (afterMute ? afterUnread : 0) - (beforeMute ? beforeUnread : 0)
|
|
120
|
+
accountChangeMap[wechatAccountId].sessionCount += 1
|
|
121
|
+
})
|
|
122
|
+
return Object.keys(accountChangeMap).map(accountId => accountChangeMap[accountId])
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function updateAssignAccountUnread (clientChat, changes, taskId, eventType) {
|
|
126
|
+
return Promise.all(changes.map(change => {
|
|
127
|
+
const accountUnreadBefore = getAccountUnreadSnapshot(clientChat.account, [change.wechatAccountId])[0] || {
|
|
128
|
+
wechatAccountId: change.wechatAccountId,
|
|
129
|
+
unread: 0,
|
|
130
|
+
muteUnread: 0
|
|
131
|
+
}
|
|
132
|
+
let promise
|
|
133
|
+
let strategy
|
|
134
|
+
if (change.isNewAccount) {
|
|
135
|
+
strategy = 'server-refresh'
|
|
136
|
+
promise = clientChat.account.refreshAccountUnreadMessageNum({
|
|
137
|
+
wechatAccountId: change.wechatAccountId
|
|
138
|
+
})
|
|
139
|
+
} else if (change.unreadDelta || change.muteDelta) {
|
|
140
|
+
strategy = 'delta'
|
|
141
|
+
promise = clientChat.account.updateAccountUnreadMessageNum(change.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => ({
|
|
142
|
+
num: Math.max(0, (unreadMesasgeNum || 0) + change.unreadDelta),
|
|
143
|
+
muteNum: Math.max(0, (unreadMessageMuteNum || 0) + change.muteDelta)
|
|
144
|
+
}))
|
|
145
|
+
} else {
|
|
146
|
+
strategy = 'no-change'
|
|
147
|
+
promise = Promise.resolve()
|
|
148
|
+
}
|
|
149
|
+
return promise.then(() => {
|
|
150
|
+
console.info(ASSIGN_SESSION_LOG_PREFIX, 'account-unread-updated', {
|
|
151
|
+
eventType,
|
|
152
|
+
taskId,
|
|
153
|
+
wechatAccountId: change.wechatAccountId,
|
|
154
|
+
sessionCount: change.sessionCount,
|
|
155
|
+
unreadDelta: change.unreadDelta,
|
|
156
|
+
muteDelta: change.muteDelta,
|
|
157
|
+
strategy,
|
|
158
|
+
before: accountUnreadBefore,
|
|
159
|
+
after: getAccountUnreadSnapshot(clientChat.account, [change.wechatAccountId])[0] || null
|
|
160
|
+
})
|
|
161
|
+
}).catch(error => {
|
|
162
|
+
console.error(ASSIGN_SESSION_LOG_PREFIX, 'account-unread-update-error', {
|
|
163
|
+
eventType,
|
|
164
|
+
taskId,
|
|
165
|
+
wechatAccountId: change.wechatAccountId,
|
|
166
|
+
unreadDelta: change.unreadDelta,
|
|
167
|
+
muteDelta: change.muteDelta,
|
|
168
|
+
strategy,
|
|
169
|
+
message: error && error.message ? error.message : String(error)
|
|
170
|
+
})
|
|
171
|
+
throw error
|
|
172
|
+
})
|
|
173
|
+
}))
|
|
174
|
+
}
|
|
175
|
+
|
|
46
176
|
class ClientChat {
|
|
47
177
|
data = Vue.observable({
|
|
48
178
|
connectStatus: CONNECT_STATUS.Normal
|
|
@@ -866,6 +996,16 @@ class ClientChat {
|
|
|
866
996
|
},
|
|
867
997
|
// 好友有变化,如分配的情况
|
|
868
998
|
onCmdFriendInfoChanged: ({ data }) => {
|
|
999
|
+
const assignAccountUnreadBefore = data.changeType === 4 ? getAccountUnreadSnapshot(this.account) : null
|
|
1000
|
+
if (data.changeType === 4) {
|
|
1001
|
+
console.info(ASSIGN_SESSION_LOG_PREFIX, 'socket-event', {
|
|
1002
|
+
eventType: 'friend-info-changed',
|
|
1003
|
+
taskId: data.taskId,
|
|
1004
|
+
changeType: data.changeType,
|
|
1005
|
+
itemCount: Array.isArray(data.friends) ? data.friends.length : 0,
|
|
1006
|
+
accountUnreadBefore: assignAccountUnreadBefore
|
|
1007
|
+
})
|
|
1008
|
+
}
|
|
869
1009
|
if (!this.socketFriendInfoChangedSerialQueue) {
|
|
870
1010
|
this.socketFriendInfoChangedSerialQueue = createSerialQueue()
|
|
871
1011
|
}
|
|
@@ -879,14 +1019,19 @@ class ClientChat {
|
|
|
879
1019
|
accountIds: (this.account.accountData || []).map(v => v.id)
|
|
880
1020
|
})
|
|
881
1021
|
} else {
|
|
1022
|
+
const sessionUnreadBefore = getSessionUnreadSnapshot(this.session)
|
|
1023
|
+
const accountIdBeforeMap = Object.keys(this.account.accountMap || {}).reduce((result, accountId) => {
|
|
1024
|
+
result[accountId] = true
|
|
1025
|
+
return result
|
|
1026
|
+
}, {})
|
|
882
1027
|
// 增量拉取分配产生的会话
|
|
883
1028
|
return this.session.loadAssignTaskSessionData({
|
|
884
1029
|
taskId: data.taskId
|
|
885
1030
|
}).then((rs) => {
|
|
886
|
-
const wechatAccountIds =
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
1031
|
+
const wechatAccountIds = getAssignAccountIds(rs)
|
|
1032
|
+
const accountUnreadBefore = assignAccountUnreadBefore.filter(item => wechatAccountIds.indexOf(item.wechatAccountId) >= 0)
|
|
1033
|
+
const accountUnreadChanges = getAssignUnreadChanges(this, rs, sessionUnreadBefore, accountIdBeforeMap, data.taskId)
|
|
1034
|
+
let accountUnreadUpdated = false
|
|
890
1035
|
const changeFriendMap = {}
|
|
891
1036
|
// 删除changeType为3移除的好友,例如转移的场景
|
|
892
1037
|
if (data.friends && data.friends.length) {
|
|
@@ -919,25 +1064,27 @@ class ClientChat {
|
|
|
919
1064
|
return this.contacts.getFriend(sessionFriendId, true)
|
|
920
1065
|
})
|
|
921
1066
|
}
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
muteNum: (unreadMessageMuteNum || 0) + (session.unreadMsgCount || 0)
|
|
930
|
-
}
|
|
931
|
-
} else {
|
|
932
|
-
return {
|
|
933
|
-
num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
|
|
934
|
-
muteNum: unreadMessageMuteNum
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
})
|
|
1067
|
+
ps = ps.then(() => updateAssignAccountUnread(this, accountUnreadChanges, data.taskId, 'friend-info-changed')).then(() => {
|
|
1068
|
+
accountUnreadUpdated = true
|
|
1069
|
+
}).catch(error => {
|
|
1070
|
+
console.error(ASSIGN_SESSION_LOG_PREFIX, 'socket-process-error', {
|
|
1071
|
+
eventType: 'friend-info-changed',
|
|
1072
|
+
taskId: data.taskId,
|
|
1073
|
+
message: error && error.message ? error.message : String(error)
|
|
938
1074
|
})
|
|
939
|
-
|
|
1075
|
+
throw error
|
|
1076
|
+
})
|
|
940
1077
|
return ps.finally(() => {
|
|
1078
|
+
console.info(ASSIGN_SESSION_LOG_PREFIX, 'socket-complete', {
|
|
1079
|
+
eventType: 'friend-info-changed',
|
|
1080
|
+
taskId: data.taskId,
|
|
1081
|
+
sessionCount: rs ? rs.length : 0,
|
|
1082
|
+
wechatAccountIds,
|
|
1083
|
+
accountUnreadChanges,
|
|
1084
|
+
accountUnreadBefore,
|
|
1085
|
+
accountUnreadAfter: getAccountUnreadSnapshot(this.account, wechatAccountIds),
|
|
1086
|
+
accountUnreadUpdated
|
|
1087
|
+
})
|
|
941
1088
|
// 这里应该标记那些工作微信号的通讯录修改了,后面要在界面打个提示,告诉用户通讯录变化了,让手动刷新一下
|
|
942
1089
|
// 同时也将缓存都清理一下,例如工作微信号分组统计数量等
|
|
943
1090
|
this.contacts.markModify() // 标记通讯录修改
|
|
@@ -976,16 +1123,31 @@ class ClientChat {
|
|
|
976
1123
|
},
|
|
977
1124
|
// 群聊有变化,如分配的情况
|
|
978
1125
|
onCmdChatroomInfoChanged: ({ data }) => {
|
|
1126
|
+
const assignAccountUnreadBefore = data.changeType === 4 ? getAccountUnreadSnapshot(this.account) : null
|
|
1127
|
+
if (data.changeType === 4) {
|
|
1128
|
+
console.info(ASSIGN_SESSION_LOG_PREFIX, 'socket-event', {
|
|
1129
|
+
eventType: 'chatroom-info-changed',
|
|
1130
|
+
taskId: data.taskId,
|
|
1131
|
+
changeType: data.changeType,
|
|
1132
|
+
itemCount: Array.isArray(data.chatrooms) ? data.chatrooms.length : 0,
|
|
1133
|
+
accountUnreadBefore: assignAccountUnreadBefore
|
|
1134
|
+
})
|
|
1135
|
+
}
|
|
979
1136
|
// 配分群聊
|
|
980
1137
|
if (data.changeType === 4) {
|
|
1138
|
+
const sessionUnreadBefore = getSessionUnreadSnapshot(this.session)
|
|
1139
|
+
const accountIdBeforeMap = Object.keys(this.account.accountMap || {}).reduce((result, accountId) => {
|
|
1140
|
+
result[accountId] = true
|
|
1141
|
+
return result
|
|
1142
|
+
}, {})
|
|
981
1143
|
// 增量拉取分配产生的会话
|
|
982
1144
|
return this.session.loadAssignTaskSessionData({
|
|
983
1145
|
taskId: data.taskId
|
|
984
1146
|
}).then((rs) => {
|
|
985
|
-
const wechatAccountIds =
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
1147
|
+
const wechatAccountIds = getAssignAccountIds(rs)
|
|
1148
|
+
const accountUnreadBefore = assignAccountUnreadBefore.filter(item => wechatAccountIds.indexOf(item.wechatAccountId) >= 0)
|
|
1149
|
+
const accountUnreadChanges = getAssignUnreadChanges(this, rs, sessionUnreadBefore, accountIdBeforeMap, data.taskId)
|
|
1150
|
+
let accountUnreadUpdated = false
|
|
989
1151
|
// 删除changeType为3移除的群聊,例如转移的场景
|
|
990
1152
|
if (data.chatrooms && data.chatrooms.length) {
|
|
991
1153
|
data.chatrooms.forEach(room => {
|
|
@@ -1001,25 +1163,27 @@ class ClientChat {
|
|
|
1001
1163
|
ps = this.account.reloadData()
|
|
1002
1164
|
}
|
|
1003
1165
|
}
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
muteNum: (unreadMessageMuteNum || 0) + (session.unreadMsgCount || 0)
|
|
1012
|
-
}
|
|
1013
|
-
} else {
|
|
1014
|
-
return {
|
|
1015
|
-
num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
|
|
1016
|
-
muteNum: unreadMessageMuteNum
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1019
|
-
})
|
|
1166
|
+
ps = ps.then(() => updateAssignAccountUnread(this, accountUnreadChanges, data.taskId, 'chatroom-info-changed')).then(() => {
|
|
1167
|
+
accountUnreadUpdated = true
|
|
1168
|
+
}).catch(error => {
|
|
1169
|
+
console.error(ASSIGN_SESSION_LOG_PREFIX, 'socket-process-error', {
|
|
1170
|
+
eventType: 'chatroom-info-changed',
|
|
1171
|
+
taskId: data.taskId,
|
|
1172
|
+
message: error && error.message ? error.message : String(error)
|
|
1020
1173
|
})
|
|
1021
|
-
|
|
1174
|
+
throw error
|
|
1175
|
+
})
|
|
1022
1176
|
return ps.finally(() => {
|
|
1177
|
+
console.info(ASSIGN_SESSION_LOG_PREFIX, 'socket-complete', {
|
|
1178
|
+
eventType: 'chatroom-info-changed',
|
|
1179
|
+
taskId: data.taskId,
|
|
1180
|
+
sessionCount: rs ? rs.length : 0,
|
|
1181
|
+
wechatAccountIds,
|
|
1182
|
+
accountUnreadChanges,
|
|
1183
|
+
accountUnreadBefore,
|
|
1184
|
+
accountUnreadAfter: getAccountUnreadSnapshot(this.account, wechatAccountIds),
|
|
1185
|
+
accountUnreadUpdated
|
|
1186
|
+
})
|
|
1023
1187
|
// 这里应该标记那些工作微信号的通讯录修改了,后面要在界面打个提示,告诉用户通讯录变化了,让手动刷新一下
|
|
1024
1188
|
// 同时也将缓存都清理一下,例如工作微信号分组统计数量等
|
|
1025
1189
|
this.contacts.markModify() // 标记通讯录修改
|