@aochuang/client-sdk 1.0.400 → 1.0.401
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/wechat-chat-control/location/location.vue +11 -3
- package/package.json +1 -1
- package/services/client-chat/client-chat-wechat/client-chat-account.js +37 -7
- package/services/client-chat/client-chat-wechat/client-chat-message.js +175 -18
- package/services/client-chat/client-chat-wechat/client-chat-session.js +91 -12
- package/services/client-chat/client-chat-wechat/client-chat-socket.js +80 -22
- package/services/client-chat/client-chat-wechat/client-chat.js +59 -11
- package/services/socket/socket.js +56 -7
- package/utils/log/constants.js +13 -0
- package/utils/log/export.js +88 -0
- package/utils/log/findings.md +141 -0
- package/utils/log/index.js +331 -0
- package/utils/log/indexed-db.js +228 -0
- package/utils/log/progress.md +267 -0
- package/utils/log/serialize.js +146 -0
- package/utils/log/task_plan.md +149 -0
- package/utils/log//345/210/206/346/236/220/344/270/216/344/274/230/345/214/226/346/226/271/346/241/210.md +303 -0
- package/utils/log//346/212/200/346/234/257/346/226/271/346/241/210/346/226/207/346/241/243.md +201 -0
- package/utils/log//346/236/266/346/236/204/346/226/207/346/241/243.md +169 -0
- package/utils/log//351/234/200/346/261/202/346/226/207/346/241/243.md +124 -0
- package/utils/log.js +2 -626
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="sdk-chat-control-location" :class="['sdk-chat-control-location--' + type]">
|
|
3
|
-
<template v-if="type === 'default'">
|
|
3
|
+
<template v-if="type === 'default' || type === 'thumb'">
|
|
4
4
|
<div class="sdk-chat-control-location__main">
|
|
5
5
|
<div class="sdk-chat-control-location__head">
|
|
6
6
|
<h4 class="sdk-chat-control-location__title">{{address}}</h4>
|
|
@@ -46,7 +46,7 @@ export default {
|
|
|
46
46
|
type: String,
|
|
47
47
|
default: 'default',
|
|
48
48
|
validator (value) {
|
|
49
|
-
return ['quote', 'default'].includes(value)
|
|
49
|
+
return ['quote', 'default', 'thumb'].includes(value)
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
52
|
/**
|
|
@@ -89,7 +89,8 @@ export default {
|
|
|
89
89
|
}
|
|
90
90
|
</script>
|
|
91
91
|
<style lang="less">
|
|
92
|
-
.sdk-chat-control-location--default
|
|
92
|
+
.sdk-chat-control-location--default,
|
|
93
|
+
.sdk-chat-control-location--thumb {
|
|
93
94
|
.sdk-chat-control-location__body{
|
|
94
95
|
line-height: 0;
|
|
95
96
|
}
|
|
@@ -149,6 +150,13 @@ export default {
|
|
|
149
150
|
z-index: 3;
|
|
150
151
|
}
|
|
151
152
|
}
|
|
153
|
+
.sdk-chat-control-location--thumb {
|
|
154
|
+
display: inline-block;
|
|
155
|
+
overflow: hidden;
|
|
156
|
+
background-color: #fff;
|
|
157
|
+
border: 1px solid #eee;
|
|
158
|
+
border-radius: 4px;
|
|
159
|
+
}
|
|
152
160
|
.sdk-chat-control-location__body{
|
|
153
161
|
overflow: hidden;
|
|
154
162
|
}
|
package/package.json
CHANGED
|
@@ -56,15 +56,30 @@ export default class ClientChatAccount {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
_addUnreadMessageNumLog (title, data) {
|
|
59
|
-
|
|
59
|
+
try {
|
|
60
|
+
if (!this.onUnreadMessageNumLog) {
|
|
61
|
+
return
|
|
62
|
+
}
|
|
60
63
|
this.onUnreadMessageNumLog({
|
|
61
|
-
group: '
|
|
62
|
-
content: {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
64
|
+
group: 'diagnostic:account_unread_changed',
|
|
65
|
+
content: Object.assign({
|
|
66
|
+
event: 'account_unread_changed',
|
|
67
|
+
title
|
|
68
|
+
}, data)
|
|
66
69
|
})
|
|
67
|
-
}
|
|
70
|
+
} catch (error) {}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
_addDiagnosticLog (event, data) {
|
|
74
|
+
try {
|
|
75
|
+
if (!this.onUnreadMessageNumLog) {
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
this.onUnreadMessageNumLog({
|
|
79
|
+
group: `diagnostic:${event}`,
|
|
80
|
+
content: Object.assign({ event }, data)
|
|
81
|
+
})
|
|
82
|
+
} catch (error) {}
|
|
68
83
|
}
|
|
69
84
|
|
|
70
85
|
get accountData () {
|
|
@@ -198,6 +213,7 @@ export default class ClientChatAccount {
|
|
|
198
213
|
}
|
|
199
214
|
|
|
200
215
|
refreshAllAccountUnreadMesageNum () {
|
|
216
|
+
const startedAt = Date.now()
|
|
201
217
|
this.getAccountUnreadMessageNumMethod({
|
|
202
218
|
wechatAccountIds: Object.keys(this.accountMap)
|
|
203
219
|
}).then(rs => {
|
|
@@ -216,10 +232,17 @@ export default class ClientChatAccount {
|
|
|
216
232
|
source: 'refreshAll',
|
|
217
233
|
accounts: nextData
|
|
218
234
|
})
|
|
235
|
+
}).catch(error => {
|
|
236
|
+
this._addDiagnosticLog('account_unread_refresh_failed', {
|
|
237
|
+
scope: 'all',
|
|
238
|
+
durationMs: Date.now() - startedAt,
|
|
239
|
+
errorType: error && (error.name || error.code) || typeof error
|
|
240
|
+
})
|
|
219
241
|
})
|
|
220
242
|
}
|
|
221
243
|
|
|
222
244
|
refreshAccountUnreadMessageNum (params) {
|
|
245
|
+
const startedAt = Date.now()
|
|
223
246
|
const { wechatAccountId, ...nextParams } = params
|
|
224
247
|
this.getAccountUnreadMessageNumMethod(Object.assign({
|
|
225
248
|
wechatAccountIds: [wechatAccountId]
|
|
@@ -251,6 +274,13 @@ export default class ClientChatAccount {
|
|
|
251
274
|
before: before ? { num: before.num, muteNum: before.muteNum } : null,
|
|
252
275
|
after: { num: after.num, muteNum: after.muteNum }
|
|
253
276
|
})
|
|
277
|
+
}).catch(error => {
|
|
278
|
+
this._addDiagnosticLog('account_unread_refresh_failed', {
|
|
279
|
+
scope: 'single',
|
|
280
|
+
wechatAccountId,
|
|
281
|
+
durationMs: Date.now() - startedAt,
|
|
282
|
+
errorType: error && (error.name || error.code) || typeof error
|
|
283
|
+
})
|
|
254
284
|
})
|
|
255
285
|
}
|
|
256
286
|
|
|
@@ -54,6 +54,7 @@ export default class ClientChatMessage {
|
|
|
54
54
|
groupField: null, // 分组的字段
|
|
55
55
|
checkMessageSendResultMethod: null, // 检查消息发送结果
|
|
56
56
|
loadLossMessageDataMethod: null, // 加载丢失的消息数据,例如socket断开期间没有收到的数据
|
|
57
|
+
getSessionIdMethod: null,
|
|
57
58
|
onAddMessageSuccess: null // 新增消息成功回调事件
|
|
58
59
|
}, options)
|
|
59
60
|
if (!options.clientChat) {
|
|
@@ -68,10 +69,72 @@ export default class ClientChatMessage {
|
|
|
68
69
|
this.sortField = options.sortField
|
|
69
70
|
this.checkMessageSendResultMethod = options.checkMessageSendResultMethod
|
|
70
71
|
this.loadLossMessageDataMethod = options.loadLossMessageDataMethod
|
|
72
|
+
this.getSessionIdMethod = options.getSessionIdMethod
|
|
71
73
|
this.onAddMessageSuccess = options.onAddMessageSuccess
|
|
72
74
|
this.event = new Event()
|
|
73
75
|
}
|
|
74
76
|
|
|
77
|
+
addDiagnosticLog (event, data = {}) {
|
|
78
|
+
if (!this.clientChat || !this.clientChat.socket || !this.clientChat.socket.addLog) {
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
this.clientChat.socket.addLog({
|
|
83
|
+
group: `diagnostic:${event}`,
|
|
84
|
+
content: Object.assign({
|
|
85
|
+
event
|
|
86
|
+
}, data)
|
|
87
|
+
})
|
|
88
|
+
} catch (error) {}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
getMessageDiagnosticData (data, extra = {}) {
|
|
92
|
+
let sessionId
|
|
93
|
+
try {
|
|
94
|
+
sessionId = this.getSessionIdMethod && this.getSessionIdMethod(data)
|
|
95
|
+
} catch (error) {}
|
|
96
|
+
return Object.assign({
|
|
97
|
+
messageId: data && data.id,
|
|
98
|
+
msgSvrId: data && data.msgSvrId,
|
|
99
|
+
sessionId
|
|
100
|
+
}, extra)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
handleSessionUpdateError (data, error) {
|
|
104
|
+
this.addDiagnosticLog('message_session_update_failed', this.getMessageDiagnosticData(data, {
|
|
105
|
+
errorType: error && (error.name || error.code) || typeof error
|
|
106
|
+
}))
|
|
107
|
+
try {
|
|
108
|
+
console.error('[client-chat-message] onAddMessageSuccess error', {
|
|
109
|
+
messageId: data && data.id,
|
|
110
|
+
error
|
|
111
|
+
})
|
|
112
|
+
} catch (consoleError) {}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
getGroupMessageSummary (groupId) {
|
|
116
|
+
const summary = {
|
|
117
|
+
count: 0,
|
|
118
|
+
latestMessageId: null,
|
|
119
|
+
latestMessageTime: null
|
|
120
|
+
}
|
|
121
|
+
if (!groupId) {
|
|
122
|
+
return summary
|
|
123
|
+
}
|
|
124
|
+
Object.keys(this.messageMap).forEach(id => {
|
|
125
|
+
const message = this.messageMap[id]
|
|
126
|
+
if (!message || message[this.groupField] !== groupId) {
|
|
127
|
+
return
|
|
128
|
+
}
|
|
129
|
+
summary.count++
|
|
130
|
+
if (!summary.latestMessageTime || message[this.sortField] > summary.latestMessageTime) {
|
|
131
|
+
summary.latestMessageId = message.id
|
|
132
|
+
summary.latestMessageTime = message[this.sortField]
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
return summary
|
|
136
|
+
}
|
|
137
|
+
|
|
75
138
|
getSortField (time) {
|
|
76
139
|
const step = 1000 * 60 * 60 * 24
|
|
77
140
|
const day = Math.floor(time / step)
|
|
@@ -110,9 +173,15 @@ export default class ClientChatMessage {
|
|
|
110
173
|
*/
|
|
111
174
|
addMessage (data, fireEvent) {
|
|
112
175
|
if (!data || !data.id || !data[this.groupField] || !data[this.sortField]) {
|
|
176
|
+
this.addDiagnosticLog('message_rejected', this.getMessageDiagnosticData(data, {
|
|
177
|
+
reason: 'missing_required_field'
|
|
178
|
+
}))
|
|
113
179
|
throw new Error('缺少必须参数')
|
|
114
180
|
}
|
|
115
181
|
if (this.messageMap[data.id]) {
|
|
182
|
+
this.addDiagnosticLog('message_rejected', this.getMessageDiagnosticData(data, {
|
|
183
|
+
reason: 'duplicate_message_id'
|
|
184
|
+
}))
|
|
116
185
|
return
|
|
117
186
|
}
|
|
118
187
|
if (this.tempMessageMap[data.id]) {
|
|
@@ -133,11 +202,22 @@ export default class ClientChatMessage {
|
|
|
133
202
|
Vue.set(this.data.messageData[groupField][sortFields.day], sortFields.milliseconds, [])
|
|
134
203
|
}
|
|
135
204
|
if (this.data.messageData[groupField][sortFields.day][sortFields.milliseconds].some(v => v.id === data.id)) {
|
|
205
|
+
this.addDiagnosticLog('message_rejected', this.getMessageDiagnosticData(data, {
|
|
206
|
+
reason: 'duplicate_time_bucket'
|
|
207
|
+
}))
|
|
136
208
|
return
|
|
137
209
|
}
|
|
138
210
|
this.data.messageData[groupField][sortFields.day][sortFields.milliseconds].push(data)
|
|
139
211
|
this.messageMap[data.id] = data
|
|
140
212
|
this.setLastMessageTime(groupField, data[this.sortField], data)
|
|
213
|
+
const storedDiagnostic = {}
|
|
214
|
+
if (isBeforeLastMessage) {
|
|
215
|
+
storedDiagnostic.outOfOrder = true
|
|
216
|
+
}
|
|
217
|
+
if (fireEvent === false) {
|
|
218
|
+
storedDiagnostic.eventDispatch = 'disabled'
|
|
219
|
+
}
|
|
220
|
+
this.addDiagnosticLog('message_stored', this.getMessageDiagnosticData(data, storedDiagnostic))
|
|
141
221
|
// 发送中的消息并且不是临时占位消息,需要增加轮询结果逻辑
|
|
142
222
|
if (data.isSend && data.sendStatus === 1 && !data._temp) {
|
|
143
223
|
// 排除一下系统消息,因为后端系统消息的sendStatus永远为1,这会导致前端总是轮训去调用接口检查消息状态
|
|
@@ -149,26 +229,49 @@ export default class ClientChatMessage {
|
|
|
149
229
|
// 先执行onAddMessageSuccess再发add-message事件,保证会话的getSession轮询先由这里发起、更新会话的回调排在最前面,
|
|
150
230
|
// 外部监听add-message后再调getSession只是复用同一个轮询
|
|
151
231
|
// try/catch是为了避免回调里的异常把add-message事件吞掉(外部的新消息提醒、本地消息缓存都依赖这个事件)
|
|
232
|
+
let sessionUpdateResult
|
|
152
233
|
try {
|
|
153
|
-
this.onAddMessageSuccess && this.onAddMessageSuccess({
|
|
234
|
+
sessionUpdateResult = this.onAddMessageSuccess && this.onAddMessageSuccess({
|
|
154
235
|
data,
|
|
155
236
|
lastMessageTime,
|
|
156
237
|
isBeforeLastMessage
|
|
157
238
|
})
|
|
158
239
|
} catch (error) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
240
|
+
this.handleSessionUpdateError(data, error)
|
|
241
|
+
}
|
|
242
|
+
if (sessionUpdateResult && typeof sessionUpdateResult.catch === 'function') {
|
|
243
|
+
sessionUpdateResult.catch(error => {
|
|
244
|
+
this.handleSessionUpdateError(data, error)
|
|
162
245
|
})
|
|
163
246
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
})
|
|
247
|
+
// 如果消息包含这种情况,就不能往外发送add-message事件
|
|
248
|
+
// 因为例如群发的消息,他没有会话,导致前端在处理来了新消息通知铃声提醒,获取会话一直获取不到,然后会总是发送请求
|
|
249
|
+
let suppressedReason = null
|
|
250
|
+
if (isBeforeLastMessage) {
|
|
251
|
+
suppressedReason = 'out_of_order'
|
|
252
|
+
} else if (isAutoReadMessage(data)) {
|
|
253
|
+
suppressedReason = 'auto_read'
|
|
254
|
+
} else if (shouldIgnoreSessionByMessage(data)) {
|
|
255
|
+
suppressedReason = 'ignore_session'
|
|
256
|
+
} else if (isDeletedMsg(data)) {
|
|
257
|
+
suppressedReason = 'deleted'
|
|
258
|
+
} else if (isBlockedMsg(data)) {
|
|
259
|
+
suppressedReason = 'blocked'
|
|
260
|
+
}
|
|
261
|
+
if (!suppressedReason) {
|
|
262
|
+
this.event && this.event.emit('add-message', {
|
|
263
|
+
data
|
|
264
|
+
})
|
|
265
|
+
this.addDiagnosticLog('message_event_emitted', this.getMessageDiagnosticData(data))
|
|
266
|
+
} else {
|
|
267
|
+
const suppressedDiagnostic = { reason: suppressedReason }
|
|
268
|
+
if (suppressedReason === 'out_of_order') {
|
|
269
|
+
suppressedDiagnostic.messageTime = data[this.sortField]
|
|
270
|
+
suppressedDiagnostic.lastMessageTime = lastMessageTime
|
|
271
|
+
}
|
|
272
|
+
this.addDiagnosticLog('message_event_suppressed', this.getMessageDiagnosticData(data, suppressedDiagnostic))
|
|
273
|
+
}
|
|
170
274
|
}
|
|
171
|
-
}
|
|
172
275
|
}
|
|
173
276
|
|
|
174
277
|
removeMessage (id) {
|
|
@@ -421,8 +524,54 @@ export default class ClientChatMessage {
|
|
|
421
524
|
}
|
|
422
525
|
|
|
423
526
|
reloadMessageData (params) {
|
|
527
|
+
const startedAt = Date.now()
|
|
528
|
+
const targetId = params && params[this.groupField]
|
|
529
|
+
const totalMemoryBefore = Object.keys(this.messageMap).length
|
|
530
|
+
const targetBefore = this.getGroupMessageSummary(targetId)
|
|
424
531
|
this.clearMessage()
|
|
425
|
-
return this.loadMessageData(params)
|
|
532
|
+
return this.loadMessageData(params).then(data => {
|
|
533
|
+
const targetAfter = this.getGroupMessageSummary(targetId)
|
|
534
|
+
this.addDiagnosticLog('chat_reload_result', {
|
|
535
|
+
result: 'success',
|
|
536
|
+
targetField: this.groupField,
|
|
537
|
+
targetId,
|
|
538
|
+
totalMemoryBefore,
|
|
539
|
+
targetMemoryBefore: targetBefore.count,
|
|
540
|
+
latestMessageIdBefore: targetBefore.latestMessageId,
|
|
541
|
+
latestMessageTimeBefore: targetBefore.latestMessageTime,
|
|
542
|
+
clearedCount: totalMemoryBefore,
|
|
543
|
+
loadedCount: Array.isArray(data) ? data.length : 0,
|
|
544
|
+
finalTargetCount: targetAfter.count,
|
|
545
|
+
latestMessageIdAfter: targetAfter.latestMessageId,
|
|
546
|
+
latestMessageTimeAfter: targetAfter.latestMessageTime,
|
|
547
|
+
upward: params && params.upward,
|
|
548
|
+
smallWechatTime: params && params.smallWechatTime,
|
|
549
|
+
bigWechatTime: params && params.bigWechatTime,
|
|
550
|
+
durationMs: Date.now() - startedAt
|
|
551
|
+
})
|
|
552
|
+
return data
|
|
553
|
+
}, error => {
|
|
554
|
+
const targetAfter = this.getGroupMessageSummary(targetId)
|
|
555
|
+
this.addDiagnosticLog('chat_reload_result', {
|
|
556
|
+
result: 'failed',
|
|
557
|
+
targetField: this.groupField,
|
|
558
|
+
targetId,
|
|
559
|
+
totalMemoryBefore,
|
|
560
|
+
targetMemoryBefore: targetBefore.count,
|
|
561
|
+
latestMessageIdBefore: targetBefore.latestMessageId,
|
|
562
|
+
latestMessageTimeBefore: targetBefore.latestMessageTime,
|
|
563
|
+
clearedCount: totalMemoryBefore,
|
|
564
|
+
finalTargetCount: targetAfter.count,
|
|
565
|
+
latestMessageIdAfter: targetAfter.latestMessageId,
|
|
566
|
+
latestMessageTimeAfter: targetAfter.latestMessageTime,
|
|
567
|
+
upward: params && params.upward,
|
|
568
|
+
smallWechatTime: params && params.smallWechatTime,
|
|
569
|
+
bigWechatTime: params && params.bigWechatTime,
|
|
570
|
+
durationMs: Date.now() - startedAt,
|
|
571
|
+
errorType: error && (error.name || error.code) || typeof error
|
|
572
|
+
})
|
|
573
|
+
return Promise.reject(error)
|
|
574
|
+
})
|
|
426
575
|
}
|
|
427
576
|
|
|
428
577
|
/***
|
|
@@ -587,18 +736,26 @@ export default class ClientChatMessage {
|
|
|
587
736
|
if (!this.loadLossMessageDataMethod) {
|
|
588
737
|
throw new Error('[ClientChatWechat]缺少loadLossMessageDataMethod方法定义')
|
|
589
738
|
}
|
|
590
|
-
this.loadLossMessageDataMethod({
|
|
739
|
+
return this.loadLossMessageDataMethod({
|
|
591
740
|
lastReceiveMessageTime: this.data.lastReceiveMessageTime
|
|
592
741
|
}).then((rs) => {
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
742
|
+
const result = {
|
|
743
|
+
returnedCount: 0,
|
|
744
|
+
insertedCount: 0,
|
|
745
|
+
duplicateCount: 0
|
|
596
746
|
}
|
|
597
|
-
|
|
598
|
-
|
|
747
|
+
const messages = rs && Array.isArray(rs.data) ? rs.data : []
|
|
748
|
+
result.returnedCount = messages.length
|
|
749
|
+
// 做个去重
|
|
750
|
+
const nextMessages = messages.filter(v => !this.messageMap[v.id])
|
|
751
|
+
result.insertedCount = nextMessages.length
|
|
752
|
+
result.duplicateCount = messages.length - nextMessages.length
|
|
753
|
+
if (nextMessages.length) {
|
|
754
|
+
nextMessages.forEach(item => {
|
|
599
755
|
this.addMessage(item)
|
|
600
756
|
})
|
|
601
757
|
}
|
|
758
|
+
return result
|
|
602
759
|
})
|
|
603
760
|
}
|
|
604
761
|
|
|
@@ -4,6 +4,8 @@ import { createSessionId } from './utils.js'
|
|
|
4
4
|
import { createPollRequest } from '../../../utils/util.js'
|
|
5
5
|
|
|
6
6
|
const ALL_WECHAT_ACCOUNT_ID = 'all'
|
|
7
|
+
const GET_SESSION_POLL_SPAN_TIME = 5 * 1000
|
|
8
|
+
const GET_SESSION_POLL_TIMEOUT = 10 * 60 * 1000
|
|
7
9
|
|
|
8
10
|
const loopLoadAssignSessionData = (fetchFn, params) => {
|
|
9
11
|
let lastPs = null
|
|
@@ -230,20 +232,21 @@ export default class ClientChatSession {
|
|
|
230
232
|
})
|
|
231
233
|
}
|
|
232
234
|
|
|
233
|
-
_addGetSessionLog (
|
|
235
|
+
_addGetSessionLog (event, data) {
|
|
234
236
|
if (this.onGetSessionLog) {
|
|
235
237
|
this.onGetSessionLog({
|
|
236
|
-
group:
|
|
237
|
-
content: {
|
|
238
|
-
title,
|
|
239
|
-
data
|
|
240
|
-
}
|
|
238
|
+
group: `diagnostic:${event}`,
|
|
239
|
+
content: Object.assign({ event }, data)
|
|
241
240
|
})
|
|
242
241
|
}
|
|
243
242
|
}
|
|
244
243
|
|
|
245
244
|
getSession (sessionId, serializeMethod) {
|
|
246
245
|
if (this.sessionMap[sessionId]) {
|
|
246
|
+
this._addGetSessionLog('session_resolved', {
|
|
247
|
+
sessionId,
|
|
248
|
+
source: 'memory'
|
|
249
|
+
})
|
|
247
250
|
return Promise.resolve({
|
|
248
251
|
data: this.sessionMap[sessionId]
|
|
249
252
|
})
|
|
@@ -255,6 +258,10 @@ export default class ClientChatSession {
|
|
|
255
258
|
if (serializeMethod) {
|
|
256
259
|
pollRequest.serializeMethods.push(serializeMethod)
|
|
257
260
|
}
|
|
261
|
+
this._addGetSessionLog('session_poll_joined', {
|
|
262
|
+
sessionId,
|
|
263
|
+
mergedCount: pollRequest.serializeMethods.length
|
|
264
|
+
})
|
|
258
265
|
return pollRequest.ps
|
|
259
266
|
}
|
|
260
267
|
|
|
@@ -273,7 +280,7 @@ export default class ClientChatSession {
|
|
|
273
280
|
pollRequest.lastRequestError = error && (error.message || error.errMsg || error.toString && error.toString()) || error
|
|
274
281
|
return Promise.reject(error)
|
|
275
282
|
})
|
|
276
|
-
})
|
|
283
|
+
}, GET_SESSION_POLL_SPAN_TIME, GET_SESSION_POLL_TIMEOUT)
|
|
277
284
|
pollRequest.serializeMethods = serializeMethod ? [serializeMethod] : []
|
|
278
285
|
pollRequest.requestCount = 0
|
|
279
286
|
pollRequest.emptyResponseCount = 0
|
|
@@ -281,8 +288,10 @@ export default class ClientChatSession {
|
|
|
281
288
|
pollRequest.lastRequestError = null
|
|
282
289
|
pollRequest.startedAt = Date.now()
|
|
283
290
|
this.pollRequestMap[sessionId] = pollRequest
|
|
284
|
-
this._addGetSessionLog('
|
|
285
|
-
sessionId
|
|
291
|
+
this._addGetSessionLog('session_poll_started', {
|
|
292
|
+
sessionId,
|
|
293
|
+
spanTime: GET_SESSION_POLL_SPAN_TIME,
|
|
294
|
+
timeout: GET_SESSION_POLL_TIMEOUT
|
|
286
295
|
})
|
|
287
296
|
pollRequest.ps = pollRequest.start().then(rs => {
|
|
288
297
|
if (!rs.data) {
|
|
@@ -308,7 +317,7 @@ export default class ClientChatSession {
|
|
|
308
317
|
unreadDelta: context.accountUnreadDelta
|
|
309
318
|
})
|
|
310
319
|
const wechatAccountId = rs.data.wechatAccountId
|
|
311
|
-
this._addGetSessionLog('
|
|
320
|
+
this._addGetSessionLog('session_poll_completed', {
|
|
312
321
|
sessionId,
|
|
313
322
|
requestCount: pollRequest.requestCount,
|
|
314
323
|
emptyResponseCount: pollRequest.emptyResponseCount,
|
|
@@ -326,8 +335,10 @@ export default class ClientChatSession {
|
|
|
326
335
|
})
|
|
327
336
|
return rs
|
|
328
337
|
}).catch((error) => {
|
|
329
|
-
this._addGetSessionLog('
|
|
338
|
+
this._addGetSessionLog('session_poll_failed', {
|
|
330
339
|
sessionId,
|
|
340
|
+
isTimeout: error === 'timeout',
|
|
341
|
+
timeout: GET_SESSION_POLL_TIMEOUT,
|
|
331
342
|
requestCount: pollRequest.requestCount,
|
|
332
343
|
emptyResponseCount: pollRequest.emptyResponseCount,
|
|
333
344
|
requestErrorCount: pollRequest.requestErrorCount,
|
|
@@ -924,6 +935,16 @@ export default class ClientChatSession {
|
|
|
924
935
|
}
|
|
925
936
|
}
|
|
926
937
|
if (changeProps && Object.keys(changeProps).length) {
|
|
938
|
+
if (changeProps.unreadMsgCount) {
|
|
939
|
+
this._addGetSessionLog('session_unread_changed', {
|
|
940
|
+
sessionId,
|
|
941
|
+
wechatAccountId: session.wechatAccountId,
|
|
942
|
+
source: 'updateSession',
|
|
943
|
+
before: changeProps.unreadMsgCount.before,
|
|
944
|
+
after: changeProps.unreadMsgCount.after,
|
|
945
|
+
delta: (changeProps.unreadMsgCount.after || 0) - (changeProps.unreadMsgCount.before || 0)
|
|
946
|
+
})
|
|
947
|
+
}
|
|
927
948
|
this.onUpdateSession && this.onUpdateSession({
|
|
928
949
|
session,
|
|
929
950
|
changeProps,
|
|
@@ -943,10 +964,30 @@ export default class ClientChatSession {
|
|
|
943
964
|
if (!session) {
|
|
944
965
|
return
|
|
945
966
|
}
|
|
967
|
+
const oldUnreadMsgCount = session.unreadMsgCount || 0
|
|
968
|
+
this._addGetSessionLog('session_read_requested', {
|
|
969
|
+
sessionId,
|
|
970
|
+
wechatAccountId: session.wechatAccountId,
|
|
971
|
+
oldUnreadMsgCount
|
|
972
|
+
})
|
|
946
973
|
return this.updateSessionRead({
|
|
947
974
|
conversationId: sessionId
|
|
948
975
|
}).then(() => {
|
|
949
976
|
this.markSessionRead(sessionId)
|
|
977
|
+
this._addGetSessionLog('session_read_applied', {
|
|
978
|
+
sessionId,
|
|
979
|
+
wechatAccountId: session.wechatAccountId,
|
|
980
|
+
oldUnreadMsgCount,
|
|
981
|
+
unreadMsgCount: 0
|
|
982
|
+
})
|
|
983
|
+
}).catch(error => {
|
|
984
|
+
this._addGetSessionLog('session_read_failed', {
|
|
985
|
+
sessionId,
|
|
986
|
+
wechatAccountId: session.wechatAccountId,
|
|
987
|
+
oldUnreadMsgCount,
|
|
988
|
+
error: error && (error.message || error.errMsg || error.toString && error.toString()) || error
|
|
989
|
+
})
|
|
990
|
+
return Promise.reject(error)
|
|
950
991
|
})
|
|
951
992
|
}
|
|
952
993
|
|
|
@@ -1137,6 +1178,13 @@ export default class ClientChatSession {
|
|
|
1137
1178
|
lastUpdateTime: null // 最后更新时间
|
|
1138
1179
|
})
|
|
1139
1180
|
this.data.loading = true
|
|
1181
|
+
const startedAt = Date.now()
|
|
1182
|
+
this._addGetSessionLog('session_list_requested', {
|
|
1183
|
+
mode: 'reload',
|
|
1184
|
+
wechatAccountId: params.wechatAccountId,
|
|
1185
|
+
lastUpdateTime: params.lastUpdateTime,
|
|
1186
|
+
size: params.size
|
|
1187
|
+
})
|
|
1140
1188
|
const ps1 = this.loadSessionData(params, {
|
|
1141
1189
|
lastSession: null,
|
|
1142
1190
|
lastUpdateSession: null,
|
|
@@ -1144,7 +1192,7 @@ export default class ClientChatSession {
|
|
|
1144
1192
|
})
|
|
1145
1193
|
ps1.then((rs) => {
|
|
1146
1194
|
this.setSessionData(rs.data, params.wechatAccountId || ALL_WECHAT_ACCOUNT_ID)
|
|
1147
|
-
})
|
|
1195
|
+
}, () => {})
|
|
1148
1196
|
if (this.cancelLoadDataRequest) {
|
|
1149
1197
|
this.cancelLoadDataRequest()
|
|
1150
1198
|
}
|
|
@@ -1153,9 +1201,21 @@ export default class ClientChatSession {
|
|
|
1153
1201
|
}
|
|
1154
1202
|
return Promise.all([ps1]).then((rs) => {
|
|
1155
1203
|
this.data.loading = false
|
|
1204
|
+
this._addGetSessionLog('session_list_applied', {
|
|
1205
|
+
mode: 'reload',
|
|
1206
|
+
wechatAccountId: params.wechatAccountId,
|
|
1207
|
+
count: rs[0] && rs[0].data && rs[0].data.length || 0,
|
|
1208
|
+
duration: Date.now() - startedAt
|
|
1209
|
+
})
|
|
1156
1210
|
return rs[0]
|
|
1157
1211
|
}, err => {
|
|
1158
1212
|
this.data.loading = false
|
|
1213
|
+
this._addGetSessionLog('session_list_failed', {
|
|
1214
|
+
mode: 'reload',
|
|
1215
|
+
wechatAccountId: params.wechatAccountId,
|
|
1216
|
+
duration: Date.now() - startedAt,
|
|
1217
|
+
error: err && (err.message || err.errMsg || err.toString && err.toString()) || err
|
|
1218
|
+
})
|
|
1159
1219
|
return Promise.reject(err)
|
|
1160
1220
|
})
|
|
1161
1221
|
}
|
|
@@ -1167,6 +1227,13 @@ export default class ClientChatSession {
|
|
|
1167
1227
|
size: 20 // 本次要获取的会话条数
|
|
1168
1228
|
}, params)
|
|
1169
1229
|
this.data.loading = true
|
|
1230
|
+
const startedAt = Date.now()
|
|
1231
|
+
this._addGetSessionLog('session_list_requested', {
|
|
1232
|
+
mode: 'load_more',
|
|
1233
|
+
wechatAccountId: params.wechatAccountId,
|
|
1234
|
+
lastUpdateTime: params.lastUpdateTime,
|
|
1235
|
+
size: params.size
|
|
1236
|
+
})
|
|
1170
1237
|
let lastSession = this._getLastSessionBySessionGroup(params.wechatAccountId || ALL_WECHAT_ACCOUNT_ID)
|
|
1171
1238
|
const ps1 = this.loadSessionData(params, {
|
|
1172
1239
|
lastSession,
|
|
@@ -1184,9 +1251,21 @@ export default class ClientChatSession {
|
|
|
1184
1251
|
}
|
|
1185
1252
|
return Promise.all([ps1]).then((rs) => {
|
|
1186
1253
|
this.data.loading = false
|
|
1254
|
+
this._addGetSessionLog('session_list_applied', {
|
|
1255
|
+
mode: 'load_more',
|
|
1256
|
+
wechatAccountId: params.wechatAccountId,
|
|
1257
|
+
count: rs[0] && rs[0].data && rs[0].data.length || 0,
|
|
1258
|
+
duration: Date.now() - startedAt
|
|
1259
|
+
})
|
|
1187
1260
|
return rs[0]
|
|
1188
1261
|
}, err => {
|
|
1189
1262
|
this.data.loading = false
|
|
1263
|
+
this._addGetSessionLog('session_list_failed', {
|
|
1264
|
+
mode: 'load_more',
|
|
1265
|
+
wechatAccountId: params.wechatAccountId,
|
|
1266
|
+
duration: Date.now() - startedAt,
|
|
1267
|
+
error: err && (err.message || err.errMsg || err.toString && err.toString()) || err
|
|
1268
|
+
})
|
|
1190
1269
|
return Promise.reject(err)
|
|
1191
1270
|
})
|
|
1192
1271
|
}
|