@aochuang/client-sdk 1.0.321 → 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
|
|
@@ -419,7 +390,7 @@ class ClientChat {
|
|
|
419
390
|
return this.handleAutoReadMessageSession(sessionId)
|
|
420
391
|
}
|
|
421
392
|
// 如果消息包含这种情况,就不加入会话列表
|
|
422
|
-
if (shouldIgnoreSessionByMessage(data)) {
|
|
393
|
+
if (shouldIgnoreSessionByMessage(data) || isDeletedMsg(data) || isBlockedMsg(data)) {
|
|
423
394
|
return
|
|
424
395
|
}
|
|
425
396
|
const localSession = this.session.findSession(({ session }) => session.conversationId === sessionId)
|
|
@@ -554,7 +525,7 @@ class ClientChat {
|
|
|
554
525
|
return this.handleAutoReadMessageSession(sessionId)
|
|
555
526
|
}
|
|
556
527
|
// 如果消息包含这种情况,就不加入会话列表
|
|
557
|
-
if (shouldIgnoreSessionByMessage(data)) {
|
|
528
|
+
if (shouldIgnoreSessionByMessage(data) || isDeletedMsg(data) || isBlockedMsg(data)) {
|
|
558
529
|
return
|
|
559
530
|
}
|
|
560
531
|
// 更新会话未读消息数量
|
|
@@ -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
|
* 有两种情况,一种是从客户发过来的消息,另一种是客服发送的消息
|