@aochuang/client-sdk 1.0.381 → 1.0.400
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 +4 -40
- package/components/chat-editor/chat-editor.vue +5 -75
- package/components/index.js +6 -1
- package/components/layout/layout.vue +5 -0
- package/components/session-select/session-select-item.vue +8 -9
- package/components/wechat-chat-control/location/location.vue +6 -14
- package/components/wework-chat-control/channel-card/channel-card.vue +144 -0
- package/components/wework-chat-control/channel-live/channel-live.vue +7 -2
- package/components/wework-chat-control/company-card/company-card.vue +1 -1
- package/components/wework-chat-control/custom-expression/custom-expression.vue +2 -1
- package/components/wework-chat-control/file-url/file-url.vue +34 -16
- package/components/wework-chat-control/image/image.vue +137 -2
- package/components/wework-chat-control/index.js +15 -7
- package/components/wework-chat-control/location/location.vue +3 -3
- package/components/wework-chat-control/merge-message/merge-message-panel.vue +63 -0
- package/components/wework-chat-control/merge-message/merge-message.vue +84 -0
- package/components/wework-chat-control/merge-message/util.js +59 -0
- package/components/wework-chat-control/metting/enterprise-wechat.png +0 -0
- package/components/wework-chat-control/metting/meeting-video.svg +4 -0
- package/components/wework-chat-control/metting/metting.vue +181 -0
- package/components/wework-chat-control/red-envelopes/red-envelopes.vue +3 -2
- package/components/wework-chat-control/text/text-default.vue +99 -0
- package/components/wework-chat-control/text/text-quote.vue +138 -0
- package/components/wework-chat-control/text/text.vue +27 -143
- package/components/wework-chat-control/url/url-channel-live.vue +53 -0
- package/components/wework-chat-control/url/url-miniprogram.vue +6 -7
- package/components/wework-chat-control/url/url.vue +26 -2
- package/components/wework-chat-control/util.js +30 -17
- package/components/wework-chat-control/video/video.vue +11 -3
- package/components/wework-chat-control/voice/voice.vue +14 -3
- package/components/wework-chat-control/wework-chat-control-config-item.vue +24 -0
- package/components/wework-chat-control/wework-chat-control-config-msg.vue +25 -0
- package/{uni-components/chat-control/chat-control-config.vue → components/wework-chat-control/wework-chat-control-config.vue} +16 -13
- package/components/wework-chat-panel/chat-panel-chat-status/chat-panel-chat-status.vue +120 -0
- package/components/wework-chat-panel/chat-panel-item.vue +70 -39
- package/components/wework-chat-panel/chat-panel.vue +96 -13
- package/package.json +10 -3
- package/services/client-chat/client-chat-wework/client-chat-account.js +93 -1
- package/services/client-chat/client-chat-wework/client-chat-concats.js +104 -18
- package/services/client-chat/client-chat-wework/client-chat-message.js +268 -11
- package/services/client-chat/client-chat-wework/client-chat-session.js +271 -191
- package/services/client-chat/client-chat-wework/client-chat-socket.js +18 -2
- package/services/client-chat/client-chat-wework/client-chat.js +470 -85
- package/services/client-chat/client-chat-wework/docs/README.md +308 -0
- package/services/client-chat/client-chat-wework/utils.js +5 -5
- package/components/wework-chat-panel/chat-panel-controls/company-card/company-card.vue +0 -35
- package/components/wework-chat-panel/chat-panel-controls/expression/expression.vue +0 -36
- package/components/wework-chat-panel/chat-panel-controls/file-url/file-url.vue +0 -35
- package/components/wework-chat-panel/chat-panel-controls/image/image.vue +0 -36
- package/components/wework-chat-panel/chat-panel-controls/index.js +0 -35
- package/components/wework-chat-panel/chat-panel-controls/jx-sys-text/jx-sys-text.vue +0 -28
- package/components/wework-chat-panel/chat-panel-controls/link/link.vue +0 -35
- package/components/wework-chat-panel/chat-panel-controls/location/location.vue +0 -35
- package/components/wework-chat-panel/chat-panel-controls/text/text.vue +0 -43
- package/components/wework-chat-panel/chat-panel-controls/unkonw/unkonw.vue +0 -39
- package/components/wework-chat-panel/chat-panel-controls/video/video.vue +0 -37
- package/components/wework-chat-panel/chat-panel-controls/voice/voice.vue +0 -35
- package/uni-common/account-portray/account-portray.vue +0 -51
- package/uni-common/account-select/account-select-item.vue +0 -172
- package/uni-common/account-select/account-select.vue +0 -252
- package/uni-common/all-friend-avatar/all-friend-avatar.vue +0 -49
- package/uni-common/friend-avatar/default.svg +0 -1
- package/uni-common/friend-avatar/friend-avatar.vue +0 -27
- package/uni-common/friend-avatar/index.js +0 -3
- package/uni-common/friend-loader/friend-loader.vue +0 -53
- package/uni-common/friend-portray/friend-portray.vue +0 -56
- package/uni-common/group-avatar/default.svg +0 -1
- package/uni-common/group-avatar/group-avatar.vue +0 -18
- package/uni-common/group-avatar/index.js +0 -3
- package/uni-common/room-avatar/default.svg +0 -6
- package/uni-common/room-avatar/index.js +0 -3
- package/uni-common/room-avatar/room-avatar.vue +0 -27
- package/uni-common/room-loader/room-loader.vue +0 -53
- package/uni-common/room-portray/room-portray.vue +0 -56
- package/uni-components/chat-control/calling/calling.vue +0 -91
- package/uni-components/chat-control/calling/phone-fill.svg +0 -1
- package/uni-components/chat-control/calling/vidicon-fill.svg +0 -1
- package/uni-components/chat-control/channel-video/channel-video.vue +0 -89
- package/uni-components/chat-control/channel-video-card/channel-video-card.vue +0 -105
- package/uni-components/chat-control/channel-video-live/channel-video-live.vue +0 -92
- package/uni-components/chat-control/chat-control-config-item/chat-control-config-item.vue +0 -20
- package/uni-components/chat-control/chat-control-config-item/index.js +0 -3
- package/uni-components/chat-control/chat-control-config-msg/chat-control-config-msg-app.vue +0 -25
- package/uni-components/chat-control/chat-control-config-msg/chat-control-config-msg-h5.vue +0 -21
- package/uni-components/chat-control/chat-control.vue +0 -218
- package/uni-components/chat-control/company-card/company-card.vue +0 -123
- package/uni-components/chat-control/const.js +0 -28
- package/uni-components/chat-control/expression/expression.vue +0 -41
- package/uni-components/chat-control/image/image.vue +0 -68
- package/uni-components/chat-control/index.js +0 -89
- package/uni-components/chat-control/location/location.vue +0 -110
- package/uni-components/chat-control/member-change/member-change.vue +0 -32
- package/uni-components/chat-control/quote-message/quote-message.vue +0 -216
- package/uni-components/chat-control/real-time-position/real-time-position.vue +0 -62
- package/uni-components/chat-control/redpacket/red-envelope.svg +0 -1
- package/uni-components/chat-control/redpacket/redpacket.vue +0 -75
- package/uni-components/chat-control/share-card/share-card.vue +0 -101
- package/uni-components/chat-control/system/system.vue +0 -69
- package/uni-components/chat-control/system-batch-message/system-batch-message.vue +0 -30
- package/uni-components/chat-control/system-text/system-text.vue +0 -32
- package/uni-components/chat-control/text/text.vue +0 -67
- package/uni-components/chat-control/text-with-at/text-with-at.vue +0 -51
- package/uni-components/chat-control/transfer/red-transfer.svg +0 -1
- package/uni-components/chat-control/transfer/transfer.vue +0 -80
- package/uni-components/chat-control/unkonw/unkonw.vue +0 -37
- package/uni-components/chat-control/url/icons/file-excel-line.svg +0 -1
- package/uni-components/chat-control/url/icons/file-info-line.svg +0 -1
- package/uni-components/chat-control/url/icons/file-music-line.svg +0 -1
- package/uni-components/chat-control/url/icons/file-pdf-line.svg +0 -1
- package/uni-components/chat-control/url/icons/file-ppt-line.svg +0 -1
- package/uni-components/chat-control/url/icons/file-settings-line.svg +0 -1
- package/uni-components/chat-control/url/icons/file-text-line.svg +0 -1
- package/uni-components/chat-control/url/icons/file-unknow-line.svg +0 -1
- package/uni-components/chat-control/url/icons/file-word-line.svg +0 -1
- package/uni-components/chat-control/url/icons/file-zip-line.svg +0 -1
- package/uni-components/chat-control/url/icons/index.js +0 -24
- package/uni-components/chat-control/url/miniprogram.svg +0 -1
- package/uni-components/chat-control/url/url-miniprogram.vue +0 -116
- package/uni-components/chat-control/url/url.vue +0 -306
- package/uni-components/chat-control/url-new/icons/file-excel-line.svg +0 -1
- package/uni-components/chat-control/url-new/icons/file-info-line.svg +0 -1
- package/uni-components/chat-control/url-new/icons/file-music-line.svg +0 -1
- package/uni-components/chat-control/url-new/icons/file-pdf-line.svg +0 -1
- package/uni-components/chat-control/url-new/icons/file-ppt-line.svg +0 -1
- package/uni-components/chat-control/url-new/icons/file-settings-line.svg +0 -1
- package/uni-components/chat-control/url-new/icons/file-text-line.svg +0 -1
- package/uni-components/chat-control/url-new/icons/file-unknow-line.svg +0 -1
- package/uni-components/chat-control/url-new/icons/file-word-line.svg +0 -1
- package/uni-components/chat-control/url-new/icons/file-zip-line.svg +0 -1
- package/uni-components/chat-control/url-new/icons/index.js +0 -24
- package/uni-components/chat-control/url-new/url-new.vue +0 -110
- package/uni-components/chat-control/utils.js +0 -12
- package/uni-components/chat-control/video/video.vue +0 -156
- package/uni-components/chat-control/voice/voice.vue +0 -166
- package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet-collect.vue +0 -84
- package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet-system.vue +0 -28
- package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet.vue +0 -85
- package/uni-components/chat-editor/chat-editor-func/chat-editor-func.vue +0 -157
- package/uni-components/chat-editor/chat-editor-func-at/chat-editor-func-at-panel.vue +0 -158
- package/uni-components/chat-editor/chat-editor-func-at/chat-editor-func-at.vue +0 -61
- package/uni-components/chat-editor/chat-editor-func-button/chat-editor-func-button.vue +0 -58
- package/uni-components/chat-editor/chat-editor-func-file/chat-editor-func-file.vue +0 -54
- package/uni-components/chat-editor/chat-editor-func-image/chat-editor-func-image.vue +0 -42
- package/uni-components/chat-editor/chat-editor-func-video/chat-editor-func-video.vue +0 -42
- package/uni-components/chat-editor/chat-editor-func-voice/chat-editor-func-voice.vue +0 -25
- package/uni-components/chat-editor/chat-editor-message-send/chat-editor-message-send.vue +0 -158
- package/uni-components/chat-editor/chat-editor-quote/chat-editor-quote.vue +0 -75
- package/uni-components/chat-editor/chat-editor.vue +0 -257
- package/uni-components/chat-editor/index.js +0 -10
- package/uni-components/chat-editor/util.js +0 -65
- package/uni-components/chat-panel/chat-panel-chats-box.vue +0 -238
- package/uni-components/chat-panel/chat-panel-chats-forward/chat-panel-chats-forward.vue +0 -273
- package/uni-components/chat-panel/chat-panel-chats-item.vue +0 -578
- package/uni-components/chat-panel/chat-panel-chats-status/chat-panel-chats-status.vue +0 -71
- package/uni-components/chat-panel/chat-panel-chats.vue +0 -368
- package/uni-components/chat-panel/chat-panel.vue +0 -227
- package/uni-components/contacts-group-select/contacts-group-select-item.vue +0 -85
- package/uni-components/contacts-group-select/contacts-group-select-panel.vue +0 -119
- package/uni-components/contacts-group-select/contacts-group-select.vue +0 -150
|
@@ -5,7 +5,6 @@ import ClientChatContacts from './client-chat-concats.js'
|
|
|
5
5
|
import ClientChatAccount from './client-chat-account.js'
|
|
6
6
|
import ClientChatSocket from './client-chat-socket.js'
|
|
7
7
|
import { createSessionId } from './utils.js'
|
|
8
|
-
import { createPollRequest } from '../../../utils/util.js'
|
|
9
8
|
import Event from '../../../utils/event.js'
|
|
10
9
|
|
|
11
10
|
const CONNECT_STATUS = {
|
|
@@ -22,8 +21,6 @@ class ClientChat {
|
|
|
22
21
|
return this.data.connectStatus === CONNECT_STATUS.Loading
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
_sessionPollRequestMap = {}
|
|
26
|
-
|
|
27
24
|
constructor (options) {
|
|
28
25
|
|
|
29
26
|
options = Object.assign({
|
|
@@ -32,6 +29,7 @@ class ClientChat {
|
|
|
32
29
|
getLoginUserIdMethod: null,
|
|
33
30
|
getLoginUserTokenMethod: null,
|
|
34
31
|
loadAccountDataMethod: null,
|
|
32
|
+
getLoginAccountIdMethod: null, // 因为1.0有帮聊逻辑,帮聊消息以及通讯录的accountId不是登录用户的accountId,会导致找到的会话出现问题,所以这里提供一个方法让外部传入
|
|
35
33
|
loadSessionDataMethod: null,
|
|
36
34
|
updateSessionReadMethod: null,
|
|
37
35
|
getSessionMethod: null,
|
|
@@ -39,6 +37,7 @@ class ClientChat {
|
|
|
39
37
|
getAccountUnreadMessageNumMethod: null,
|
|
40
38
|
updateAccountMessageReadMethod: null,
|
|
41
39
|
deleteAccountSessionMethod: null,
|
|
40
|
+
getAccountGreetingUnreadMsgCountMethod: null,
|
|
42
41
|
loadContactsRoomGroupDataMethod: null,
|
|
43
42
|
loadContactsFriendGroupDataMethod: null,
|
|
44
43
|
loadContactsFriendDataMethod: null,
|
|
@@ -48,8 +47,10 @@ class ClientChat {
|
|
|
48
47
|
getContactsRoomGroupCountMethod: null,
|
|
49
48
|
getContactsFriendMethod: null,
|
|
50
49
|
getContactsRoomMethod: null,
|
|
51
|
-
loadFriendMessageDataMethod: null,
|
|
50
|
+
loadFriendMessageDataMethod: null,
|
|
52
51
|
loadRoomMessageDataMethod: null,
|
|
52
|
+
checkMessageSendResultMethod: null,
|
|
53
|
+
recallMessageMethod: null,
|
|
53
54
|
onOverwriteFriendInfoChange: null // 为了兼容1.0拉取会话逻辑加的,1.0暂时不支持根据taskId拉取
|
|
54
55
|
}, options)
|
|
55
56
|
if (!options.loadFriendMessageDataMethod) {
|
|
@@ -57,8 +58,9 @@ class ClientChat {
|
|
|
57
58
|
}
|
|
58
59
|
if (!options.loadRoomMessageDataMethod) {
|
|
59
60
|
throw new Error('loadRoomMessageDataMethod不能为空')
|
|
60
|
-
}
|
|
61
|
+
}
|
|
61
62
|
this.onOverwriteFriendInfoChange = options.onOverwriteFriendInfoChange
|
|
63
|
+
this.getLoginAccountIdMethod = options.getLoginAccountIdMethod
|
|
62
64
|
this.event = new Event({
|
|
63
65
|
checkOnMethod: (name) => {
|
|
64
66
|
if (name === 'ready') {
|
|
@@ -75,6 +77,14 @@ class ClientChat {
|
|
|
75
77
|
getSessionMethod: options.getSessionMethod,
|
|
76
78
|
loadSessionDataMethod: options.loadSessionDataMethod,
|
|
77
79
|
deleteSessionMethod: options.deleteSessionMethod,
|
|
80
|
+
onAddSession: ({ session, unreadDelta }) => {
|
|
81
|
+
if (!unreadDelta) {
|
|
82
|
+
return
|
|
83
|
+
}
|
|
84
|
+
this.account.updateAccountUnreadMessageNum(session.qwAccountId, ({ unreadMesasgeNum }) => {
|
|
85
|
+
return (unreadMesasgeNum || 0) + unreadDelta
|
|
86
|
+
})
|
|
87
|
+
},
|
|
78
88
|
onSessionReadChange: ({ session, oldUnreadMsgCount }) => {
|
|
79
89
|
this.account.updateAccountUnreadMessageNum(session.qwAccountId, ({ unreadMesasgeNum }) => {
|
|
80
90
|
return Math.max(0, unreadMesasgeNum - oldUnreadMsgCount)
|
|
@@ -85,54 +95,72 @@ class ClientChat {
|
|
|
85
95
|
groupField: 'contactId',
|
|
86
96
|
sortField: 'sendTime',
|
|
87
97
|
clientChat: this,
|
|
88
|
-
|
|
89
|
-
|
|
98
|
+
checkMessageSendResultMethod: options.checkMessageSendResultMethod,
|
|
99
|
+
recallMessageMethod: options.recallMessageMethod,
|
|
100
|
+
recallMessageIdField: 'contactMessageId',
|
|
101
|
+
onAddMessageSuccess: ({ data, isBeforeLastMessage }) => {
|
|
102
|
+
const accountId = options.getLoginAccountIdMethod ? options.getLoginAccountIdMethod() : data.qwAccountId
|
|
103
|
+
let sessionId = createSessionId(accountId, data.contactId)
|
|
90
104
|
// 更新会话
|
|
91
105
|
if (!sessionId) {
|
|
92
106
|
return
|
|
93
107
|
}
|
|
108
|
+
if (isBeforeLastMessage) {
|
|
109
|
+
return
|
|
110
|
+
}
|
|
94
111
|
const localSession = this.session.getSessionByLocal(sessionId)
|
|
95
112
|
if (!localSession) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
113
|
+
return this.session.getSession(sessionId, (rs, context) => {
|
|
114
|
+
if (rs && rs.data) {
|
|
115
|
+
const isAfterServerMessage = data.sendTime > context.baseLastMsgTime
|
|
116
|
+
const isNewerMessage = data.sendTime > (rs.data.lastMsgTime || 0)
|
|
117
|
+
if (isNewerMessage) {
|
|
118
|
+
rs.data.lastMsgContent = data.content
|
|
119
|
+
rs.data.lastMsgType = data.msgType
|
|
120
|
+
rs.data.lastMsgTime = data.sendTime
|
|
121
|
+
rs.data.lastMsgId = data.id
|
|
122
|
+
rs.data.lastUpdateTime = data.updateDate
|
|
123
|
+
}
|
|
124
|
+
const isCurrentSession = this.session.currentSession && this.session.currentSession.id === sessionId
|
|
125
|
+
// 服务端返回的会话还没有包含当前消息时,本地补充会话未读数
|
|
126
|
+
if (!data.isSend && isAfterServerMessage) {
|
|
127
|
+
rs.data.unreadMsgCount = isCurrentSession ? 0 : (rs.data.unreadMsgCount || 0) + 1
|
|
128
|
+
}
|
|
129
|
+
// 账号未读只累计本次轮询期间新增的消息,避免重复累计服务端已有的未读数
|
|
130
|
+
if (!data.isSend && !(isAfterServerMessage && isCurrentSession)) {
|
|
131
|
+
context.accountUnreadDelta += 1
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return rs
|
|
135
|
+
}).catch(() => {})
|
|
110
136
|
} else {
|
|
111
137
|
this.session.updateSession(sessionId, ({ session }) => {
|
|
112
|
-
|
|
113
|
-
if (!
|
|
114
|
-
|
|
138
|
+
const isNewerMessage = data.sendTime > (session.lastMsgTime || 0)
|
|
139
|
+
if (!isNewerMessage) {
|
|
140
|
+
return {}
|
|
115
141
|
}
|
|
116
|
-
|
|
117
|
-
if (this.session.currentSession && this.session.currentSession.id === sessionId) {
|
|
118
|
-
unreadMsgCount = 0
|
|
119
|
-
// 标记已读,并且设置未读数量为0
|
|
120
|
-
this.session.setSessionRead(sessionId)
|
|
121
|
-
} else {
|
|
122
|
-
// 更新账号未读消息数量
|
|
123
|
-
this.account.updateAccountUnreadMessageNum(session.qwAccountId, ({ unreadMesasgeNum }) => {
|
|
124
|
-
return unreadMesasgeNum += 1
|
|
125
|
-
})
|
|
126
|
-
}
|
|
127
|
-
const nextSessin = {
|
|
142
|
+
const nextSession = {
|
|
128
143
|
lastMsgContent: data.content,
|
|
129
144
|
lastMsgType: data.msgType,
|
|
130
145
|
lastMsgTime: data.sendTime,
|
|
131
146
|
lastMsgId: data.id,
|
|
132
147
|
lastUpdateTime: data.updateDate,
|
|
133
|
-
unreadMsgCount
|
|
148
|
+
unreadMsgCount: session.unreadMsgCount || 0
|
|
149
|
+
}
|
|
150
|
+
if (!data.isSend) {
|
|
151
|
+
if (this.session.currentSession && this.session.currentSession.id === sessionId) {
|
|
152
|
+
// 标记已读
|
|
153
|
+
nextSession.unreadMsgCount = 0
|
|
154
|
+
this.session.setSessionRead(sessionId)
|
|
155
|
+
} else {
|
|
156
|
+
nextSession.unreadMsgCount += 1
|
|
157
|
+
// 更新账号未读消息数量
|
|
158
|
+
this.account.updateAccountUnreadMessageNum(session.qwAccountId, ({ unreadMesasgeNum }) => {
|
|
159
|
+
return (unreadMesasgeNum || 0) + 1
|
|
160
|
+
})
|
|
161
|
+
}
|
|
134
162
|
}
|
|
135
|
-
return
|
|
163
|
+
return nextSession
|
|
136
164
|
})
|
|
137
165
|
}
|
|
138
166
|
},
|
|
@@ -144,65 +172,84 @@ class ClientChat {
|
|
|
144
172
|
groupField: 'contactId',
|
|
145
173
|
sortField: 'sendTime',
|
|
146
174
|
clientChat: this,
|
|
147
|
-
|
|
175
|
+
checkMessageSendResultMethod: options.checkMessageSendResultMethod,
|
|
148
176
|
// loadLossMessageDataMethod: options.loadLossFriendMessageDataMethod,
|
|
149
177
|
queryMethod: (params) => {
|
|
150
178
|
return options.loadFriendMessageDataMethod(params)
|
|
151
179
|
}
|
|
152
180
|
})
|
|
181
|
+
this.friendMessage.setRelatedMessageService(this.friendMessageFilter)
|
|
153
182
|
this.roomMessage = new ClientChatMessage({
|
|
154
183
|
groupField: 'roomId',
|
|
155
184
|
sortField: 'sendTime',
|
|
156
185
|
clientChat: this,
|
|
157
|
-
|
|
158
|
-
|
|
186
|
+
checkMessageSendResultMethod: options.checkMessageSendResultMethod,
|
|
187
|
+
recallMessageMethod: options.recallMessageMethod,
|
|
188
|
+
recallMessageIdField: 'roomMessageId',
|
|
189
|
+
onAddMessageSuccess: ({ data, isBeforeLastMessage }) => {
|
|
190
|
+
const accountId = options.getLoginAccountIdMethod ? options.getLoginAccountIdMethod() : data.qwAccountId
|
|
191
|
+
let sessionId = createSessionId(accountId, data.roomId)
|
|
159
192
|
// 更新会话
|
|
160
193
|
if (!sessionId) {
|
|
161
194
|
return
|
|
162
195
|
}
|
|
196
|
+
if (isBeforeLastMessage) {
|
|
197
|
+
return
|
|
198
|
+
}
|
|
163
199
|
// 更新会话未读消息数量
|
|
164
200
|
const localSession = this.session.getSessionByLocal(sessionId)
|
|
165
201
|
if (!localSession) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
202
|
+
return this.session.getSession(sessionId, (rs, context) => {
|
|
203
|
+
if (rs && rs.data) {
|
|
204
|
+
const isAfterServerMessage = data.sendTime > context.baseLastMsgTime
|
|
205
|
+
const isNewerMessage = data.sendTime > (rs.data.lastMsgTime || 0)
|
|
206
|
+
if (isNewerMessage) {
|
|
207
|
+
rs.data.lastMsgContent = data.content
|
|
208
|
+
rs.data.lastMsgType = data.msgType
|
|
209
|
+
rs.data.lastMsgTime = data.sendTime
|
|
210
|
+
rs.data.lastMsgId = data.id
|
|
211
|
+
rs.data.lastUpdateTime = data.updateDate
|
|
212
|
+
}
|
|
213
|
+
const isCurrentSession = this.session.currentSession && this.session.currentSession.id === sessionId
|
|
214
|
+
// 服务端返回的会话还没有包含当前消息时,本地补充会话未读数
|
|
215
|
+
if (!data.isSend && isAfterServerMessage) {
|
|
216
|
+
rs.data.unreadMsgCount = isCurrentSession ? 0 : (rs.data.unreadMsgCount || 0) + 1
|
|
217
|
+
}
|
|
218
|
+
// 账号未读只累计本次轮询期间新增的消息,避免重复累计服务端已有的未读数
|
|
219
|
+
if (!data.isSend && !(isAfterServerMessage && isCurrentSession)) {
|
|
220
|
+
context.accountUnreadDelta += 1
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return rs
|
|
224
|
+
}).catch(() => {})
|
|
180
225
|
} else {
|
|
181
226
|
this.session.updateSession(sessionId, ({ session }) => {
|
|
182
|
-
|
|
183
|
-
if (!
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
// 如果是当前会话,那么未读消息需要设置为0
|
|
187
|
-
if (this.session.currentSession && this.session.currentSession.id === sessionId) {
|
|
188
|
-
unreadMsgCount = 0
|
|
189
|
-
// 标记已读,并且设置未读数量为0
|
|
190
|
-
this.session.setSessionRead(sessionId)
|
|
191
|
-
} else {
|
|
192
|
-
// 更新账号未读消息数量
|
|
193
|
-
this.account.updateAccountUnreadMessageNum(session.qwAccountId, ({ unreadMesasgeNum }) => {
|
|
194
|
-
return unreadMesasgeNum += 1
|
|
195
|
-
})
|
|
227
|
+
const isNewerMessage = data.sendTime > (session.lastMsgTime || 0)
|
|
228
|
+
if (!isNewerMessage) {
|
|
229
|
+
return {}
|
|
196
230
|
}
|
|
197
|
-
const
|
|
231
|
+
const nextSession = {
|
|
198
232
|
lastMsgContent: data.content,
|
|
199
233
|
lastMsgType: data.msgType,
|
|
200
234
|
lastMsgTime: data.sendTime,
|
|
201
235
|
lastMsgId: data.id,
|
|
202
236
|
lastUpdateTime: data.updateDate,
|
|
203
|
-
unreadMsgCount
|
|
237
|
+
unreadMsgCount: session.unreadMsgCount || 0
|
|
204
238
|
}
|
|
205
|
-
|
|
239
|
+
if (!data.isSend) {
|
|
240
|
+
if (this.session.currentSession && this.session.currentSession.id === sessionId) {
|
|
241
|
+
// 标记已读
|
|
242
|
+
nextSession.unreadMsgCount = 0
|
|
243
|
+
this.session.setSessionRead(sessionId)
|
|
244
|
+
} else {
|
|
245
|
+
nextSession.unreadMsgCount += 1
|
|
246
|
+
// 更新账号未读消息数量
|
|
247
|
+
this.account.updateAccountUnreadMessageNum(session.qwAccountId, ({ unreadMesasgeNum }) => {
|
|
248
|
+
return (unreadMesasgeNum || 0) + 1
|
|
249
|
+
})
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return nextSession
|
|
206
253
|
})
|
|
207
254
|
}
|
|
208
255
|
},
|
|
@@ -214,12 +261,13 @@ class ClientChat {
|
|
|
214
261
|
groupField: 'roomId',
|
|
215
262
|
sortField: 'sendTime',
|
|
216
263
|
clientChat: this,
|
|
217
|
-
|
|
264
|
+
checkMessageSendResultMethod: options.checkMessageSendResultMethod,
|
|
218
265
|
// loadLossMessageDataMethod: options.loadLossRoomMessageDataMethod,
|
|
219
266
|
queryMethod: (params) => {
|
|
220
267
|
return options.loadRoomMessageDataMethod(params)
|
|
221
268
|
}
|
|
222
269
|
})
|
|
270
|
+
this.roomMessage.setRelatedMessageService(this.roomMessageFilter)
|
|
223
271
|
this.contacts = new ClientChatContacts({
|
|
224
272
|
loadContactsRoomGroupDataMethod: options.loadContactsRoomGroupDataMethod,
|
|
225
273
|
loadContactsFriendGroupDataMethod: options.loadContactsFriendGroupDataMethod,
|
|
@@ -237,12 +285,18 @@ class ClientChat {
|
|
|
237
285
|
loadAccountDataMethod: options.loadAccountDataMethod,
|
|
238
286
|
getAccountUnreadMessageNumMethod: options.getAccountUnreadMessageNumMethod,
|
|
239
287
|
updateAccountMessageReadMethod: options.updateAccountMessageReadMethod,
|
|
288
|
+
getAccountGreetingUnreadMsgCountMethod: options.getAccountGreetingUnreadMsgCountMethod,
|
|
240
289
|
onAccountAdded: ({ account }) => {
|
|
241
290
|
return this.account.refreshAccountUnreadMessageNum({
|
|
242
291
|
qwAccountId: account.id,
|
|
243
292
|
corpId: account.corpId
|
|
244
293
|
})
|
|
245
294
|
},
|
|
295
|
+
onAccountLoaded: () => {
|
|
296
|
+
if (options.getAccountGreetingUnreadMsgCountMethod) {
|
|
297
|
+
this.account.refreshAllAccountGreetingUnreadMsgCount().catch(() => {})
|
|
298
|
+
}
|
|
299
|
+
},
|
|
246
300
|
onCurrentAccountChange: ({ currentAccount }) => {
|
|
247
301
|
this.contacts.refreshAllFriendGroupCount({
|
|
248
302
|
qwAccountId: currentAccount ? currentAccount.id : null
|
|
@@ -258,6 +312,106 @@ class ClientChat {
|
|
|
258
312
|
})
|
|
259
313
|
this.socket = new ClientChatSocket({
|
|
260
314
|
socket: options.socket,
|
|
315
|
+
onCmdQwContactRequestChanged: ({ data } = {}) => {
|
|
316
|
+
// {
|
|
317
|
+
// "cmdType": CmdQwContactRequestChanged
|
|
318
|
+
// "seq": 123,
|
|
319
|
+
// "cmdType": "CmdQwContactRequestChanged",
|
|
320
|
+
// "changeType": 1,
|
|
321
|
+
// "record": { ...QwContactRequestRecordDto...
|
|
322
|
+
// }
|
|
323
|
+
// changeType:1 = 新增、2 = 状态变化(值来自 ChangeTypeEnum,序列化为数字)
|
|
324
|
+
// 触发时机:新同步到一条好友请求 → changeType=1;之后每次状态流转(1/2/3/4)→ changeType=2
|
|
325
|
+
// 推送目标:该记录 accountId 对应的客服端。若该请求未分配客服(设备无保管者)则不推送,前端不能依赖推送判断「没有新的好友请求」
|
|
326
|
+
// 新增和状态流转都会影响待处理数量,刷新对应账号的好友请求数
|
|
327
|
+
this.refreshGreetingUnreadMsgCountByPush(data)
|
|
328
|
+
this.event.emit('contactRequestChanged', { data })
|
|
329
|
+
},
|
|
330
|
+
onCmdQwAcceptContactRequest: ({ data } = {}) => {
|
|
331
|
+
// CmdQwAcceptContactRequest 请求字段不变(qwAccountId、remoteId),错误提示文案不变。但点击通过后状态立即变为 1(请求中),需等设备回执:超时→2、失败→3、成功→4。原来把「通过成功」判断为 2 的逻辑必须改成 4
|
|
332
|
+
this.refreshGreetingUnreadMsgCountByPush(data)
|
|
333
|
+
},
|
|
334
|
+
onCmdQwContactInfoChanged: ({ data }) => {
|
|
335
|
+
const contacts = data && (Array.isArray(data.contacts)
|
|
336
|
+
? data.contacts
|
|
337
|
+
: (data.contactId ? [data] : []))
|
|
338
|
+
if (!contacts || !contacts.length) {
|
|
339
|
+
this.markAccountsModified(data && data.qwAccountIds)
|
|
340
|
+
return
|
|
341
|
+
}
|
|
342
|
+
const tasks = []
|
|
343
|
+
const removedTasks = []
|
|
344
|
+
const addedAccountIds = contacts
|
|
345
|
+
.filter(contact => contact && Number(contact.changeType) === 1)
|
|
346
|
+
.map(contact => contact.qwAccountId || data.qwAccountId)
|
|
347
|
+
return this.reloadAccountDataIfMissing(addedAccountIds).then(newAccountMap => {
|
|
348
|
+
contacts.forEach(contact => {
|
|
349
|
+
if (!contact) {
|
|
350
|
+
return
|
|
351
|
+
}
|
|
352
|
+
const changeType = Number(contact.changeType)
|
|
353
|
+
if (changeType === 1) {
|
|
354
|
+
tasks.push(this.handleQwContactAdded(contact, data, newAccountMap))
|
|
355
|
+
} else if (changeType === 2) {
|
|
356
|
+
tasks.push(this.handleQwContactUpdated(contact))
|
|
357
|
+
} else if (changeType === 3) {
|
|
358
|
+
removedTasks.push(this.handleQwContactRemoved(contact, data))
|
|
359
|
+
}
|
|
360
|
+
})
|
|
361
|
+
return Promise.all(tasks.concat(removedTasks))
|
|
362
|
+
}).then(results => {
|
|
363
|
+
const accountUnreadCountMap = {}
|
|
364
|
+
removedTasks.forEach((task, index) => {
|
|
365
|
+
const result = results[tasks.length + index]
|
|
366
|
+
if (!result || !result.accountId || !result.unreadCount) {
|
|
367
|
+
return
|
|
368
|
+
}
|
|
369
|
+
accountUnreadCountMap[result.accountId] = (accountUnreadCountMap[result.accountId] || 0) + result.unreadCount
|
|
370
|
+
})
|
|
371
|
+
return Promise.all(Object.keys(accountUnreadCountMap).map(accountId => {
|
|
372
|
+
const removedUnreadCount = accountUnreadCountMap[accountId]
|
|
373
|
+
return this.account.updateAccountUnreadMessageNum(accountId, ({ unreadMesasgeNum }) => {
|
|
374
|
+
return Math.max(0, unreadMesasgeNum - removedUnreadCount)
|
|
375
|
+
}).catch(error => {
|
|
376
|
+
console.warn('[client-chat] update account unread count failed', error)
|
|
377
|
+
})
|
|
378
|
+
}))
|
|
379
|
+
})
|
|
380
|
+
},
|
|
381
|
+
onCmdQwRoomInfoChanged: ({ data }) => {
|
|
382
|
+
const rooms = data && (Array.isArray(data.rooms)
|
|
383
|
+
? data.rooms
|
|
384
|
+
: (data.roomId ? [data] : []))
|
|
385
|
+
if (!rooms || !rooms.length) {
|
|
386
|
+
this.markAccountsModified(data && data.qwAccountIds)
|
|
387
|
+
return
|
|
388
|
+
}
|
|
389
|
+
const tasks = []
|
|
390
|
+
const removedTasks = []
|
|
391
|
+
const addedAccountIds = rooms
|
|
392
|
+
.filter(room => room && Number(room.changeType) === 1)
|
|
393
|
+
.map(room => room.qwAccountId || data.qwAccountId)
|
|
394
|
+
return this.reloadAccountDataIfMissing(addedAccountIds).then(newAccountMap => {
|
|
395
|
+
rooms.forEach(room => {
|
|
396
|
+
if (!room) {
|
|
397
|
+
return
|
|
398
|
+
}
|
|
399
|
+
const changeType = Number(room.changeType)
|
|
400
|
+
if (changeType === 1) {
|
|
401
|
+
tasks.push(this.handleQwRoomAdded(room, data, newAccountMap))
|
|
402
|
+
} else if (changeType === 2) {
|
|
403
|
+
tasks.push(this.handleQwRoomUpdated(room))
|
|
404
|
+
} else if (changeType === 3) {
|
|
405
|
+
removedTasks.push(this.handleQwRoomRemoved(room, data))
|
|
406
|
+
}
|
|
407
|
+
})
|
|
408
|
+
return Promise.all(tasks.concat(removedTasks))
|
|
409
|
+
}).then(results => {
|
|
410
|
+
return this.updateRemovedSessionUnreadCounts(
|
|
411
|
+
results.slice(tasks.length)
|
|
412
|
+
)
|
|
413
|
+
})
|
|
414
|
+
},
|
|
261
415
|
// 接受新消息
|
|
262
416
|
onCmdQwNewMessage: ({ data }) => {
|
|
263
417
|
// 插入消息
|
|
@@ -267,6 +421,20 @@ class ClientChat {
|
|
|
267
421
|
this.roomMessage.addMessage(data.roomMessage)
|
|
268
422
|
}
|
|
269
423
|
},
|
|
424
|
+
onCmdQwMessageRecalled: ({ data }) => {
|
|
425
|
+
if (data && data.contactMessageId) {
|
|
426
|
+
this.friendMessage.handleMessageRecalled(data)
|
|
427
|
+
} else if (data && data.roomMessageId) {
|
|
428
|
+
this.roomMessage.handleMessageRecalled(data)
|
|
429
|
+
}
|
|
430
|
+
},
|
|
431
|
+
onCmdQwMessageRecallFailed: ({ data }) => {
|
|
432
|
+
if (data && data.contactMessageId) {
|
|
433
|
+
this.friendMessage.handleMessageRecallFailed(data)
|
|
434
|
+
} else if (data && data.roomMessageId) {
|
|
435
|
+
this.roomMessage.handleMessageRecallFailed(data)
|
|
436
|
+
}
|
|
437
|
+
},
|
|
270
438
|
// 会话失效
|
|
271
439
|
onCmdCmdKickOut: () => {
|
|
272
440
|
// 一般可能同一个账号在其他设备登录,这种情况需要重新登录
|
|
@@ -279,19 +447,241 @@ class ClientChat {
|
|
|
279
447
|
})
|
|
280
448
|
},
|
|
281
449
|
onHeartbeatSuccess: ({ data }) => {
|
|
282
|
-
|
|
283
|
-
return
|
|
284
|
-
}
|
|
285
|
-
const onlineMap = data.wq || {}
|
|
450
|
+
const onlineMap = data || {}
|
|
286
451
|
Object.keys(onlineMap).forEach(k => {
|
|
287
452
|
this.account.updateAccount(k, {
|
|
288
453
|
alive: onlineMap[k]
|
|
289
|
-
})
|
|
454
|
+
})
|
|
455
|
+
})
|
|
456
|
+
}
|
|
457
|
+
})
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
getQwAccountCorpId (qwAccountId, corpId) {
|
|
461
|
+
if (corpId || !qwAccountId || !this.account) {
|
|
462
|
+
return corpId
|
|
463
|
+
}
|
|
464
|
+
const account = this.account.getAccountData().find(item => item.id === qwAccountId)
|
|
465
|
+
return account && account.corpId
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
markAccountsModified (qwAccountIds) {
|
|
469
|
+
if (!Array.isArray(qwAccountIds) || !qwAccountIds.length) {
|
|
470
|
+
return
|
|
471
|
+
}
|
|
472
|
+
this.session.markModify(qwAccountIds)
|
|
473
|
+
this.contacts.markModify(qwAccountIds)
|
|
474
|
+
qwAccountIds.forEach(qwAccountId => {
|
|
475
|
+
this.contacts.clearAllFriendGroupCountCache(qwAccountId)
|
|
476
|
+
this.contacts.clearAllRoomGroupCountCache(qwAccountId)
|
|
477
|
+
})
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* 根据好友请求相关推送刷新待处理好友请求数量
|
|
482
|
+
* 推送里能拿到账号id就只刷该账号,否则刷全部
|
|
483
|
+
*/
|
|
484
|
+
refreshGreetingUnreadMsgCountByPush (data) {
|
|
485
|
+
if (!this.account || !this.account.getAccountGreetingUnreadMsgCountMethod) {
|
|
486
|
+
return
|
|
487
|
+
}
|
|
488
|
+
const record = (data && data.record) || data || {}
|
|
489
|
+
const qwAccountId = record.qwAccountId || record.accountId || (data && data.qwAccountId)
|
|
490
|
+
const params = qwAccountId && this.account.accountMap[qwAccountId] ? { qwAccountIds: [qwAccountId] } : undefined
|
|
491
|
+
this.account.getAccountGreetingUnreadMsgCount(params).catch(() => {})
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
updateRemovedSessionUnreadCounts (results) {
|
|
495
|
+
const accountUnreadCountMap = {}
|
|
496
|
+
;(results || []).forEach(result => {
|
|
497
|
+
if (!result || !result.accountId || !result.unreadCount) {
|
|
498
|
+
return
|
|
499
|
+
}
|
|
500
|
+
accountUnreadCountMap[result.accountId] = (accountUnreadCountMap[result.accountId] || 0) + result.unreadCount
|
|
501
|
+
})
|
|
502
|
+
return Promise.all(Object.keys(accountUnreadCountMap).map(accountId => {
|
|
503
|
+
const removedUnreadCount = accountUnreadCountMap[accountId]
|
|
504
|
+
return this.account.updateAccountUnreadMessageNum(accountId, ({ unreadMesasgeNum }) => {
|
|
505
|
+
return Math.max(0, unreadMesasgeNum - removedUnreadCount)
|
|
506
|
+
}).catch(error => {
|
|
507
|
+
console.warn('[client-chat] update account unread count failed', error)
|
|
508
|
+
})
|
|
509
|
+
}))
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* 新增联系人/群聊所属的企微号不在当前企微号列表里时(例如客服原来一个企微号都没有,后台分配后),需要重新加载企微号列表
|
|
514
|
+
* 返回新加载出来的企微号id map,新企微号的未读数会在onAccountAdded里以服务端为准刷新,不需要再本地累加
|
|
515
|
+
*/
|
|
516
|
+
reloadAccountDataIfMissing (qwAccountIds) {
|
|
517
|
+
// 先等正在进行的加载完成,避免reloadData把初始化中的加载请求取消掉
|
|
518
|
+
return Promise.resolve(this.account._cacheLoadPromise).catch(() => {}).then(() => {
|
|
519
|
+
const missingAccountIds = (qwAccountIds || []).filter((id, index, data) => {
|
|
520
|
+
return id && data.indexOf(id) === index && !this.account.accountMap[id]
|
|
521
|
+
})
|
|
522
|
+
if (!missingAccountIds.length) {
|
|
523
|
+
return {}
|
|
524
|
+
}
|
|
525
|
+
return this.account.reloadData().then(() => {
|
|
526
|
+
return missingAccountIds.reduce((rs, id) => {
|
|
527
|
+
rs[id] = true
|
|
528
|
+
return rs
|
|
529
|
+
}, {})
|
|
530
|
+
})
|
|
531
|
+
}).catch(error => {
|
|
532
|
+
console.warn('[client-chat] reload account data failed', error)
|
|
533
|
+
return {}
|
|
534
|
+
})
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
handleQwContactAdded (contact, eventData, newAccountMap) {
|
|
538
|
+
const qwAccountId = contact.qwAccountId || (eventData && eventData.qwAccountId)
|
|
539
|
+
const corpId = this.getQwAccountCorpId(
|
|
540
|
+
qwAccountId,
|
|
541
|
+
contact.corpId || (eventData && eventData.corpId)
|
|
542
|
+
)
|
|
543
|
+
const contactId = contact.contactId
|
|
544
|
+
// 通讯录是游标分页,新联系人不直接插入本地列表,标记通讯录修改提示用户刷新,同时清理分组数量缓存
|
|
545
|
+
this.contacts.markModify(qwAccountId)
|
|
546
|
+
this.contacts.clearAllFriendGroupCountCache(qwAccountId)
|
|
547
|
+
const accountId = this.getLoginAccountIdMethod ? this.getLoginAccountIdMethod() : qwAccountId
|
|
548
|
+
const sessionId = createSessionId(accountId, contactId)
|
|
549
|
+
if (!sessionId) {
|
|
550
|
+
return Promise.resolve()
|
|
551
|
+
}
|
|
552
|
+
const localSession = this.session.getSessionByLocal(sessionId)
|
|
553
|
+
const oldUnread = localSession ? (localSession.unreadMsgCount || 0) : 0
|
|
554
|
+
return this.session.getSession(sessionId).then(rs => {
|
|
555
|
+
const serverSession = rs && rs.data
|
|
556
|
+
const newUnread = serverSession ? (serverSession.unreadMsgCount || 0) : 0
|
|
557
|
+
const accountId = (serverSession && serverSession.qwAccountId) || qwAccountId
|
|
558
|
+
const unreadDiff = newUnread - oldUnread
|
|
559
|
+
if (accountId && unreadDiff && !(newAccountMap && newAccountMap[accountId])) {
|
|
560
|
+
return this.account.updateAccountUnreadMessageNum(accountId, ({ unreadMesasgeNum }) => {
|
|
561
|
+
return Math.max(0, unreadMesasgeNum + unreadDiff)
|
|
290
562
|
})
|
|
291
563
|
}
|
|
564
|
+
}).catch(error => {
|
|
565
|
+
console.warn('[client-chat] refresh added contact session failed', error)
|
|
566
|
+
})
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
handleQwContactUpdated (contact) {
|
|
570
|
+
if (!contact.contactId) {
|
|
571
|
+
return Promise.resolve()
|
|
572
|
+
}
|
|
573
|
+
return this.contacts.refreshFriend(contact.contactId).catch(error => {
|
|
574
|
+
console.warn('[client-chat] refresh contact failed', error)
|
|
575
|
+
})
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
handleQwContactRemoved (contact, eventData) {
|
|
579
|
+
if (!contact.contactId) {
|
|
580
|
+
return Promise.resolve()
|
|
581
|
+
}
|
|
582
|
+
this.contacts.removeFriend(contact.contactId)
|
|
583
|
+
this.contacts.clearAllFriendGroupCountCache(contact.qwAccountId || (eventData && eventData.qwAccountId))
|
|
584
|
+
let session = this.session.findSession(({ session }) => {
|
|
585
|
+
return String(session.type) === '0' &&
|
|
586
|
+
session.targetId === contact.contactId &&
|
|
587
|
+
(!contact.qwAccountId || session.qwAccountId === contact.qwAccountId)
|
|
588
|
+
})
|
|
589
|
+
if (!session) {
|
|
590
|
+
const qwAccountId = contact.qwAccountId || (eventData && eventData.qwAccountId)
|
|
591
|
+
const accountId = this.getLoginAccountIdMethod ? this.getLoginAccountIdMethod() : qwAccountId
|
|
592
|
+
const sessionId = createSessionId(
|
|
593
|
+
accountId,
|
|
594
|
+
contact.contactId
|
|
595
|
+
)
|
|
596
|
+
session = sessionId && this.session.getSessionByLocal(sessionId)
|
|
597
|
+
}
|
|
598
|
+
if (!session) {
|
|
599
|
+
return Promise.resolve()
|
|
600
|
+
}
|
|
601
|
+
if (this.session.currentSession && this.session.currentSession.id === session.id) {
|
|
602
|
+
this.session.setCurrentSession(null)
|
|
603
|
+
}
|
|
604
|
+
const accountId = session.qwAccountId || contact.qwAccountId
|
|
605
|
+
const unreadCount = session.unreadMsgCount || 0
|
|
606
|
+
this.session.removeSession(session.id)
|
|
607
|
+
return Promise.resolve({
|
|
608
|
+
accountId,
|
|
609
|
+
unreadCount
|
|
292
610
|
})
|
|
293
611
|
}
|
|
294
612
|
|
|
613
|
+
handleQwRoomAdded (room, eventData, newAccountMap) {
|
|
614
|
+
if (!room.roomId) {
|
|
615
|
+
return Promise.resolve()
|
|
616
|
+
}
|
|
617
|
+
const qwAccountId = room.qwAccountId || (eventData && eventData.qwAccountId)
|
|
618
|
+
// 通讯录是游标分页,新群聊不直接插入本地列表,标记通讯录修改提示用户刷新,同时清理分组数量缓存
|
|
619
|
+
this.contacts.markModify(qwAccountId)
|
|
620
|
+
this.contacts.clearAllRoomGroupCountCache(qwAccountId)
|
|
621
|
+
const accountId = this.getLoginAccountIdMethod ? this.getLoginAccountIdMethod() : qwAccountId
|
|
622
|
+
const sessionId = createSessionId(accountId, room.roomId)
|
|
623
|
+
if (!sessionId) {
|
|
624
|
+
return Promise.resolve()
|
|
625
|
+
}
|
|
626
|
+
const localSession = this.session.getSessionByLocal(sessionId)
|
|
627
|
+
const oldUnread = localSession ? (localSession.unreadMsgCount || 0) : 0
|
|
628
|
+
return this.session.getSession(sessionId).then(rs => {
|
|
629
|
+
const serverSession = rs && rs.data
|
|
630
|
+
const unreadDiff = (serverSession ? (serverSession.unreadMsgCount || 0) : 0) - oldUnread
|
|
631
|
+
const changedAccountId = (serverSession && serverSession.qwAccountId) || qwAccountId
|
|
632
|
+
if (changedAccountId && unreadDiff && !(newAccountMap && newAccountMap[changedAccountId])) {
|
|
633
|
+
return this.account.updateAccountUnreadMessageNum(changedAccountId, ({ unreadMesasgeNum }) => {
|
|
634
|
+
return Math.max(0, unreadMesasgeNum + unreadDiff)
|
|
635
|
+
})
|
|
636
|
+
}
|
|
637
|
+
}).catch(error => {
|
|
638
|
+
console.warn('[client-chat] refresh added room session failed', error)
|
|
639
|
+
})
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
handleQwRoomUpdated (room) {
|
|
643
|
+
if (!room.roomId) {
|
|
644
|
+
return Promise.resolve()
|
|
645
|
+
}
|
|
646
|
+
return this.contacts.refreshRoom(room.roomId).catch(error => {
|
|
647
|
+
console.warn('[client-chat] refresh room failed', error)
|
|
648
|
+
})
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
handleQwRoomRemoved (room, eventData) {
|
|
652
|
+
if (!room.roomId) {
|
|
653
|
+
return Promise.resolve()
|
|
654
|
+
}
|
|
655
|
+
this.contacts.removeRoom(room.roomId)
|
|
656
|
+
this.event.emit('roomRemoved', {
|
|
657
|
+
roomId: room.roomId
|
|
658
|
+
})
|
|
659
|
+
const qwAccountId = room.qwAccountId || (eventData && eventData.qwAccountId)
|
|
660
|
+
this.contacts.clearAllRoomGroupCountCache(qwAccountId)
|
|
661
|
+
let session = this.session.findSession(({ session }) => {
|
|
662
|
+
return String(session.type) === '1' &&
|
|
663
|
+
session.targetId === room.roomId &&
|
|
664
|
+
(!qwAccountId || session.qwAccountId === qwAccountId)
|
|
665
|
+
})
|
|
666
|
+
if (!session) {
|
|
667
|
+
const accountId = this.getLoginAccountIdMethod ? this.getLoginAccountIdMethod() : qwAccountId
|
|
668
|
+
const sessionId = createSessionId(accountId, room.roomId)
|
|
669
|
+
session = sessionId && this.session.getSessionByLocal(sessionId)
|
|
670
|
+
}
|
|
671
|
+
if (!session) {
|
|
672
|
+
return Promise.resolve()
|
|
673
|
+
}
|
|
674
|
+
if (this.session.currentSession && this.session.currentSession.id === session.id) {
|
|
675
|
+
this.session.setCurrentSession(null)
|
|
676
|
+
}
|
|
677
|
+
const unreadCount = session.unreadMsgCount || 0
|
|
678
|
+
this.session.removeSession(session.id)
|
|
679
|
+
return Promise.resolve({
|
|
680
|
+
accountId: session.qwAccountId || qwAccountId,
|
|
681
|
+
unreadCount
|
|
682
|
+
})
|
|
683
|
+
}
|
|
684
|
+
|
|
295
685
|
connect () {
|
|
296
686
|
if (this.data.connectStatus === CONNECT_STATUS.Complete) {
|
|
297
687
|
return Promise.resolve()
|
|
@@ -311,12 +701,7 @@ class ClientChat {
|
|
|
311
701
|
|
|
312
702
|
disconnect () {
|
|
313
703
|
this.data.connectStatus = CONNECT_STATUS.Normal
|
|
314
|
-
|
|
315
|
-
Object.keys(this._sessionPollRequestMap).forEach(key => {
|
|
316
|
-
this._sessionPollRequestMap[key].stop()
|
|
317
|
-
})
|
|
318
|
-
this._sessionPollRequestMap = {}
|
|
319
|
-
}
|
|
704
|
+
this.session.stopGetSessionPollRequests()
|
|
320
705
|
this.contacts.reset()
|
|
321
706
|
this.account.reset()
|
|
322
707
|
this.friendMessage.reset()
|
|
@@ -328,4 +713,4 @@ class ClientChat {
|
|
|
328
713
|
}
|
|
329
714
|
}
|
|
330
715
|
|
|
331
|
-
export default ClientChat
|
|
716
|
+
export default ClientChat
|