@aochuang/client-sdk 1.0.320 → 1.0.322
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
|
@@ -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
|
|
@@ -141,7 +112,7 @@ class ClientChat {
|
|
|
141
112
|
})
|
|
142
113
|
const mergeSessionCommonOptions = (options, instance) => {
|
|
143
114
|
let updateSessioning = false
|
|
144
|
-
let
|
|
115
|
+
let removeSessioning = false
|
|
145
116
|
options.onAddSession = ({ session }) => {
|
|
146
117
|
// 同步未读会话
|
|
147
118
|
if (instance !== this.sessionUnread && session.unreadMsgCount > 0) {
|
|
@@ -219,23 +190,15 @@ class ClientChat {
|
|
|
219
190
|
}
|
|
220
191
|
}
|
|
221
192
|
options.onRemoveSession = ({ session }) => {
|
|
222
|
-
|
|
223
|
-
if (instance === this.session) {
|
|
224
|
-
this.sessionFilter.removeSession(session.conversationId)
|
|
225
|
-
if (this.sessionManage.currentSession && this.sessionManage.currentSession.conversationId === session.conversationId) {
|
|
226
|
-
this.sessionManage.setCurrentSession(null)
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
options.onDeleteSession = ({ session }) => {
|
|
231
|
-
if (!session) {
|
|
193
|
+
if (instance !== this.session) {
|
|
232
194
|
return
|
|
233
195
|
}
|
|
234
|
-
if (
|
|
196
|
+
if (removeSessioning) {
|
|
235
197
|
return
|
|
236
198
|
}
|
|
237
|
-
|
|
199
|
+
removeSessioning = true
|
|
238
200
|
try {
|
|
201
|
+
// 同步账号未读数量
|
|
239
202
|
this.account.updateAccountUnreadMessageNum(session.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => {
|
|
240
203
|
// 如果是免打扰的会话
|
|
241
204
|
if (session.mute) {
|
|
@@ -274,9 +237,12 @@ class ClientChat {
|
|
|
274
237
|
})
|
|
275
238
|
throw error
|
|
276
239
|
} finally {
|
|
277
|
-
|
|
240
|
+
removeSessioning = false
|
|
278
241
|
}
|
|
279
242
|
}
|
|
243
|
+
options.onDeleteSession = ({ session }) => {
|
|
244
|
+
// todo
|
|
245
|
+
}
|
|
280
246
|
options.onClearVirtualSession = ({ virtualSessionData }) => {
|
|
281
247
|
const selectedVirtualSession = virtualSessionData.find(v => this.sessionManage.currentSession && v.conversationId === this.sessionManage.currentSession.conversationId)
|
|
282
248
|
if (selectedVirtualSession) {
|
|
@@ -424,7 +390,7 @@ class ClientChat {
|
|
|
424
390
|
return this.handleAutoReadMessageSession(sessionId)
|
|
425
391
|
}
|
|
426
392
|
// 如果消息包含这种情况,就不加入会话列表
|
|
427
|
-
if (shouldIgnoreSessionByMessage(data)) {
|
|
393
|
+
if (shouldIgnoreSessionByMessage(data) || isDeletedMsg(data) || isBlockedMsg(data)) {
|
|
428
394
|
return
|
|
429
395
|
}
|
|
430
396
|
const localSession = this.session.findSession(({ session }) => session.conversationId === sessionId)
|
|
@@ -559,7 +525,7 @@ class ClientChat {
|
|
|
559
525
|
return this.handleAutoReadMessageSession(sessionId)
|
|
560
526
|
}
|
|
561
527
|
// 如果消息包含这种情况,就不加入会话列表
|
|
562
|
-
if (shouldIgnoreSessionByMessage(data)) {
|
|
528
|
+
if (shouldIgnoreSessionByMessage(data) || isDeletedMsg(data) || isBlockedMsg(data)) {
|
|
563
529
|
return
|
|
564
530
|
}
|
|
565
531
|
// 更新会话未读消息数量
|
|
@@ -933,6 +899,24 @@ class ClientChat {
|
|
|
933
899
|
return this.contacts.getFriend(sessionFriendId, true)
|
|
934
900
|
})
|
|
935
901
|
}
|
|
902
|
+
// 刷新工作微信号未读消息数量
|
|
903
|
+
if (rs && rs.length) {
|
|
904
|
+
rs.forEach(session => {
|
|
905
|
+
this.account.updateAccountUnreadMessageNum(session.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => {
|
|
906
|
+
if (session.mute) {
|
|
907
|
+
return {
|
|
908
|
+
num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
|
|
909
|
+
muteNum: (unreadMessageMuteNum || 0) + (session.unreadMsgCount || 0)
|
|
910
|
+
}
|
|
911
|
+
} else {
|
|
912
|
+
return {
|
|
913
|
+
num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
|
|
914
|
+
muteNum: unreadMessageMuteNum
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
})
|
|
918
|
+
})
|
|
919
|
+
}
|
|
936
920
|
return ps.finally(() => {
|
|
937
921
|
// 这里应该标记那些工作微信号的通讯录修改了,后面要在界面打个提示,告诉用户通讯录变化了,让手动刷新一下
|
|
938
922
|
// 同时也将缓存都清理一下,例如工作微信号分组统计数量等
|
|
@@ -997,6 +981,24 @@ class ClientChat {
|
|
|
997
981
|
ps = this.account.reloadData()
|
|
998
982
|
}
|
|
999
983
|
}
|
|
984
|
+
// 刷新工作微信号未读消息数量
|
|
985
|
+
if (rs && rs.length) {
|
|
986
|
+
rs.forEach(session => {
|
|
987
|
+
this.account.updateAccountUnreadMessageNum(session.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => {
|
|
988
|
+
if (session.mute) {
|
|
989
|
+
return {
|
|
990
|
+
num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
|
|
991
|
+
muteNum: (unreadMessageMuteNum || 0) + (session.unreadMsgCount || 0)
|
|
992
|
+
}
|
|
993
|
+
} else {
|
|
994
|
+
return {
|
|
995
|
+
num: (unreadMesasgeNum || 0) + (session.unreadMsgCount || 0),
|
|
996
|
+
muteNum: unreadMessageMuteNum
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
})
|
|
1000
|
+
})
|
|
1001
|
+
}
|
|
1000
1002
|
return ps.finally(() => {
|
|
1001
1003
|
// 这里应该标记那些工作微信号的通讯录修改了,后面要在界面打个提示,告诉用户通讯录变化了,让手动刷新一下
|
|
1002
1004
|
// 同时也将缓存都清理一下,例如工作微信号分组统计数量等
|
|
@@ -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
|
* 有两种情况,一种是从客户发过来的消息,另一种是客服发送的消息
|