@aochuang/client-sdk 1.0.377 → 1.0.378
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/components/chat-editor/chat-editor-suggestions/chat-editor-suggestions.vue +40 -4
- package/components/chat-editor/chat-editor.vue +75 -5
- package/package.json +1 -1
- package/services/client-chat/client-chat-wechat/client-chat-message.js +15 -5
- package/services/client-chat/client-chat-wechat/client-chat-session.js +13 -50
- package/services/client-chat/client-chat-wechat/client-chat.js +4 -48
- package/services/client-chat/client-chat-wechat/docs//350/264/246/345/217/267/346/234/252/350/257/273/346/225/260/351/207/217/344/270/216/344/274/232/350/257/235/346/234/252/350/257/273/346/225/260/351/207/217/344/270/215/344/270/200/350/207/264/351/227/256/351/242/230/344/277/256/345/244/215.md +4 -2
|
@@ -19,11 +19,12 @@
|
|
|
19
19
|
<span
|
|
20
20
|
class="sdk-chat-editor-suggestions__close"
|
|
21
21
|
title="关闭"
|
|
22
|
-
@
|
|
22
|
+
@mousedown.prevent.stop
|
|
23
|
+
@click.stop="handleCloseClick"
|
|
23
24
|
></span>
|
|
24
25
|
</div>
|
|
25
26
|
</div>
|
|
26
|
-
<div class="sdk-chat-editor-suggestions__body" ref="body">
|
|
27
|
+
<div class="sdk-chat-editor-suggestions__body" ref="body" @scroll="handleBodyScroll">
|
|
27
28
|
<template v-if="data && data.length">
|
|
28
29
|
<div class="sdk-chat-editor-suggestions__list">
|
|
29
30
|
<div
|
|
@@ -39,6 +40,9 @@
|
|
|
39
40
|
</div>
|
|
40
41
|
</div>
|
|
41
42
|
</template>
|
|
43
|
+
<div v-if="loadingMore" class="sdk-chat-editor-suggestions__load-more">
|
|
44
|
+
<ui-loading size="mini" text="加载中..."></ui-loading>
|
|
45
|
+
</div>
|
|
42
46
|
</div>
|
|
43
47
|
<div class="sdk-chat-editor-suggestions__foot">
|
|
44
48
|
<ui-icon name="information-line"></ui-icon> 提示:
|
|
@@ -68,8 +72,20 @@ export default {
|
|
|
68
72
|
type: Boolean,
|
|
69
73
|
default: false
|
|
70
74
|
},
|
|
75
|
+
loadingMore: {
|
|
76
|
+
type: Boolean,
|
|
77
|
+
default: false
|
|
78
|
+
},
|
|
71
79
|
confirmMethod: {
|
|
72
80
|
type: Function
|
|
81
|
+
},
|
|
82
|
+
loadMoreEnabled: {
|
|
83
|
+
type: Boolean,
|
|
84
|
+
default: false
|
|
85
|
+
},
|
|
86
|
+
hasMore: {
|
|
87
|
+
type: Boolean,
|
|
88
|
+
default: false
|
|
73
89
|
}
|
|
74
90
|
},
|
|
75
91
|
data () {
|
|
@@ -106,7 +122,16 @@ export default {
|
|
|
106
122
|
},
|
|
107
123
|
methods: {
|
|
108
124
|
handleCloseClick () {
|
|
109
|
-
this
|
|
125
|
+
this.$emit('close')
|
|
126
|
+
},
|
|
127
|
+
handleBodyScroll (evt) {
|
|
128
|
+
if (!this.loadMoreEnabled || this.loading || this.loadingMore || !this.hasMore) {
|
|
129
|
+
return
|
|
130
|
+
}
|
|
131
|
+
const target = evt.target
|
|
132
|
+
if (target.scrollHeight - target.scrollTop - target.clientHeight <= 20) {
|
|
133
|
+
this.$emit('load-more')
|
|
134
|
+
}
|
|
110
135
|
},
|
|
111
136
|
handleItemMouseEnter (item) {
|
|
112
137
|
this.focusId = item.id
|
|
@@ -180,7 +205,10 @@ export default {
|
|
|
180
205
|
checkAutoFocus () {
|
|
181
206
|
if (!this.data || !this.data.length) {
|
|
182
207
|
this.focusId = null
|
|
183
|
-
|
|
208
|
+
return
|
|
209
|
+
}
|
|
210
|
+
const hasFocusedItem = this.data.some(item => item.id === this.focusId)
|
|
211
|
+
if (!hasFocusedItem) {
|
|
184
212
|
this.focusId = this.data[0].id
|
|
185
213
|
}
|
|
186
214
|
},
|
|
@@ -297,6 +325,14 @@ export default {
|
|
|
297
325
|
overflow: auto;
|
|
298
326
|
position: relative;
|
|
299
327
|
}
|
|
328
|
+
.sdk-chat-editor-suggestions__load-more {
|
|
329
|
+
height: 28px;
|
|
330
|
+
display: flex;
|
|
331
|
+
align-items: center;
|
|
332
|
+
justify-content: center;
|
|
333
|
+
color: #999;
|
|
334
|
+
font-size: 12px;
|
|
335
|
+
}
|
|
300
336
|
.sdk-chat-editor-suggestions__foot{
|
|
301
337
|
color: #999;
|
|
302
338
|
line-height: 24px;
|
|
@@ -46,8 +46,13 @@
|
|
|
46
46
|
ref="suggestions"
|
|
47
47
|
:keyword="suggestionsKeyword"
|
|
48
48
|
:loading="suggestioning"
|
|
49
|
+
:loading-more="suggestionsLoadingMore"
|
|
49
50
|
:data="suggestionsData"
|
|
50
51
|
:confirm-method="handleSuggestionsConfirmMethod"
|
|
52
|
+
:load-more-enabled="suggestionsLoadMore"
|
|
53
|
+
:has-more="suggestionsHasMore"
|
|
54
|
+
@load-more="handleSuggestionsLoadMore"
|
|
55
|
+
@close="handleSuggestionsClose"
|
|
51
56
|
@closed="handleSuggestionsClosed"
|
|
52
57
|
>
|
|
53
58
|
<template slot="item" slot-scope="scope">
|
|
@@ -83,6 +88,14 @@ export default {
|
|
|
83
88
|
fetchSuggestionsMethod: {
|
|
84
89
|
type: Function
|
|
85
90
|
},
|
|
91
|
+
suggestionsLoadMore: {
|
|
92
|
+
type: Boolean,
|
|
93
|
+
default: false
|
|
94
|
+
},
|
|
95
|
+
suggestionsPageSize: {
|
|
96
|
+
type: Number,
|
|
97
|
+
default: 20
|
|
98
|
+
},
|
|
86
99
|
confirmSuggestionsMethod: {
|
|
87
100
|
type: Function
|
|
88
101
|
},
|
|
@@ -99,6 +112,8 @@ export default {
|
|
|
99
112
|
sending: false,
|
|
100
113
|
popoverActive: false,
|
|
101
114
|
suggestioning: false,
|
|
115
|
+
suggestionsLoadingMore: false,
|
|
116
|
+
suggestionsHasMore: false,
|
|
102
117
|
suggestionsData: [],
|
|
103
118
|
suggestionsKeyword: null,
|
|
104
119
|
inputValue: this.value || ''
|
|
@@ -127,6 +142,30 @@ export default {
|
|
|
127
142
|
},
|
|
128
143
|
handleSuggestionsClosed () {
|
|
129
144
|
this.suggestionsData = []
|
|
145
|
+
this.suggestionsLoadingMore = false
|
|
146
|
+
this.suggestionsHasMore = false
|
|
147
|
+
},
|
|
148
|
+
handleSuggestionsClose () {
|
|
149
|
+
const range = this.cacheInputRange ? Object.assign({}, this.cacheInputRange) : null
|
|
150
|
+
this.closeSuggestions()
|
|
151
|
+
this.$nextTick(() => {
|
|
152
|
+
this.focus()
|
|
153
|
+
if (range) {
|
|
154
|
+
this.setSelectionByTextRange(range.start, range.end)
|
|
155
|
+
}
|
|
156
|
+
})
|
|
157
|
+
},
|
|
158
|
+
handleSuggestionsLoadMore () {
|
|
159
|
+
if (!this.suggestionsLoadMore || this.suggestioning || this.suggestionsLoadingMore || !this.suggestionsHasMore) {
|
|
160
|
+
return
|
|
161
|
+
}
|
|
162
|
+
const lastItem = this.suggestionsData.length
|
|
163
|
+
? this.suggestionsData[this.suggestionsData.length - 1]
|
|
164
|
+
: null
|
|
165
|
+
return this.loadSuggestions(this.suggestionsKeyword, this.suggestionsNearsetInfo, {
|
|
166
|
+
isLoadMore: true,
|
|
167
|
+
lastItem
|
|
168
|
+
})
|
|
130
169
|
},
|
|
131
170
|
handleSuggestionsConfirmMethod ({ item }) {
|
|
132
171
|
const next = () => {
|
|
@@ -255,29 +294,58 @@ export default {
|
|
|
255
294
|
this.loadSuggestions(nearest, nearsetInfo)
|
|
256
295
|
}, 200)
|
|
257
296
|
},
|
|
258
|
-
loadSuggestions (keyword, nearestInfo) {
|
|
297
|
+
loadSuggestions (keyword, nearestInfo, options = {}) {
|
|
259
298
|
if (!this.fetchSuggestionsMethod) {
|
|
260
299
|
return
|
|
261
300
|
}
|
|
301
|
+
const isLoadMore = !!options.isLoadMore
|
|
262
302
|
keyword = this.normalizeSuggestionsKeyword(nearestInfo, keyword)
|
|
303
|
+
if (!isLoadMore) {
|
|
304
|
+
this.suggestionsHasMore = false
|
|
305
|
+
}
|
|
263
306
|
const requestId = (this._suggestionsRequestId || 0) + 1
|
|
264
307
|
this._suggestionsRequestId = requestId
|
|
265
|
-
|
|
308
|
+
if (isLoadMore) {
|
|
309
|
+
this.suggestionsLoadingMore = true
|
|
310
|
+
} else {
|
|
311
|
+
this.suggestioning = true
|
|
312
|
+
}
|
|
266
313
|
this.suggestionsKeyword = keyword
|
|
267
314
|
this.popoverActive = true
|
|
268
315
|
clearTimeout(this._loadSuggestionsTimer)
|
|
269
316
|
return this.fetchSuggestionsMethod({
|
|
270
317
|
keyword,
|
|
271
318
|
nearestInfo,
|
|
272
|
-
isAtContext: !!(nearestInfo && nearestInfo.isAtContext)
|
|
319
|
+
isAtContext: !!(nearestInfo && nearestInfo.isAtContext),
|
|
320
|
+
isLoadMore,
|
|
321
|
+
lastItem: options.lastItem || null
|
|
273
322
|
}).then(rs => {
|
|
274
323
|
if (requestId !== this._suggestionsRequestId) {
|
|
275
324
|
return
|
|
276
325
|
}
|
|
277
|
-
|
|
326
|
+
const nextData = rs || []
|
|
327
|
+
if (isLoadMore) {
|
|
328
|
+
const ids = new Set(this.suggestionsData.map(item => item.id))
|
|
329
|
+
this.suggestionsData = this.suggestionsData.concat(nextData.filter(item => {
|
|
330
|
+
if (ids.has(item.id)) {
|
|
331
|
+
return false
|
|
332
|
+
}
|
|
333
|
+
ids.add(item.id)
|
|
334
|
+
return true
|
|
335
|
+
}))
|
|
336
|
+
} else {
|
|
337
|
+
this.suggestionsData = nextData
|
|
338
|
+
}
|
|
339
|
+
this.suggestionsHasMore = this.suggestionsLoadMore &&
|
|
340
|
+
this.suggestionsPageSize > 0 &&
|
|
341
|
+
nextData.length >= this.suggestionsPageSize
|
|
278
342
|
}).finally(() => {
|
|
279
343
|
if (requestId === this._suggestionsRequestId) {
|
|
280
|
-
|
|
344
|
+
if (isLoadMore) {
|
|
345
|
+
this.suggestionsLoadingMore = false
|
|
346
|
+
} else {
|
|
347
|
+
this.suggestioning = false
|
|
348
|
+
}
|
|
281
349
|
}
|
|
282
350
|
})
|
|
283
351
|
},
|
|
@@ -294,6 +362,8 @@ export default {
|
|
|
294
362
|
this._suggestionsRequestId = (this._suggestionsRequestId || 0) + 1
|
|
295
363
|
this.$refs.suggestions && this.$refs.suggestions.close()
|
|
296
364
|
this.suggestioning = false
|
|
365
|
+
this.suggestionsLoadingMore = false
|
|
366
|
+
this.suggestionsHasMore = false
|
|
297
367
|
this.popoverActive = false
|
|
298
368
|
},
|
|
299
369
|
hasCurrentSuggestionsContext () {
|
package/package.json
CHANGED
|
@@ -146,6 +146,21 @@ export default class ClientChatMessage {
|
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
if (fireEvent !== false) {
|
|
149
|
+
// 先执行onAddMessageSuccess再发add-message事件,保证会话的getSession轮询先由这里发起、更新会话的回调排在最前面,
|
|
150
|
+
// 外部监听add-message后再调getSession只是复用同一个轮询
|
|
151
|
+
// try/catch是为了避免回调里的异常把add-message事件吞掉(外部的新消息提醒、本地消息缓存都依赖这个事件)
|
|
152
|
+
try {
|
|
153
|
+
this.onAddMessageSuccess && this.onAddMessageSuccess({
|
|
154
|
+
data,
|
|
155
|
+
lastMessageTime,
|
|
156
|
+
isBeforeLastMessage
|
|
157
|
+
})
|
|
158
|
+
} catch (error) {
|
|
159
|
+
console.error('[client-chat-message] onAddMessageSuccess error', {
|
|
160
|
+
messageId: data.id,
|
|
161
|
+
error
|
|
162
|
+
})
|
|
163
|
+
}
|
|
149
164
|
// 如果消息包含这种情况,就不能往外发送add-message事件
|
|
150
165
|
// 因为例如群发的消息,他没有会话,导致前端在处理来了新消息通知铃声提醒,获取会话一直获取不到,然后会总是发送请求
|
|
151
166
|
if (!isBeforeLastMessage && !isAutoReadMessage(data) && !shouldIgnoreSessionByMessage(data) && !isDeletedMsg(data) && !isBlockedMsg(data)) {
|
|
@@ -153,11 +168,6 @@ export default class ClientChatMessage {
|
|
|
153
168
|
data
|
|
154
169
|
})
|
|
155
170
|
}
|
|
156
|
-
this.onAddMessageSuccess && this.onAddMessageSuccess({
|
|
157
|
-
data,
|
|
158
|
-
lastMessageTime,
|
|
159
|
-
isBeforeLastMessage
|
|
160
|
-
})
|
|
161
171
|
}
|
|
162
172
|
}
|
|
163
173
|
|
|
@@ -242,37 +242,19 @@ export default class ClientChatSession {
|
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
-
|
|
246
|
-
if (!serializeMethod) {
|
|
247
|
-
return false
|
|
248
|
-
}
|
|
249
|
-
const messageId = taskOptions.messageId
|
|
250
|
-
if (messageId && pollRequest.serializeTaskMap[messageId]) {
|
|
251
|
-
return false
|
|
252
|
-
}
|
|
253
|
-
const task = {
|
|
254
|
-
messageId,
|
|
255
|
-
wechatTime: taskOptions.wechatTime || 0,
|
|
256
|
-
index: pollRequest.serializeTasks.length,
|
|
257
|
-
serializeMethod
|
|
258
|
-
}
|
|
259
|
-
pollRequest.serializeTasks.push(task)
|
|
260
|
-
if (messageId) {
|
|
261
|
-
pollRequest.serializeTaskMap[messageId] = task
|
|
262
|
-
}
|
|
263
|
-
return true
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
getSession (sessionId, serializeMethod, taskOptions = {}) {
|
|
245
|
+
getSession (sessionId, serializeMethod) {
|
|
267
246
|
if (this.sessionMap[sessionId]) {
|
|
268
247
|
return Promise.resolve({
|
|
269
248
|
data: this.sessionMap[sessionId]
|
|
270
249
|
})
|
|
271
250
|
}
|
|
272
251
|
// 这里需要轮询从后端获取会话,后端会话更新和创建是异步的,所以要多轮训请求几次
|
|
252
|
+
// 同一个会话只会有一个轮询,轮询期间再次调用只把serializeMethod挂到这个轮询上,等结果回来后依次执行
|
|
273
253
|
let pollRequest = this.pollRequestMap[sessionId]
|
|
274
254
|
if (pollRequest && pollRequest.ps) {
|
|
275
|
-
|
|
255
|
+
if (serializeMethod) {
|
|
256
|
+
pollRequest.serializeMethods.push(serializeMethod)
|
|
257
|
+
}
|
|
276
258
|
return pollRequest.ps
|
|
277
259
|
}
|
|
278
260
|
|
|
@@ -292,50 +274,33 @@ export default class ClientChatSession {
|
|
|
292
274
|
return Promise.reject(error)
|
|
293
275
|
})
|
|
294
276
|
})
|
|
295
|
-
pollRequest.
|
|
296
|
-
pollRequest.serializeTaskMap = {}
|
|
277
|
+
pollRequest.serializeMethods = serializeMethod ? [serializeMethod] : []
|
|
297
278
|
pollRequest.requestCount = 0
|
|
298
279
|
pollRequest.emptyResponseCount = 0
|
|
299
280
|
pollRequest.requestErrorCount = 0
|
|
300
281
|
pollRequest.lastRequestError = null
|
|
301
282
|
pollRequest.startedAt = Date.now()
|
|
302
|
-
this._addGetSessionSerializeTask(pollRequest, serializeMethod, taskOptions)
|
|
303
283
|
this.pollRequestMap[sessionId] = pollRequest
|
|
304
284
|
this._addGetSessionLog('创建会话轮询', {
|
|
305
|
-
sessionId
|
|
306
|
-
messageId: taskOptions.messageId,
|
|
307
|
-
wechatTime: taskOptions.wechatTime,
|
|
308
|
-
taskCount: pollRequest.serializeTasks.length
|
|
285
|
+
sessionId
|
|
309
286
|
})
|
|
310
287
|
pollRequest.ps = pollRequest.start().then(rs => {
|
|
311
288
|
if (!rs.data) {
|
|
312
289
|
return Promise.reject('未找到会话' + sessionId)
|
|
313
290
|
}
|
|
314
291
|
/**
|
|
315
|
-
* 轮询合并上下文,会依次传给每个 serializeMethod(见 client-chat.js
|
|
292
|
+
* 轮询合并上下文,会依次传给每个 serializeMethod(见 client-chat.js onAddMessageSuccess 里 getSession 的回调)
|
|
316
293
|
* baseLastMsgTime 服务端返回的会话 lastMsgTime,用来判断某条消息服务端是否已经算进 unreadMsgCount
|
|
317
|
-
* processedMessageIds 本次轮询期间处理过的所有消息 id
|
|
318
|
-
* skippedMessageIds 服务端返回的会话已经包含(wechatTime <= baseLastMsgTime)、本地不再给会话未读 +1 的消息 id
|
|
319
|
-
* unreadMessageIds 本地给会话未读 +1 的消息 id
|
|
320
294
|
* accountUnreadDelta 本次轮询期间需要累加到工作微信号(账号)未读数量上的条数。
|
|
321
|
-
*
|
|
322
|
-
*
|
|
295
|
+
* 账号未读初始值是登录时取的,不包含本次收到的任何消息,所以服务端已经算进会话 unreadMsgCount 的消息也要算进来;
|
|
296
|
+
* 只有"正在看当前会话被直接标记已读"的消息不算
|
|
323
297
|
*/
|
|
324
298
|
const context = {
|
|
325
299
|
baseLastMsgTime: rs.data.lastMsgTime || 0,
|
|
326
|
-
processedMessageIds: [],
|
|
327
|
-
skippedMessageIds: [],
|
|
328
|
-
unreadMessageIds: [],
|
|
329
300
|
accountUnreadDelta: 0
|
|
330
301
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
})
|
|
334
|
-
serializeTasks.forEach(task => {
|
|
335
|
-
rs = task.serializeMethod(rs, context) || rs
|
|
336
|
-
if (task.messageId) {
|
|
337
|
-
context.processedMessageIds.push(task.messageId)
|
|
338
|
-
}
|
|
302
|
+
pollRequest.serializeMethods.forEach(method => {
|
|
303
|
+
rs = method(rs, context) || rs
|
|
339
304
|
})
|
|
340
305
|
// wechatAccountId 传 null 表示非分页来源,onAddSession 会把未读同步到账号;
|
|
341
306
|
// 同时带上 unreadDelta,让账号只累加本次新增的条数,而不是服务端返回的整个 unreadMsgCount(那里面的存量部分账号初始值已经包含了)
|
|
@@ -353,9 +318,7 @@ export default class ClientChatSession {
|
|
|
353
318
|
lastMsgTime: rs.data.lastMsgTime,
|
|
354
319
|
lastMsgId: rs.data.lastMsgId,
|
|
355
320
|
unreadMsgCount: rs.data.unreadMsgCount,
|
|
356
|
-
|
|
357
|
-
skippedMessageCount: context.skippedMessageIds.length,
|
|
358
|
-
unreadMessageCount: context.unreadMessageIds.length,
|
|
321
|
+
mergedCount: pollRequest.serializeMethods.length,
|
|
359
322
|
accountUnreadDelta: context.accountUnreadDelta,
|
|
360
323
|
hasSessionMap: !!this.sessionMap[sessionId],
|
|
361
324
|
hasAllSessionGroup: !!this._getSessionBySessionGroup(sessionId, ALL_WECHAT_ACCOUNT_ID),
|
|
@@ -437,22 +437,6 @@ class ClientChat {
|
|
|
437
437
|
}
|
|
438
438
|
const localSession = this.session.findSession(({ session }) => session.conversationId === sessionId)
|
|
439
439
|
if (!localSession) {
|
|
440
|
-
if (!this.session.pollRequestMap[sessionId]) {
|
|
441
|
-
this.socket.addLog({
|
|
442
|
-
group: 'client-chat-message:onAddMessageSuccess',
|
|
443
|
-
content: {
|
|
444
|
-
title: '未获取到会话,开始从服务端获取',
|
|
445
|
-
data: {
|
|
446
|
-
sessionId,
|
|
447
|
-
accountId,
|
|
448
|
-
wechatFriendId: data.wechatFriendId,
|
|
449
|
-
wechatAccountId: data.wechatAccountId,
|
|
450
|
-
messageId: data.id,
|
|
451
|
-
wechatTime: data.wechatTime
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
})
|
|
455
|
-
}
|
|
456
440
|
return this.session.getSession(sessionId, (rs, context) => {
|
|
457
441
|
if (rs && rs.data) {
|
|
458
442
|
const isAfterServerMessage = data.wechatTime > context.baseLastMsgTime
|
|
@@ -467,19 +451,16 @@ class ClientChat {
|
|
|
467
451
|
// 正在看这个会话并且允许自动标记已读
|
|
468
452
|
const isCurrentSessionRead = this.sessionManage.currentSession && this.sessionManage.currentSession.conversationId === sessionId && this.shouldMarkCurrentSessionRead(sessionId, data)
|
|
469
453
|
// 会话未读数量:isAfterServerMessage 为 true 表示这条消息比服务端返回的会话 lastMsgTime 新,
|
|
470
|
-
// 服务端返回的 unreadMsgCount 还没算它,需要本地 +1
|
|
454
|
+
// 服务端返回的 unreadMsgCount 还没算它,需要本地 +1;否则服务端已经算进去了,不再重复 +1
|
|
471
455
|
if (!data.isSend && isAfterServerMessage) {
|
|
472
456
|
if (isCurrentSessionRead) {
|
|
473
457
|
rs.data.unreadMsgCount = 0
|
|
474
458
|
} else {
|
|
475
459
|
rs.data.unreadMsgCount = (rs.data.unreadMsgCount || 0) + 1
|
|
476
|
-
context.unreadMessageIds.push(data.id)
|
|
477
460
|
}
|
|
478
|
-
} else {
|
|
479
|
-
context.skippedMessageIds.push(data.id)
|
|
480
461
|
}
|
|
481
462
|
// 账号未读数量:和会话未读数量的判断口径不一样。
|
|
482
|
-
// 账号未读初始值是登录时从服务端取的,不包含这条新消息,所以不管这条消息有没有被服务端算进会话的 unreadMsgCount
|
|
463
|
+
// 账号未读初始值是登录时从服务端取的,不包含这条新消息,所以不管这条消息有没有被服务端算进会话的 unreadMsgCount,
|
|
483
464
|
// 账号都要 +1。唯一不加的情况是"正在看当前会话并被直接标记已读"(此时会话未读被置 0,不会再通过 onSessionReadChange 扣减账号)。
|
|
484
465
|
// 这个累计值会通过 addSession(rs.data, null, { unreadDelta }) 传给 onAddSession,账号只累加这个增量而不是整个 unreadMsgCount
|
|
485
466
|
if (!data.isSend && !(isAfterServerMessage && isCurrentSessionRead)) {
|
|
@@ -487,9 +468,6 @@ class ClientChat {
|
|
|
487
468
|
}
|
|
488
469
|
}
|
|
489
470
|
return rs
|
|
490
|
-
}, {
|
|
491
|
-
messageId: data.id,
|
|
492
|
-
wechatTime: data.wechatTime
|
|
493
471
|
}).catch(() => {})
|
|
494
472
|
} else {
|
|
495
473
|
this.session.updateSession(sessionId, ({ session }) => {
|
|
@@ -584,22 +562,6 @@ class ClientChat {
|
|
|
584
562
|
// 更新会话未读消息数量
|
|
585
563
|
const localSession = this.session.findSession(({ session }) => session.conversationId === sessionId)
|
|
586
564
|
if (!localSession) {
|
|
587
|
-
if (!this.session.pollRequestMap[sessionId]) {
|
|
588
|
-
this.socket.addLog({
|
|
589
|
-
group: 'client-chat-message:onAddMessageSuccess',
|
|
590
|
-
content: {
|
|
591
|
-
title: '未获取到会话,开始从服务端获取',
|
|
592
|
-
data: {
|
|
593
|
-
sessionId,
|
|
594
|
-
accountId,
|
|
595
|
-
wechatChatroomId: data.wechatChatroomId,
|
|
596
|
-
wechatAccountId: data.wechatAccountId,
|
|
597
|
-
messageId: data.id,
|
|
598
|
-
wechatTime: data.wechatTime
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
})
|
|
602
|
-
}
|
|
603
565
|
return this.session.getSession(sessionId, (rs, context) => {
|
|
604
566
|
if (rs && rs.data) {
|
|
605
567
|
const isAfterServerMessage = data.wechatTime > context.baseLastMsgTime
|
|
@@ -614,22 +576,19 @@ class ClientChat {
|
|
|
614
576
|
// 正在看这个会话并且允许自动标记已读
|
|
615
577
|
const isCurrentSessionRead = this.sessionManage.currentSession && this.sessionManage.currentSession.conversationId === sessionId && this.shouldMarkCurrentSessionRead(sessionId, data)
|
|
616
578
|
// 会话未读数量:isAfterServerMessage 为 true 表示这条消息比服务端返回的会话 lastMsgTime 新,
|
|
617
|
-
// 服务端返回的 unreadMsgCount 还没算它,需要本地 +1
|
|
579
|
+
// 服务端返回的 unreadMsgCount 还没算它,需要本地 +1;否则服务端已经算进去了,不再重复 +1
|
|
618
580
|
if (!data.isSend && isAfterServerMessage) {
|
|
619
581
|
if (isCurrentSessionRead) {
|
|
620
582
|
rs.data.unreadMsgCount = 0
|
|
621
583
|
} else {
|
|
622
584
|
rs.data.unreadMsgCount = (rs.data.unreadMsgCount || 0) + 1
|
|
623
|
-
context.unreadMessageIds.push(data.id)
|
|
624
585
|
if (atMessage) {
|
|
625
586
|
rs.data.lastAtMsgContent = appendLastAtMsgContent(rs.data.lastAtMsgContent, atMessage)
|
|
626
587
|
}
|
|
627
588
|
}
|
|
628
|
-
} else {
|
|
629
|
-
context.skippedMessageIds.push(data.id)
|
|
630
589
|
}
|
|
631
590
|
// 账号未读数量:和会话未读数量的判断口径不一样。
|
|
632
|
-
// 账号未读初始值是登录时从服务端取的,不包含这条新消息,所以不管这条消息有没有被服务端算进会话的 unreadMsgCount
|
|
591
|
+
// 账号未读初始值是登录时从服务端取的,不包含这条新消息,所以不管这条消息有没有被服务端算进会话的 unreadMsgCount,
|
|
633
592
|
// 账号都要 +1。唯一不加的情况是"正在看当前会话并被直接标记已读"(此时会话未读被置 0,不会再通过 onSessionReadChange 扣减账号)。
|
|
634
593
|
// 这个累计值会通过 addSession(rs.data, null, { unreadDelta }) 传给 onAddSession,账号只累加这个增量而不是整个 unreadMsgCount
|
|
635
594
|
if (!data.isSend && !(isAfterServerMessage && isCurrentSessionRead)) {
|
|
@@ -637,9 +596,6 @@ class ClientChat {
|
|
|
637
596
|
}
|
|
638
597
|
}
|
|
639
598
|
return rs
|
|
640
|
-
}, {
|
|
641
|
-
messageId: data.id,
|
|
642
|
-
wechatTime: data.wechatTime
|
|
643
599
|
}).catch(() => {})
|
|
644
600
|
} else {
|
|
645
601
|
this.session.updateSession(sessionId, ({ session }) => {
|
|
@@ -84,13 +84,15 @@ SDK 里维护着两套彼此独立的本地"账本":
|
|
|
84
84
|
```js
|
|
85
85
|
// 会话未读:只在服务端没算过这条消息时 +1(原逻辑不变)
|
|
86
86
|
if (!data.isSend && isAfterServerMessage) { ... }
|
|
87
|
-
//
|
|
87
|
+
// 账号未读:不管服务端是否已经算进会话 unreadMsgCount 都 +1,只有"正在看当前会话被直接标记已读"不加
|
|
88
88
|
if (!data.isSend && !(isAfterServerMessage && isCurrentSessionRead)) {
|
|
89
89
|
context.accountUnreadDelta += 1
|
|
90
90
|
}
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
-
注意 `accountUnreadDelta` **不等于** `
|
|
93
|
+
注意 `accountUnreadDelta` **不等于** 本次给会话 `unreadMsgCount` +1 的条数:`isAfterServerMessage` 为 false 的消息表示服务端返回的会话已经把它算进 `unreadMsgCount`,但账号初始值是登录时取的,仍然不含这条,所以账号还是要 +1。
|
|
94
|
+
|
|
95
|
+
`getSession(sessionId, serializeMethod)` 只按 `sessionId` 聚合:同一个会话轮询期间的所有回调按调用顺序依次执行,不再依赖消息 id / 时间做去重或排序(消息层 `addMessage` 已按 id 去重)。
|
|
94
96
|
|
|
95
97
|
- `onAddSession`(第 132 行附近):
|
|
96
98
|
|