@aochuang/client-sdk 1.0.332 → 1.0.334
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
|
@@ -92,6 +92,7 @@ class ClientChat {
|
|
|
92
92
|
checkMessageSendResultMethod: null,
|
|
93
93
|
loadLossRoomMessageDataMethod: null,
|
|
94
94
|
loadLossFriendMessageDataMethod: null,
|
|
95
|
+
shouldMarkCurrentSessionReadMethod: null,
|
|
95
96
|
onOverwriteFriendInfoChange: null // 为了兼容1.0拉取会话逻辑加的,1.0暂时不支持根据taskId拉取
|
|
96
97
|
}, options)
|
|
97
98
|
if (!options.loadFriendMessageDataMethod) {
|
|
@@ -101,6 +102,7 @@ class ClientChat {
|
|
|
101
102
|
throw new Error('loadRoomMessageDataMethod不能为空')
|
|
102
103
|
}
|
|
103
104
|
this.onOverwriteFriendInfoChange = options.onOverwriteFriendInfoChange
|
|
105
|
+
this.shouldMarkCurrentSessionReadMethod = options.shouldMarkCurrentSessionReadMethod
|
|
104
106
|
this.event = new Event({
|
|
105
107
|
checkOnMethod: (name) => {
|
|
106
108
|
if (name === 'ready') {
|
|
@@ -461,7 +463,7 @@ class ClientChat {
|
|
|
461
463
|
unreadMsgCount: session.unreadMsgCount
|
|
462
464
|
}
|
|
463
465
|
if (!data.isSend) {
|
|
464
|
-
if (this.sessionManage.currentSession && this.sessionManage.currentSession.conversationId === sessionId) {
|
|
466
|
+
if (this.sessionManage.currentSession && this.sessionManage.currentSession.conversationId === sessionId && this.shouldMarkCurrentSessionRead(sessionId, data)) {
|
|
465
467
|
// 标记已读
|
|
466
468
|
this.session.setSessionRead(sessionId)
|
|
467
469
|
} else {
|
|
@@ -603,7 +605,7 @@ class ClientChat {
|
|
|
603
605
|
unreadMsgCount: session.unreadMsgCount
|
|
604
606
|
}
|
|
605
607
|
if (!data.isSend) {
|
|
606
|
-
if (this.sessionManage.currentSession && this.sessionManage.currentSession.conversationId === sessionId) {
|
|
608
|
+
if (this.sessionManage.currentSession && this.sessionManage.currentSession.conversationId === sessionId && this.shouldMarkCurrentSessionRead(sessionId, data)) {
|
|
607
609
|
// 标记已读
|
|
608
610
|
this.session.setSessionRead(sessionId)
|
|
609
611
|
} else {
|
|
@@ -1183,6 +1185,21 @@ class ClientChat {
|
|
|
1183
1185
|
this.event.off('ready')
|
|
1184
1186
|
}
|
|
1185
1187
|
|
|
1188
|
+
setShouldMarkCurrentSessionReadMethod (method) {
|
|
1189
|
+
this.shouldMarkCurrentSessionReadMethod = method
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
shouldMarkCurrentSessionRead (sessionId, data) {
|
|
1193
|
+
if (typeof this.shouldMarkCurrentSessionReadMethod === 'function') {
|
|
1194
|
+
return this.shouldMarkCurrentSessionReadMethod({
|
|
1195
|
+
sessionId,
|
|
1196
|
+
data,
|
|
1197
|
+
currentSession: this.sessionManage.currentSession
|
|
1198
|
+
}) !== false
|
|
1199
|
+
}
|
|
1200
|
+
return true
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1186
1203
|
handleAutoReadMessageSession (sessionId) {
|
|
1187
1204
|
if (!sessionId) {
|
|
1188
1205
|
return
|
|
@@ -15,6 +15,7 @@ export default class ClietChatSocket {
|
|
|
15
15
|
// 执行回调事件前的方法
|
|
16
16
|
beforeFireCallback: null,
|
|
17
17
|
onCmdQwNewMessage: null,
|
|
18
|
+
onCmdQwContactInfoChanged: null,
|
|
18
19
|
onCmdSendMessageResult: null,
|
|
19
20
|
onCmdFriendInfoChanged: null,
|
|
20
21
|
onCmdDownloadVideoResult: null,
|
|
@@ -27,6 +28,7 @@ export default class ClietChatSocket {
|
|
|
27
28
|
}
|
|
28
29
|
this.socket = options.socket
|
|
29
30
|
this.socket.event.on('onCmdQwNewMessage', options.onCmdQwNewMessage)
|
|
31
|
+
this.socket.event.on('onCmdQwContactInfoChanged', options.onCmdQwContactInfoChanged)
|
|
30
32
|
this.socket.event.on('onHeartbeatCheck', ({ mergeParams }) => {
|
|
31
33
|
options.onHeartbeatCheck && options.onHeartbeatCheck({
|
|
32
34
|
mergeParams
|
|
@@ -62,4 +64,4 @@ export default class ClietChatSocket {
|
|
|
62
64
|
setUrl (url) {
|
|
63
65
|
this.socket.setUrl(url)
|
|
64
66
|
}
|
|
65
|
-
}
|
|
67
|
+
}
|
|
@@ -258,6 +258,58 @@ class ClientChat {
|
|
|
258
258
|
})
|
|
259
259
|
this.socket = new ClientChatSocket({
|
|
260
260
|
socket: options.socket,
|
|
261
|
+
onCmdQwContactInfoChanged: ({ data }) => {
|
|
262
|
+
if (!data) {
|
|
263
|
+
return
|
|
264
|
+
}
|
|
265
|
+
const contacts = Array.isArray(data.contacts)
|
|
266
|
+
? data.contacts
|
|
267
|
+
: (data.contactId ? [data] : [])
|
|
268
|
+
const removedSessionIds = {}
|
|
269
|
+
const accountUnreadCountMap = {}
|
|
270
|
+
let contactsModified = false
|
|
271
|
+
contacts.forEach(contact => {
|
|
272
|
+
if (!contact || Number(contact.changeType) !== 3 || !contact.contactId) {
|
|
273
|
+
return
|
|
274
|
+
}
|
|
275
|
+
contactsModified = true
|
|
276
|
+
this.contacts.removeFriend(contact.contactId)
|
|
277
|
+
let session = this.session.findSession(({ session }) => {
|
|
278
|
+
return String(session.type) === '0' &&
|
|
279
|
+
session.targetId === contact.contactId &&
|
|
280
|
+
(!contact.qwAccountId || session.qwAccountId === contact.qwAccountId)
|
|
281
|
+
})
|
|
282
|
+
if (!session) {
|
|
283
|
+
const sessionId = createSessionId(
|
|
284
|
+
contact.corpId || data.corpId,
|
|
285
|
+
contact.qwAccountId,
|
|
286
|
+
contact.contactId
|
|
287
|
+
)
|
|
288
|
+
session = sessionId && this.session.getSessionByLocal(sessionId)
|
|
289
|
+
}
|
|
290
|
+
if (!session || removedSessionIds[session.id]) {
|
|
291
|
+
return
|
|
292
|
+
}
|
|
293
|
+
removedSessionIds[session.id] = true
|
|
294
|
+
if (this.session.currentSession && this.session.currentSession.id === session.id) {
|
|
295
|
+
this.session.setCurrentSession(null)
|
|
296
|
+
}
|
|
297
|
+
const accountId = session.qwAccountId || contact.qwAccountId
|
|
298
|
+
if (accountId) {
|
|
299
|
+
accountUnreadCountMap[accountId] = (accountUnreadCountMap[accountId] || 0) + (session.unreadMsgCount || 0)
|
|
300
|
+
}
|
|
301
|
+
this.session.removeSession(session.id)
|
|
302
|
+
})
|
|
303
|
+
if (contactsModified) {
|
|
304
|
+
this.contacts.markModify()
|
|
305
|
+
}
|
|
306
|
+
return Promise.all(Object.keys(accountUnreadCountMap).map(accountId => {
|
|
307
|
+
const removedUnreadCount = accountUnreadCountMap[accountId]
|
|
308
|
+
return this.account.updateAccountUnreadMessageNum(accountId, ({ unreadMesasgeNum }) => {
|
|
309
|
+
return Math.max(0, unreadMesasgeNum - removedUnreadCount)
|
|
310
|
+
})
|
|
311
|
+
}))
|
|
312
|
+
},
|
|
261
313
|
// 接受新消息
|
|
262
314
|
onCmdQwNewMessage: ({ data }) => {
|
|
263
315
|
// 插入消息
|
|
@@ -328,4 +380,4 @@ class ClientChat {
|
|
|
328
380
|
}
|
|
329
381
|
}
|
|
330
382
|
|
|
331
|
-
export default ClientChat
|
|
383
|
+
export default ClientChat
|