@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
|
@@ -2,6 +2,7 @@ import Vue from 'vue'
|
|
|
2
2
|
import Event from '../../../utils/event.js'
|
|
3
3
|
import { unique } from '../../../utils/string.js'
|
|
4
4
|
import { formatDate } from '../../../utils/date.js'
|
|
5
|
+
import { createPromise } from '../../../utils/util'
|
|
5
6
|
|
|
6
7
|
export default class ClientChatMessage {
|
|
7
8
|
|
|
@@ -20,8 +21,12 @@ export default class ClientChatMessage {
|
|
|
20
21
|
*/
|
|
21
22
|
messageData: {}
|
|
22
23
|
})
|
|
23
|
-
|
|
24
|
+
|
|
24
25
|
messageMap = {}
|
|
26
|
+
lastMessageTimeMap = {}
|
|
27
|
+
tempMessageMap = {}
|
|
28
|
+
checkMessageSendResultTaskList = []
|
|
29
|
+
recallTaskMap = {}
|
|
25
30
|
|
|
26
31
|
get messageData () {
|
|
27
32
|
return this.data.messageData
|
|
@@ -33,18 +38,29 @@ export default class ClientChatMessage {
|
|
|
33
38
|
queryMethod: null,
|
|
34
39
|
sortField: null, // 排序的字段,必须是唯一的,例如时间
|
|
35
40
|
groupField: null, // 分组的字段
|
|
41
|
+
checkMessageSendResultMethod: null,
|
|
42
|
+
recallMessageMethod: null,
|
|
43
|
+
recallMessageIdField: null,
|
|
36
44
|
onAddMessageSuccess: null // 新增消息成功回调事件
|
|
37
45
|
}, options)
|
|
38
46
|
if (!options.clientChat) {
|
|
39
47
|
throw new Error('必须将clientChat传递过来')
|
|
40
48
|
}
|
|
49
|
+
if (!options.checkMessageSendResultMethod) throw new Error('缺少checkMessageSendResultMethod配置')
|
|
41
50
|
this.queryMethod = options.queryMethod
|
|
42
51
|
this.clientChat = options.clientChat
|
|
43
52
|
this.groupField = options.groupField
|
|
44
53
|
this.sortField = options.sortField
|
|
54
|
+
this.checkMessageSendResultMethod = options.checkMessageSendResultMethod
|
|
55
|
+
this.recallMessageMethod = options.recallMessageMethod
|
|
56
|
+
this.recallMessageIdField = options.recallMessageIdField
|
|
45
57
|
this.onAddMessageSuccess = options.onAddMessageSuccess
|
|
46
58
|
this.event = new Event()
|
|
47
59
|
}
|
|
60
|
+
|
|
61
|
+
setRelatedMessageService (messageService) {
|
|
62
|
+
this.relatedMessageService = messageService
|
|
63
|
+
}
|
|
48
64
|
|
|
49
65
|
getSortField (time) {
|
|
50
66
|
const step = 1000 * 60 * 60 * 24
|
|
@@ -74,7 +90,7 @@ export default class ClientChatMessage {
|
|
|
74
90
|
* "msgSvrId": "4319123759514541049",
|
|
75
91
|
* "msgType": 1,
|
|
76
92
|
* "origin": "0",
|
|
77
|
-
* "
|
|
93
|
+
* "status": 0,
|
|
78
94
|
* "tenantId": "1761952223049924608",
|
|
79
95
|
* "wechatAccountId": "ad9d9ae2a8be4f27311312cdd4af3549dc8427ef",
|
|
80
96
|
* "wechatFriendId": "2089efcc7f8f40b00b7f05fa4c6dfd3bb642774d",
|
|
@@ -89,7 +105,13 @@ export default class ClientChatMessage {
|
|
|
89
105
|
if (this.messageMap[data.id]) {
|
|
90
106
|
return
|
|
91
107
|
}
|
|
108
|
+
if (this.tempMessageMap[data.id]) {
|
|
109
|
+
Object.assign(data, this.tempMessageMap[data.id])
|
|
110
|
+
delete this.tempMessageMap[data.id]
|
|
111
|
+
}
|
|
92
112
|
const groupField = data[this.groupField]
|
|
113
|
+
const lastMessageTime = this.getLastMessageTime(groupField)
|
|
114
|
+
const isBeforeLastMessage = !data.isSend && lastMessageTime && data[this.sortField] < lastMessageTime
|
|
93
115
|
if (!this.data.messageData[groupField]) {
|
|
94
116
|
Vue.set(this.data.messageData, groupField, {})
|
|
95
117
|
}
|
|
@@ -105,13 +127,27 @@ export default class ClientChatMessage {
|
|
|
105
127
|
}
|
|
106
128
|
this.data.messageData[groupField][sortFields.day][sortFields.milliseconds].push(data)
|
|
107
129
|
this.messageMap[data.id] = data
|
|
130
|
+
this.setLastMessageTime(groupField, data[this.sortField], data)
|
|
131
|
+
if (data.isSend && data.status === 1 && !data._temp) this.addCheckMessageSendResultTask(data)
|
|
108
132
|
if (fireEvent !== false) {
|
|
133
|
+
try {
|
|
134
|
+
this.onAddMessageSuccess && this.onAddMessageSuccess({
|
|
135
|
+
data,
|
|
136
|
+
lastMessageTime,
|
|
137
|
+
isBeforeLastMessage
|
|
138
|
+
})
|
|
139
|
+
} catch (error) {
|
|
140
|
+
console.error('[client-chat-message] onAddMessageSuccess error', {
|
|
141
|
+
messageId: data.id,
|
|
142
|
+
error
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
if (isBeforeLastMessage) {
|
|
146
|
+
return
|
|
147
|
+
}
|
|
109
148
|
this.event && this.event.emit('add-message', {
|
|
110
149
|
data
|
|
111
150
|
})
|
|
112
|
-
this.onAddMessageSuccess && this.onAddMessageSuccess({
|
|
113
|
-
data
|
|
114
|
-
})
|
|
115
151
|
}
|
|
116
152
|
}
|
|
117
153
|
|
|
@@ -119,6 +155,8 @@ export default class ClientChatMessage {
|
|
|
119
155
|
if (!id) {
|
|
120
156
|
return
|
|
121
157
|
}
|
|
158
|
+
this.removeCheckMessageSendResultTask(id)
|
|
159
|
+
this.clearRecallState(id)
|
|
122
160
|
const message = this.messageMap[id]
|
|
123
161
|
if (!message) {
|
|
124
162
|
return
|
|
@@ -147,21 +185,57 @@ export default class ClientChatMessage {
|
|
|
147
185
|
delete this.data.messageData[groupField]
|
|
148
186
|
}
|
|
149
187
|
this.event && this.event.emit('remove-message', {
|
|
150
|
-
data
|
|
188
|
+
data: message
|
|
151
189
|
})
|
|
152
190
|
}
|
|
153
191
|
|
|
154
192
|
updateMessage (id, props) {
|
|
155
193
|
const message = this.getMessage(id)
|
|
156
194
|
if (!message) {
|
|
195
|
+
this.tempMessageMap[id] = props
|
|
157
196
|
return
|
|
158
197
|
}
|
|
159
198
|
if (!props) {
|
|
160
199
|
return
|
|
161
200
|
}
|
|
201
|
+
const groupField = message[this.groupField]
|
|
202
|
+
const oldSortFieldValue = message[this.sortField]
|
|
203
|
+
const oldSortFields = this.getSortField(oldSortFieldValue)
|
|
162
204
|
Object.keys(props).forEach(key => {
|
|
163
|
-
message
|
|
205
|
+
Vue.set(message, key, props[key])
|
|
164
206
|
})
|
|
207
|
+
if (typeof props[this.sortField] !== 'undefined' && props[this.sortField] !== oldSortFieldValue) {
|
|
208
|
+
const oldBucket = this.data.messageData[groupField] &&
|
|
209
|
+
this.data.messageData[groupField][oldSortFields.day] &&
|
|
210
|
+
this.data.messageData[groupField][oldSortFields.day][oldSortFields.milliseconds]
|
|
211
|
+
if (oldBucket) {
|
|
212
|
+
const index = oldBucket.findIndex(item => item.id === message.id)
|
|
213
|
+
if (index >= 0) {
|
|
214
|
+
oldBucket.splice(index, 1)
|
|
215
|
+
}
|
|
216
|
+
if (!oldBucket.length) {
|
|
217
|
+
Vue.delete(this.data.messageData[groupField][oldSortFields.day], oldSortFields.milliseconds)
|
|
218
|
+
}
|
|
219
|
+
if (!Object.keys(this.data.messageData[groupField][oldSortFields.day]).length) {
|
|
220
|
+
Vue.delete(this.data.messageData[groupField], oldSortFields.day)
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
const newSortFields = this.getSortField(message[this.sortField])
|
|
224
|
+
if (!this.data.messageData[groupField]) {
|
|
225
|
+
Vue.set(this.data.messageData, groupField, {})
|
|
226
|
+
}
|
|
227
|
+
if (!this.data.messageData[groupField][newSortFields.day]) {
|
|
228
|
+
Vue.set(this.data.messageData[groupField], newSortFields.day, {})
|
|
229
|
+
}
|
|
230
|
+
if (!this.data.messageData[groupField][newSortFields.day][newSortFields.milliseconds]) {
|
|
231
|
+
Vue.set(this.data.messageData[groupField][newSortFields.day], newSortFields.milliseconds, [])
|
|
232
|
+
}
|
|
233
|
+
const newBucket = this.data.messageData[groupField][newSortFields.day][newSortFields.milliseconds]
|
|
234
|
+
if (!newBucket.some(item => item.id === message.id)) {
|
|
235
|
+
newBucket.push(message)
|
|
236
|
+
}
|
|
237
|
+
this.setLastMessageTime(groupField, message[this.sortField], message)
|
|
238
|
+
}
|
|
165
239
|
}
|
|
166
240
|
|
|
167
241
|
getMessage (id) {
|
|
@@ -178,6 +252,7 @@ export default class ClientChatMessage {
|
|
|
178
252
|
message
|
|
179
253
|
})
|
|
180
254
|
if (rs === false) {
|
|
255
|
+
this.clearRecallState(message.id)
|
|
181
256
|
delete this.messageMap[message.id]
|
|
182
257
|
}
|
|
183
258
|
return rs
|
|
@@ -199,6 +274,8 @@ export default class ClientChatMessage {
|
|
|
199
274
|
return rs
|
|
200
275
|
}, {})
|
|
201
276
|
} else {
|
|
277
|
+
this.clearRecallTasks()
|
|
278
|
+
this.tempMessageMap = {}
|
|
202
279
|
this.data.messageData = {}
|
|
203
280
|
this.messageMap = {}
|
|
204
281
|
}
|
|
@@ -215,11 +292,11 @@ export default class ClientChatMessage {
|
|
|
215
292
|
}, data, {
|
|
216
293
|
cmdType: 'CmdQwSendMessage'
|
|
217
294
|
})).then(({ data }) => {
|
|
218
|
-
if (data.
|
|
295
|
+
if (data.status === 0) {
|
|
219
296
|
// 发送成功
|
|
220
|
-
} else if (data.
|
|
297
|
+
} else if (data.status === 2) {
|
|
221
298
|
// 发送失败
|
|
222
|
-
} else if (data.
|
|
299
|
+
} else if (data.status === 1) {
|
|
223
300
|
// 发送中
|
|
224
301
|
}
|
|
225
302
|
// 如果返回的是对象,证明发送成功了
|
|
@@ -230,6 +307,139 @@ export default class ClientChatMessage {
|
|
|
230
307
|
return data
|
|
231
308
|
})
|
|
232
309
|
}
|
|
310
|
+
|
|
311
|
+
getRecallMessage (id) {
|
|
312
|
+
return this.getMessage(id) || this.tempMessageMap[id] ||
|
|
313
|
+
(this.relatedMessageService && (this.relatedMessageService.getMessage(id) || this.relatedMessageService.tempMessageMap[id]))
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
updateRecallMessage (id, props) {
|
|
317
|
+
this.updateMessage(id, props)
|
|
318
|
+
if (this.relatedMessageService) {
|
|
319
|
+
this.relatedMessageService.updateMessage(id, props)
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
clearRecallTask (id) {
|
|
324
|
+
const task = this.recallTaskMap[id]
|
|
325
|
+
if (!task) {
|
|
326
|
+
return
|
|
327
|
+
}
|
|
328
|
+
clearTimeout(task.timer)
|
|
329
|
+
delete this.recallTaskMap[id]
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
clearRecallState (id) {
|
|
333
|
+
this.clearRecallTask(id)
|
|
334
|
+
delete this.tempMessageMap[id]
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
getRecallErrorMessage (error) {
|
|
338
|
+
const responseData = error && error.response && error.response.data
|
|
339
|
+
if (responseData) {
|
|
340
|
+
return responseData.msg || responseData.message || responseData.error_description || '未知原因'
|
|
341
|
+
}
|
|
342
|
+
if (typeof error === 'string') {
|
|
343
|
+
return error
|
|
344
|
+
}
|
|
345
|
+
return (error && (error.errMsg || error.message)) || '未知原因'
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
recallMessage (params) {
|
|
349
|
+
const data = params || {}
|
|
350
|
+
const messageId = data[this.recallMessageIdField]
|
|
351
|
+
if (!this.recallMessageIdField || !messageId) {
|
|
352
|
+
return Promise.reject(new Error('缺少消息ID'))
|
|
353
|
+
}
|
|
354
|
+
if (!data.sendTime) {
|
|
355
|
+
return Promise.reject(new Error('缺少消息发送时间'))
|
|
356
|
+
}
|
|
357
|
+
if (!this.recallMessageMethod) {
|
|
358
|
+
return Promise.reject(new Error('缺少撤回消息接口配置'))
|
|
359
|
+
}
|
|
360
|
+
const message = this.getRecallMessage(messageId)
|
|
361
|
+
if (message && message.recalled) {
|
|
362
|
+
return Promise.reject(new Error('消息已撤回'))
|
|
363
|
+
}
|
|
364
|
+
if (message && message.recalling) {
|
|
365
|
+
return Promise.reject(new Error('消息正在撤回中'))
|
|
366
|
+
}
|
|
367
|
+
const requestData = {
|
|
368
|
+
[this.recallMessageIdField]: messageId,
|
|
369
|
+
sendTime: data.sendTime
|
|
370
|
+
}
|
|
371
|
+
this.clearRecallTask(messageId)
|
|
372
|
+
this.updateRecallMessage(messageId, {
|
|
373
|
+
recalling: true,
|
|
374
|
+
recallStatus: null,
|
|
375
|
+
recallResultMsg: null
|
|
376
|
+
})
|
|
377
|
+
const task = {
|
|
378
|
+
timer: setTimeout(() => {
|
|
379
|
+
if (this.recallTaskMap[messageId] !== task) {
|
|
380
|
+
return
|
|
381
|
+
}
|
|
382
|
+
delete this.recallTaskMap[messageId]
|
|
383
|
+
this.updateRecallMessage(messageId, {
|
|
384
|
+
recalling: false,
|
|
385
|
+
recallStatus: 'timeout',
|
|
386
|
+
recallResultMsg: '获取结果超时'
|
|
387
|
+
})
|
|
388
|
+
}, 10 * 1000)
|
|
389
|
+
}
|
|
390
|
+
this.recallTaskMap[messageId] = task
|
|
391
|
+
|
|
392
|
+
return Promise.resolve().then(() => this.recallMessageMethod(requestData)).catch(error => {
|
|
393
|
+
if (this.recallTaskMap[messageId] === task) {
|
|
394
|
+
this.clearRecallTask(messageId)
|
|
395
|
+
this.updateRecallMessage(messageId, {
|
|
396
|
+
recalling: false,
|
|
397
|
+
recallStatus: 'failed',
|
|
398
|
+
recallResultMsg: this.getRecallErrorMessage(error)
|
|
399
|
+
})
|
|
400
|
+
}
|
|
401
|
+
return Promise.reject(error)
|
|
402
|
+
})
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
handleMessageRecalled (data) {
|
|
406
|
+
const messageId = data && data[this.recallMessageIdField]
|
|
407
|
+
if (!messageId) {
|
|
408
|
+
return
|
|
409
|
+
}
|
|
410
|
+
this.clearRecallTask(messageId)
|
|
411
|
+
this.updateRecallMessage(messageId, {
|
|
412
|
+
recalled: true,
|
|
413
|
+
recalling: false,
|
|
414
|
+
recallStatus: null,
|
|
415
|
+
recallResultMsg: null,
|
|
416
|
+
revokeTime: data.revokeTime
|
|
417
|
+
})
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
handleMessageRecallFailed (data) {
|
|
421
|
+
const messageId = data && data[this.recallMessageIdField]
|
|
422
|
+
if (!messageId) {
|
|
423
|
+
return
|
|
424
|
+
}
|
|
425
|
+
const message = this.getRecallMessage(messageId)
|
|
426
|
+
if (message && message.recalled) {
|
|
427
|
+
return
|
|
428
|
+
}
|
|
429
|
+
this.clearRecallTask(messageId)
|
|
430
|
+
this.updateRecallMessage(messageId, {
|
|
431
|
+
recalling: false,
|
|
432
|
+
recallStatus: 'failed',
|
|
433
|
+
recallResultMsg: data.reason || '未知原因'
|
|
434
|
+
})
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
clearRecallTasks () {
|
|
438
|
+
Object.keys(this.recallTaskMap).forEach(id => {
|
|
439
|
+
clearTimeout(this.recallTaskMap[id].timer)
|
|
440
|
+
})
|
|
441
|
+
this.recallTaskMap = {}
|
|
442
|
+
}
|
|
233
443
|
|
|
234
444
|
/***
|
|
235
445
|
* 远程加载消息
|
|
@@ -273,8 +483,55 @@ export default class ClientChatMessage {
|
|
|
273
483
|
this.clearMessage()
|
|
274
484
|
return this.loadMessageData(params)
|
|
275
485
|
}
|
|
486
|
+
|
|
487
|
+
addCheckMessageSendResultTask (message) {
|
|
488
|
+
if (this.checkMessageSendResultTaskList.some(v => v.id === message.id)) return
|
|
489
|
+
let timer
|
|
490
|
+
const task = { id: message.id, promise: createPromise(), check: () => {
|
|
491
|
+
if (message.status !== 1) return task.promise.resolve()
|
|
492
|
+
if (Date.now() - (message.createTime || message.sendTime) > 5 * 60 * 1000) return task.promise.resolve({status: 3, resultMsg: '消息发送超时'})
|
|
493
|
+
timer = setTimeout(() => {
|
|
494
|
+
Promise.resolve(this.checkMessageSendResultMethod({message})).then(rs => {
|
|
495
|
+
const data = rs && rs.data
|
|
496
|
+
if (data && data.status === 1) task.check()
|
|
497
|
+
else task.promise.resolve(data || {})
|
|
498
|
+
}, () => task.check())
|
|
499
|
+
}, 3000)
|
|
500
|
+
}, cancel: () => { clearTimeout(timer); task.promise.reject('reject') } }
|
|
501
|
+
this.checkMessageSendResultTaskList.push(task)
|
|
502
|
+
task.check()
|
|
503
|
+
task.promise.then(rs => this.updateMessage(message.id, rs || {})).finally(() => this.removeCheckMessageSendResultTask(message.id))
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
removeCheckMessageSendResultTask (id) {
|
|
507
|
+
const index = this.checkMessageSendResultTaskList.findIndex(v => v.id === id)
|
|
508
|
+
if (index >= 0) { this.checkMessageSendResultTaskList[index].cancel(); this.checkMessageSendResultTaskList.splice(index, 1) }
|
|
509
|
+
}
|
|
276
510
|
|
|
277
511
|
reset () {
|
|
512
|
+
this.clearRecallTasks()
|
|
513
|
+
this.checkMessageSendResultTaskList.forEach(task => task.cancel())
|
|
514
|
+
this.checkMessageSendResultTaskList = []
|
|
515
|
+
this.tempMessageMap = {}
|
|
516
|
+
this.messageMap = {}
|
|
517
|
+
this.lastMessageTimeMap = {}
|
|
278
518
|
this.data.messageData = {}
|
|
279
519
|
}
|
|
280
|
-
|
|
520
|
+
|
|
521
|
+
getLastMessageTime (groupField) {
|
|
522
|
+
return this.lastMessageTimeMap[groupField]
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
setLastMessageTime (groupField, messageTime, message) {
|
|
526
|
+
if (!groupField || !messageTime || (message && message.msgType === '_EMPTY_')) {
|
|
527
|
+
return
|
|
528
|
+
}
|
|
529
|
+
if (message && message._temp) {
|
|
530
|
+
return
|
|
531
|
+
}
|
|
532
|
+
const lastMessageTime = this.getLastMessageTime(groupField)
|
|
533
|
+
if (!lastMessageTime || messageTime > lastMessageTime) {
|
|
534
|
+
this.lastMessageTimeMap[groupField] = messageTime
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|