@aochuang/client-sdk 1.0.337 → 1.0.339
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/wework-chat-control/util.js +1 -1
- package/components/wework-chat-panel/chat-panel-chat-status/chat-panel-chat-status.vue +73 -0
- package/components/wework-chat-panel/chat-panel-item.vue +5 -28
- package/components/wework-chat-panel/chat-panel.vue +5 -3
- package/package.json +1 -1
- package/services/client-chat/client-chat-wework/client-chat-concats.js +49 -16
- package/services/client-chat/client-chat-wework/client-chat-message.js +5 -5
- package/services/client-chat/client-chat-wework/client-chat-session.js +20 -1
- package/services/client-chat/client-chat-wework/client-chat-socket.js +2 -0
- package/services/client-chat/client-chat-wework/client-chat.js +131 -8
- package/services/client-chat/client-chat-wework/utils.js +2 -2
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="sdk-wework-panel-chat-status">
|
|
3
|
+
<!-- status: 0 success, 1 sending, 2 failed, 3 timeout -->
|
|
4
|
+
<template v-if="data.status === 1">
|
|
5
|
+
<ui-loading size="mini"></ui-loading>
|
|
6
|
+
</template>
|
|
7
|
+
<template v-else-if="data.status === 2">
|
|
8
|
+
<bi-tooltip :text="data.resultMsg || '发送失败'">
|
|
9
|
+
<span class="sdk-wework-panel-chat-status__error">
|
|
10
|
+
<svg class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="200" height="200"><path d="M512 938.666667C276.352 938.666667 85.333333 747.648 85.333333 512S276.352 85.333333 512 85.333333s426.666667 191.018667 426.666667 426.666667-191.018667 426.666667-426.666667 426.666667z m0-486.997334L391.338667 330.965333 330.965333 391.338667 451.669333 512l-120.704 120.661333 60.373334 60.373334L512 572.330667l120.661333 120.704 60.373334-60.373334L572.330667 512l120.704-120.661333-60.373334-60.373334L512 451.669333z" fill="currentColor"></path></svg>
|
|
11
|
+
</span>
|
|
12
|
+
</bi-tooltip>
|
|
13
|
+
</template>
|
|
14
|
+
<template v-else-if="data.status === 3">
|
|
15
|
+
<bi-tooltip :text="data.resultMsg || '发送超时'">
|
|
16
|
+
<span class="sdk-wework-panel-chat-status__error">
|
|
17
|
+
<svg class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="200" height="200"><path d="M512 938.666667C276.352 938.666667 85.333333 747.648 85.333333 512S276.352 85.333333 512 85.333333s426.666667 191.018667 426.666667 426.666667-191.018667 426.666667-426.666667 426.666667z m42.666667-426.666667V298.666667h-85.333334v298.666666h256v-85.333333h-170.666666z" fill="currentColor"></path></svg>
|
|
18
|
+
</span>
|
|
19
|
+
</bi-tooltip>
|
|
20
|
+
</template>
|
|
21
|
+
<template v-if="data.recalled">
|
|
22
|
+
<bi-tooltip text="消息已撤回">
|
|
23
|
+
<span class="sdk-wework-panel-chat-status__error sdk-wework-panel-chat-status__recalled">
|
|
24
|
+
<svg class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="200" height="200"><path d="M512 0c282.752 0 512 229.248 512 512s-229.248 512-512 512S0 794.752 0 512 229.248 0 512 0z m-50.261333 255.317333c-7.765333-39.338667-39.893333-15.36-39.893334-15.36l-213.76 192c-47.616 34.944-2.730667 60.458667-2.730666 60.458667l211.541333 190.933333c42.410667 33.066667 45.866667-17.749333 45.866667-17.749333v-86.442667c215.125333-70.144 303.36 208.341333 303.36 208.341334 7.936 15.957333 13.824 0 13.824 0C862.933333 368.682667 461.952 348.586667 461.952 348.586667z" fill="currentColor"></path></svg>
|
|
25
|
+
</span>
|
|
26
|
+
</bi-tooltip>
|
|
27
|
+
</template>
|
|
28
|
+
</div>
|
|
29
|
+
</template>
|
|
30
|
+
|
|
31
|
+
<script>
|
|
32
|
+
import { Tooltip as BiTooltip } from '@aochuang/common/common'
|
|
33
|
+
import { Loading as UiLoading } from '@aochuang/common/components'
|
|
34
|
+
|
|
35
|
+
export default {
|
|
36
|
+
name: 'SdkWeworkPanelChatStatus',
|
|
37
|
+
components: {
|
|
38
|
+
BiTooltip,
|
|
39
|
+
UiLoading
|
|
40
|
+
},
|
|
41
|
+
props: {
|
|
42
|
+
data: {
|
|
43
|
+
type: Object,
|
|
44
|
+
required: true
|
|
45
|
+
},
|
|
46
|
+
updateChatBoxProp: {
|
|
47
|
+
type: Function
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
<style lang="less">
|
|
54
|
+
.sdk-wework-panel-chat-status__error {
|
|
55
|
+
display: flex;
|
|
56
|
+
flex-direction: row;
|
|
57
|
+
align-items: center;
|
|
58
|
+
font-size: 12px;
|
|
59
|
+
color: #c00;
|
|
60
|
+
width: 16px;
|
|
61
|
+
height: 16px;
|
|
62
|
+
svg {
|
|
63
|
+
width: 100%;
|
|
64
|
+
height: 100%;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
.sdk-wework-panel-chat-status__recalled {
|
|
68
|
+
opacity: .6;
|
|
69
|
+
}
|
|
70
|
+
.sdk-wework-panel-chat-status {
|
|
71
|
+
margin: 0 6px;
|
|
72
|
+
}
|
|
73
|
+
</style>
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
<template v-if="item.msgType !== '_EMPTY_'">
|
|
8
8
|
<slot name="chat-prefix" :item="item"></slot>
|
|
9
9
|
</template>
|
|
10
|
-
<template v-if="
|
|
10
|
+
<template v-if="item.msgType === MESSAGE_TYPE.TEXT || item.msgType === MESSAGE_TYPE.TEXT_W">
|
|
11
11
|
<sdk-chat-panel-box
|
|
12
12
|
:dir="dir"
|
|
13
13
|
:data="item"
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
</template>
|
|
27
27
|
</sdk-chat-panel-box>
|
|
28
28
|
</template>
|
|
29
|
-
<template v-else-if="
|
|
29
|
+
<template v-else-if="item.msgType === MESSAGE_TYPE.IMAGE">
|
|
30
30
|
<sdk-chat-panel-box
|
|
31
31
|
:dir="dir"
|
|
32
32
|
:data="item"
|
|
@@ -289,7 +289,7 @@
|
|
|
289
289
|
</template>
|
|
290
290
|
</sdk-chat-panel-box>
|
|
291
291
|
</template>
|
|
292
|
-
<template v-else-if="item.msgType == MESSAGE_TYPE.URL">
|
|
292
|
+
<template v-else-if="item.msgType == MESSAGE_TYPE.URL || item.msgType == MESSAGE_TYPE.URLNew">
|
|
293
293
|
<sdk-chat-panel-box
|
|
294
294
|
:dir="dir"
|
|
295
295
|
:data="item"
|
|
@@ -312,29 +312,6 @@
|
|
|
312
312
|
</template>
|
|
313
313
|
</sdk-chat-panel-box>
|
|
314
314
|
</template>
|
|
315
|
-
<template v-else-if="[13, 15, 20, 102].includes(item.msgType)">
|
|
316
|
-
<sdk-chat-panel-box
|
|
317
|
-
:dir="dir"
|
|
318
|
-
:data="item"
|
|
319
|
-
:fetchUserMethod="fetchUserMethod"
|
|
320
|
-
bg-color="#fff"
|
|
321
|
-
br-color="#ddd"
|
|
322
|
-
@user-avatar-click="handleUserAvatarClick"
|
|
323
|
-
@user-avatar-contextmenu="handleUserAvatarContextmenu"
|
|
324
|
-
>
|
|
325
|
-
<template slot-scope="{ updateProp }">
|
|
326
|
-
<sdk-chat-control-file-url
|
|
327
|
-
v-bind="configData"
|
|
328
|
-
:id="item.id"
|
|
329
|
-
:content="msgContent"
|
|
330
|
-
:update-chat-box-prop="updateProp"
|
|
331
|
-
></sdk-chat-control-file-url>
|
|
332
|
-
</template>
|
|
333
|
-
<template slot="append" slot-scope="{ updateProp }">
|
|
334
|
-
<slot name="chat-append" :item="item" :update-chat-box-prop="updateProp"></slot>
|
|
335
|
-
</template>
|
|
336
|
-
</sdk-chat-panel-box>
|
|
337
|
-
</template>
|
|
338
315
|
<template v-else-if="item.msgType == MESSAGE_TYPE.CUSTOM_EXPRESSION">
|
|
339
316
|
<sdk-chat-panel-box
|
|
340
317
|
:dir="dir"
|
|
@@ -510,7 +487,7 @@
|
|
|
510
487
|
:content="msgContent"
|
|
511
488
|
></sdk-chat-control-empty>
|
|
512
489
|
</template>
|
|
513
|
-
|
|
490
|
+
<template v-else>
|
|
514
491
|
<sdk-chat-panel-box
|
|
515
492
|
:dir="dir"
|
|
516
493
|
:data="item"
|
|
@@ -523,7 +500,7 @@
|
|
|
523
500
|
:content="msgContent"
|
|
524
501
|
></sdk-chat-control-unknow>
|
|
525
502
|
</sdk-chat-panel-box>
|
|
526
|
-
</template>
|
|
503
|
+
</template>
|
|
527
504
|
</div>
|
|
528
505
|
</template>
|
|
529
506
|
</wework-chat-control-config-msg>
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
:fetch-user-method="fetchUserMethod"
|
|
18
18
|
:config="config"
|
|
19
19
|
>
|
|
20
|
-
|
|
20
|
+
<template slot="chat-append" slot-scope="{ item, updateProp }">
|
|
21
21
|
<chat-panel-chat-status
|
|
22
22
|
:data="item"
|
|
23
23
|
:update-chat-box-prop="updateProp"
|
|
24
24
|
></chat-panel-chat-status>
|
|
25
|
-
</template>
|
|
25
|
+
</template>
|
|
26
26
|
<template slot="chat-prefix" slot-scope="{ item }">
|
|
27
27
|
<template v-if="selectable && handleFilterSelectMessageMethod(item)">
|
|
28
28
|
<div class="sdk-wechat-chat-panel__checkbox">
|
|
@@ -46,12 +46,14 @@
|
|
|
46
46
|
<script>
|
|
47
47
|
import SdkChatPanel from '../chat-panel'
|
|
48
48
|
import ChatPanelItem from './chat-panel-item.vue'
|
|
49
|
+
import ChatPanelChatStatus from './chat-panel-chat-status/chat-panel-chat-status.vue'
|
|
49
50
|
|
|
50
51
|
export default {
|
|
51
52
|
name: 'SdkWeworkChatPanel',
|
|
52
53
|
components: {
|
|
53
54
|
SdkChatPanel,
|
|
54
|
-
ChatPanelItem
|
|
55
|
+
ChatPanelItem,
|
|
56
|
+
ChatPanelChatStatus
|
|
55
57
|
},
|
|
56
58
|
props: {
|
|
57
59
|
mode: {
|
package/package.json
CHANGED
|
@@ -126,11 +126,7 @@ export default class ClientChatContacts {
|
|
|
126
126
|
*/
|
|
127
127
|
roomBindMemberMap: {},
|
|
128
128
|
|
|
129
|
-
|
|
130
|
-
* 标记通讯录是否修改了
|
|
131
|
-
* 如果修改了,比如接收到了分配好友的会话时,一定通讯录变了,变了的时候界面需要根据这个状态刷新通讯录
|
|
132
|
-
*/
|
|
133
|
-
isModify: false
|
|
129
|
+
modifiedAccountMap: {}
|
|
134
130
|
})
|
|
135
131
|
|
|
136
132
|
friendMap = {}
|
|
@@ -237,10 +233,6 @@ export default class ClientChatContacts {
|
|
|
237
233
|
return this.data.roomGroupData
|
|
238
234
|
}
|
|
239
235
|
|
|
240
|
-
get isModify () {
|
|
241
|
-
return this.data.isModify
|
|
242
|
-
}
|
|
243
|
-
|
|
244
236
|
setRoomGroup (data) {
|
|
245
237
|
this.data.roomGroupData = []
|
|
246
238
|
if (data && data.length) {
|
|
@@ -491,10 +483,10 @@ export default class ClientChatContacts {
|
|
|
491
483
|
}
|
|
492
484
|
}
|
|
493
485
|
const qwAccountId = this.roomMap[id].qwAccountId
|
|
494
|
-
if (qwAccountId && this.data.
|
|
495
|
-
const bindIndex = this.data.
|
|
486
|
+
if (qwAccountId && this.data.accountBindRoomMap[qwAccountId] && this.data.accountBindRoomMap[qwAccountId][groupId]) {
|
|
487
|
+
const bindIndex = this.data.accountBindRoomMap[qwAccountId][groupId].indexOf(this.roomMap[id])
|
|
496
488
|
if (bindIndex >= 0) {
|
|
497
|
-
this.data.
|
|
489
|
+
this.data.accountBindRoomMap[qwAccountId][groupId].splice(bindIndex, 1)
|
|
498
490
|
}
|
|
499
491
|
}
|
|
500
492
|
})
|
|
@@ -769,12 +761,52 @@ export default class ClientChatContacts {
|
|
|
769
761
|
})
|
|
770
762
|
}
|
|
771
763
|
|
|
772
|
-
|
|
773
|
-
|
|
764
|
+
refreshRoom (id) {
|
|
765
|
+
if (!id) {
|
|
766
|
+
return Promise.reject('缺少群id')
|
|
767
|
+
}
|
|
768
|
+
if (!this.getContactsRoomMethod) {
|
|
769
|
+
return Promise.reject(new Error('getContactsRoomMethod未定义'))
|
|
770
|
+
}
|
|
771
|
+
return this.getContactsRoomMethod({
|
|
772
|
+
id
|
|
773
|
+
}).then(rs => {
|
|
774
|
+
if (!rs || !rs.data) {
|
|
775
|
+
return Promise.reject('未找到群' + id)
|
|
776
|
+
}
|
|
777
|
+
const localRoom = this.roomMap[id]
|
|
778
|
+
if (localRoom) {
|
|
779
|
+
this.removeRoom(id)
|
|
780
|
+
const nextKeys = Object.keys(rs.data)
|
|
781
|
+
Object.keys(localRoom).forEach(key => {
|
|
782
|
+
if (!nextKeys.includes(key)) {
|
|
783
|
+
Vue.delete(localRoom, key)
|
|
784
|
+
}
|
|
785
|
+
})
|
|
786
|
+
Object.keys(rs.data).forEach(key => {
|
|
787
|
+
Vue.set(localRoom, key, rs.data[key])
|
|
788
|
+
})
|
|
789
|
+
}
|
|
790
|
+
this.addRoom(localRoom || rs.data)
|
|
791
|
+
return rs
|
|
792
|
+
})
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
isModify (qwAccountId) {
|
|
796
|
+
return !!(qwAccountId && this.data.modifiedAccountMap[qwAccountId])
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
markModify (qwAccountIds) {
|
|
800
|
+
const ids = Array.isArray(qwAccountIds) ? qwAccountIds : [qwAccountIds]
|
|
801
|
+
ids.filter(Boolean).forEach(id => {
|
|
802
|
+
Vue.set(this.data.modifiedAccountMap, id, true)
|
|
803
|
+
})
|
|
774
804
|
}
|
|
775
805
|
|
|
776
|
-
unmarkModify () {
|
|
777
|
-
|
|
806
|
+
unmarkModify (qwAccountId) {
|
|
807
|
+
if (qwAccountId) {
|
|
808
|
+
Vue.delete(this.data.modifiedAccountMap, qwAccountId)
|
|
809
|
+
}
|
|
778
810
|
}
|
|
779
811
|
|
|
780
812
|
reset () {
|
|
@@ -789,6 +821,7 @@ export default class ClientChatContacts {
|
|
|
789
821
|
this.data.groupBindRoomMap = {}
|
|
790
822
|
this.data.accountBindFriendMap = {}
|
|
791
823
|
this.data.accountBindRoomMap = {}
|
|
824
|
+
this.data.modifiedAccountMap = {}
|
|
792
825
|
this._cacheFriendGroupCountMap = null
|
|
793
826
|
this._cacheRoomGroupCountMap = null
|
|
794
827
|
if (this.cancelConnectRequest) {
|
|
@@ -74,7 +74,7 @@ export default class ClientChatMessage {
|
|
|
74
74
|
* "msgSvrId": "4319123759514541049",
|
|
75
75
|
* "msgType": 1,
|
|
76
76
|
* "origin": "0",
|
|
77
|
-
* "
|
|
77
|
+
* "status": 0,
|
|
78
78
|
* "tenantId": "1761952223049924608",
|
|
79
79
|
* "wechatAccountId": "ad9d9ae2a8be4f27311312cdd4af3549dc8427ef",
|
|
80
80
|
* "wechatFriendId": "2089efcc7f8f40b00b7f05fa4c6dfd3bb642774d",
|
|
@@ -215,11 +215,11 @@ export default class ClientChatMessage {
|
|
|
215
215
|
}, data, {
|
|
216
216
|
cmdType: 'CmdQwSendMessage'
|
|
217
217
|
})).then(({ data }) => {
|
|
218
|
-
if (data.
|
|
218
|
+
if (data.status === 0) {
|
|
219
219
|
// 发送成功
|
|
220
|
-
} else if (data.
|
|
220
|
+
} else if (data.status === 2) {
|
|
221
221
|
// 发送失败
|
|
222
|
-
} else if (data.
|
|
222
|
+
} else if (data.status === 1) {
|
|
223
223
|
// 发送中
|
|
224
224
|
}
|
|
225
225
|
// 如果返回的是对象,证明发送成功了
|
|
@@ -277,4 +277,4 @@ export default class ClientChatMessage {
|
|
|
277
277
|
reset () {
|
|
278
278
|
this.data.messageData = {}
|
|
279
279
|
}
|
|
280
|
-
}
|
|
280
|
+
}
|
|
@@ -82,7 +82,8 @@ export default class ClientChatSession {
|
|
|
82
82
|
/**
|
|
83
83
|
* 删除会话
|
|
84
84
|
*/
|
|
85
|
-
deleteSessionMethod: null
|
|
85
|
+
deleteSessionMethod: null,
|
|
86
|
+
modifiedAccountMap: {}
|
|
86
87
|
})
|
|
87
88
|
|
|
88
89
|
accountIds = []
|
|
@@ -119,6 +120,23 @@ export default class ClientChatSession {
|
|
|
119
120
|
return this.data.loading
|
|
120
121
|
}
|
|
121
122
|
|
|
123
|
+
isModify (qwAccountId) {
|
|
124
|
+
return !!(qwAccountId && this.data.modifiedAccountMap[qwAccountId])
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
markModify (qwAccountIds) {
|
|
128
|
+
const ids = Array.isArray(qwAccountIds) ? qwAccountIds : [qwAccountIds]
|
|
129
|
+
ids.filter(Boolean).forEach(id => {
|
|
130
|
+
Vue.set(this.data.modifiedAccountMap, id, true)
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
unmarkModify (qwAccountId) {
|
|
135
|
+
if (qwAccountId) {
|
|
136
|
+
Vue.delete(this.data.modifiedAccountMap, qwAccountId)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
122
140
|
get loadAssignTaskSessioning () {
|
|
123
141
|
return this.data.loadAssignTaskSessioning
|
|
124
142
|
}
|
|
@@ -944,6 +962,7 @@ export default class ClientChatSession {
|
|
|
944
962
|
this.data.sessionData = {}
|
|
945
963
|
this.data.sessionGroupData = {}
|
|
946
964
|
this.data.sessionMuteMap = {}
|
|
965
|
+
this.data.modifiedAccountMap = {}
|
|
947
966
|
// this.data.sessionUnreadCountMap = {}
|
|
948
967
|
this.sessionMap = {}
|
|
949
968
|
if (this.cancelLoadDataRequest) {
|
|
@@ -16,6 +16,7 @@ export default class ClietChatSocket {
|
|
|
16
16
|
beforeFireCallback: null,
|
|
17
17
|
onCmdQwNewMessage: null,
|
|
18
18
|
onCmdQwContactInfoChanged: null,
|
|
19
|
+
onCmdQwRoomInfoChanged: null,
|
|
19
20
|
onCmdSendMessageResult: null,
|
|
20
21
|
onCmdFriendInfoChanged: null,
|
|
21
22
|
onCmdDownloadVideoResult: null,
|
|
@@ -29,6 +30,7 @@ export default class ClietChatSocket {
|
|
|
29
30
|
this.socket = options.socket
|
|
30
31
|
this.socket.event.on('onCmdQwNewMessage', options.onCmdQwNewMessage)
|
|
31
32
|
this.socket.event.on('onCmdQwContactInfoChanged', options.onCmdQwContactInfoChanged)
|
|
33
|
+
this.socket.event.on('onCmdQwRoomInfoChanged', options.onCmdQwRoomInfoChanged)
|
|
32
34
|
this.socket.event.on('onHeartbeatCheck', ({ mergeParams }) => {
|
|
33
35
|
options.onHeartbeatCheck && options.onHeartbeatCheck({
|
|
34
36
|
mergeParams
|
|
@@ -113,7 +113,7 @@ class ClientChat {
|
|
|
113
113
|
} else {
|
|
114
114
|
this.session.updateSession(sessionId, ({ session }) => {
|
|
115
115
|
let unreadMsgCount = session.unreadMsgCount
|
|
116
|
-
if (!data.
|
|
116
|
+
if (!data.send) {
|
|
117
117
|
unreadMsgCount = unreadMsgCount + 1
|
|
118
118
|
}
|
|
119
119
|
// 如果是当前会话,那么未读消息需要设置为0
|
|
@@ -184,7 +184,7 @@ class ClientChat {
|
|
|
184
184
|
} else {
|
|
185
185
|
this.session.updateSession(sessionId, ({ session }) => {
|
|
186
186
|
let unreadMsgCount = session.unreadMsgCount
|
|
187
|
-
if (!data.
|
|
187
|
+
if (!data.send) {
|
|
188
188
|
unreadMsgCount = unreadMsgCount + 1
|
|
189
189
|
}
|
|
190
190
|
// 如果是当前会话,那么未读消息需要设置为0
|
|
@@ -262,11 +262,12 @@ class ClientChat {
|
|
|
262
262
|
})
|
|
263
263
|
this.socket = new ClientChatSocket({
|
|
264
264
|
socket: options.socket,
|
|
265
|
-
|
|
265
|
+
onCmdQwContactInfoChanged: ({ data }) => {
|
|
266
266
|
const contacts = data && (Array.isArray(data.contacts)
|
|
267
267
|
? data.contacts
|
|
268
268
|
: (data.contactId ? [data] : []))
|
|
269
269
|
if (!contacts || !contacts.length) {
|
|
270
|
+
this.markAccountsModified(data && data.qwAccountIds)
|
|
270
271
|
return
|
|
271
272
|
}
|
|
272
273
|
const tasks = []
|
|
@@ -303,6 +304,35 @@ class ClientChat {
|
|
|
303
304
|
}))
|
|
304
305
|
})
|
|
305
306
|
},
|
|
307
|
+
onCmdQwRoomInfoChanged: ({ data }) => {
|
|
308
|
+
const rooms = data && (Array.isArray(data.rooms)
|
|
309
|
+
? data.rooms
|
|
310
|
+
: (data.roomId ? [data] : []))
|
|
311
|
+
if (!rooms || !rooms.length) {
|
|
312
|
+
this.markAccountsModified(data && data.qwAccountIds)
|
|
313
|
+
return
|
|
314
|
+
}
|
|
315
|
+
const tasks = []
|
|
316
|
+
const removedTasks = []
|
|
317
|
+
rooms.forEach(room => {
|
|
318
|
+
if (!room) {
|
|
319
|
+
return
|
|
320
|
+
}
|
|
321
|
+
const changeType = Number(room.changeType)
|
|
322
|
+
if (changeType === 1) {
|
|
323
|
+
tasks.push(this.handleQwRoomAdded(room, data))
|
|
324
|
+
} else if (changeType === 2) {
|
|
325
|
+
tasks.push(this.handleQwRoomUpdated(room))
|
|
326
|
+
} else if (changeType === 3) {
|
|
327
|
+
removedTasks.push(this.handleQwRoomRemoved(room, data))
|
|
328
|
+
}
|
|
329
|
+
})
|
|
330
|
+
return Promise.all(tasks.concat(removedTasks)).then(results => {
|
|
331
|
+
return this.updateRemovedSessionUnreadCounts(
|
|
332
|
+
results.slice(tasks.length)
|
|
333
|
+
)
|
|
334
|
+
})
|
|
335
|
+
},
|
|
306
336
|
// 接受新消息
|
|
307
337
|
onCmdQwNewMessage: ({ data }) => {
|
|
308
338
|
// 插入消息
|
|
@@ -345,6 +375,32 @@ class ClientChat {
|
|
|
345
375
|
return account && account.corpId
|
|
346
376
|
}
|
|
347
377
|
|
|
378
|
+
markAccountsModified (qwAccountIds) {
|
|
379
|
+
if (!Array.isArray(qwAccountIds) || !qwAccountIds.length) {
|
|
380
|
+
return
|
|
381
|
+
}
|
|
382
|
+
this.session.markModify(qwAccountIds)
|
|
383
|
+
this.contacts.markModify(qwAccountIds)
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
updateRemovedSessionUnreadCounts (results) {
|
|
387
|
+
const accountUnreadCountMap = {}
|
|
388
|
+
;(results || []).forEach(result => {
|
|
389
|
+
if (!result || !result.accountId || !result.unreadCount) {
|
|
390
|
+
return
|
|
391
|
+
}
|
|
392
|
+
accountUnreadCountMap[result.accountId] = (accountUnreadCountMap[result.accountId] || 0) + result.unreadCount
|
|
393
|
+
})
|
|
394
|
+
return Promise.all(Object.keys(accountUnreadCountMap).map(accountId => {
|
|
395
|
+
const removedUnreadCount = accountUnreadCountMap[accountId]
|
|
396
|
+
return this.account.updateAccountUnreadMessageNum(accountId, ({ unreadMesasgeNum }) => {
|
|
397
|
+
return Math.max(0, unreadMesasgeNum - removedUnreadCount)
|
|
398
|
+
}).catch(error => {
|
|
399
|
+
console.warn('[client-chat] update account unread count failed', error)
|
|
400
|
+
})
|
|
401
|
+
}))
|
|
402
|
+
}
|
|
403
|
+
|
|
348
404
|
handleQwContactAdded (contact, eventData) {
|
|
349
405
|
const qwAccountId = contact.qwAccountId || (eventData && eventData.qwAccountId)
|
|
350
406
|
const corpId = this.getQwAccountCorpId(
|
|
@@ -359,7 +415,6 @@ class ClientChat {
|
|
|
359
415
|
}
|
|
360
416
|
const localSession = this.session.getSessionByLocal(sessionId)
|
|
361
417
|
const oldUnread = localSession ? (localSession.unreadMsgCount || 0) : 0
|
|
362
|
-
this.contacts.markModify()
|
|
363
418
|
return this.session.refreshSession(sessionId).then(rs => {
|
|
364
419
|
const serverSession = rs && rs.data
|
|
365
420
|
const newUnread = serverSession ? (serverSession.unreadMsgCount || 0) : 0
|
|
@@ -379,9 +434,7 @@ class ClientChat {
|
|
|
379
434
|
if (!contact.contactId) {
|
|
380
435
|
return Promise.resolve()
|
|
381
436
|
}
|
|
382
|
-
return this.contacts.refreshFriend(contact.contactId).
|
|
383
|
-
this.contacts.markModify()
|
|
384
|
-
}).catch(error => {
|
|
437
|
+
return this.contacts.refreshFriend(contact.contactId).catch(error => {
|
|
385
438
|
console.warn('[client-chat] refresh contact failed', error)
|
|
386
439
|
})
|
|
387
440
|
}
|
|
@@ -405,7 +458,6 @@ class ClientChat {
|
|
|
405
458
|
)
|
|
406
459
|
session = sessionId && this.session.getSessionByLocal(sessionId)
|
|
407
460
|
}
|
|
408
|
-
this.contacts.markModify()
|
|
409
461
|
if (!session) {
|
|
410
462
|
return Promise.resolve()
|
|
411
463
|
}
|
|
@@ -421,6 +473,77 @@ class ClientChat {
|
|
|
421
473
|
})
|
|
422
474
|
}
|
|
423
475
|
|
|
476
|
+
handleQwRoomAdded (room, eventData) {
|
|
477
|
+
if (!room.roomId) {
|
|
478
|
+
return Promise.resolve()
|
|
479
|
+
}
|
|
480
|
+
const qwAccountId = room.qwAccountId || (eventData && eventData.qwAccountId)
|
|
481
|
+
const accountId = this.getLoginAccountIdMethod ? this.getLoginAccountIdMethod() : qwAccountId
|
|
482
|
+
const sessionId = createSessionId(accountId, room.roomId)
|
|
483
|
+
const localSession = sessionId && this.session.getSessionByLocal(sessionId)
|
|
484
|
+
const oldUnread = localSession ? (localSession.unreadMsgCount || 0) : 0
|
|
485
|
+
const tasks = [this.contacts.refreshRoom(room.roomId).catch(error => {
|
|
486
|
+
console.warn('[client-chat] refresh added room failed', error)
|
|
487
|
+
})]
|
|
488
|
+
if (sessionId) {
|
|
489
|
+
tasks.push(this.session.refreshSession(sessionId).then(rs => {
|
|
490
|
+
const serverSession = rs && rs.data
|
|
491
|
+
const unreadDiff = (serverSession ? (serverSession.unreadMsgCount || 0) : 0) - oldUnread
|
|
492
|
+
const changedAccountId = (serverSession && serverSession.qwAccountId) || qwAccountId
|
|
493
|
+
if (changedAccountId && unreadDiff) {
|
|
494
|
+
return this.account.updateAccountUnreadMessageNum(changedAccountId, ({ unreadMesasgeNum }) => {
|
|
495
|
+
return Math.max(0, unreadMesasgeNum + unreadDiff)
|
|
496
|
+
})
|
|
497
|
+
}
|
|
498
|
+
}).catch(error => {
|
|
499
|
+
console.warn('[client-chat] refresh added room session failed', error)
|
|
500
|
+
}))
|
|
501
|
+
}
|
|
502
|
+
return Promise.all(tasks)
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
handleQwRoomUpdated (room) {
|
|
506
|
+
if (!room.roomId) {
|
|
507
|
+
return Promise.resolve()
|
|
508
|
+
}
|
|
509
|
+
return this.contacts.refreshRoom(room.roomId).catch(error => {
|
|
510
|
+
console.warn('[client-chat] refresh room failed', error)
|
|
511
|
+
})
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
handleQwRoomRemoved (room, eventData) {
|
|
515
|
+
if (!room.roomId) {
|
|
516
|
+
return Promise.resolve()
|
|
517
|
+
}
|
|
518
|
+
this.contacts.removeRoom(room.roomId)
|
|
519
|
+
this.event.emit('roomRemoved', {
|
|
520
|
+
roomId: room.roomId
|
|
521
|
+
})
|
|
522
|
+
const qwAccountId = room.qwAccountId || (eventData && eventData.qwAccountId)
|
|
523
|
+
let session = this.session.findSession(({ session }) => {
|
|
524
|
+
return String(session.type) === '1' &&
|
|
525
|
+
session.targetId === room.roomId &&
|
|
526
|
+
(!qwAccountId || session.qwAccountId === qwAccountId)
|
|
527
|
+
})
|
|
528
|
+
if (!session) {
|
|
529
|
+
const accountId = this.getLoginAccountIdMethod ? this.getLoginAccountIdMethod() : qwAccountId
|
|
530
|
+
const sessionId = createSessionId(accountId, room.roomId)
|
|
531
|
+
session = sessionId && this.session.getSessionByLocal(sessionId)
|
|
532
|
+
}
|
|
533
|
+
if (!session) {
|
|
534
|
+
return Promise.resolve()
|
|
535
|
+
}
|
|
536
|
+
if (this.session.currentSession && this.session.currentSession.id === session.id) {
|
|
537
|
+
this.session.setCurrentSession(null)
|
|
538
|
+
}
|
|
539
|
+
const unreadCount = session.unreadMsgCount || 0
|
|
540
|
+
this.session.removeSession(session.id)
|
|
541
|
+
return Promise.resolve({
|
|
542
|
+
accountId: session.qwAccountId || qwAccountId,
|
|
543
|
+
unreadCount
|
|
544
|
+
})
|
|
545
|
+
}
|
|
546
|
+
|
|
424
547
|
connect () {
|
|
425
548
|
if (this.data.connectStatus === CONNECT_STATUS.Complete) {
|
|
426
549
|
return Promise.resolve()
|
|
@@ -54,7 +54,7 @@ export function createSessionId (accountId, targetId) {
|
|
|
54
54
|
* "msgSvrId": "4319123759514541049",
|
|
55
55
|
* "msgType": 1,
|
|
56
56
|
* "origin": "0",
|
|
57
|
-
* "
|
|
57
|
+
* "status": 0,
|
|
58
58
|
* "tenantId": "1761952223049924608",
|
|
59
59
|
* "wechatAccountId": "ad9d9ae2a8be4f27311312cdd4af3549dc8427ef",
|
|
60
60
|
* "wechatFriendId": "2089efcc7f8f40b00b7f05fa4c6dfd3bb642774d",
|
|
@@ -79,4 +79,4 @@ export function createSessionData (message) {
|
|
|
79
79
|
wechatAccountId: message.wechatAccountId
|
|
80
80
|
}
|
|
81
81
|
return nextSession
|
|
82
|
-
}
|
|
82
|
+
}
|