@aochuang/client-sdk 1.0.336 → 1.0.338

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.
@@ -5,10 +5,8 @@
5
5
  <div class="sdk-session-item__avatar-image">
6
6
  <slot name="avatar"></slot>
7
7
  </div>
8
- <span class="sdk-session-item__avatar-badge">
8
+ <span v-if="data[unreadMsgCountField]" class="sdk-session-item__avatar-badge" :class="{'is-mute': data[muteField]}">
9
9
  <sdk-badge
10
- :class="{'is-mute': data[muteField]}"
11
- v-if="data[unreadMsgCountField]"
12
10
  :is-dot="data[muteField]"
13
11
  :value="data[unreadMsgCountField]"
14
12
  :max="99"
@@ -8,7 +8,7 @@ export const MESSAGE_TYPE = {
8
8
  CUSTOM_EXPRESSION_W: 104,
9
9
  // MUSIC: 1040187441,
10
10
  // ROOM_CALLING: 64,
11
- SHARE_CARD: 41,
11
+ SHARE_CARD: 31,
12
12
  // COMPANY_CARD: 41,
13
13
  // VIDEO: 43,
14
14
  // CUSTOM_EXPRESSION: 47,
@@ -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="[0, 1, 2].includes(item.msgType)">
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="[14, 101].includes(item.msgType)">
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
- <!-- <template v-else>
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>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aochuang/client-sdk",
3
- "version": "1.0.336",
3
+ "version": "1.0.338",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -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.accountBindFriendMap[qwAccountId] && this.data.accountBindFriendMap[qwAccountId][groupId]) {
495
- const bindIndex = this.data.accountBindFriendMap[qwAccountId][groupId].indexOf(this.roomMap[id])
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.accountBindFriendMap[qwAccountId][groupId].splice(bindIndex, 1)
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
- markModify () {
773
- this.data.isModify = true
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
- this.data.isModify = false
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) {
@@ -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.isSend) {
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.isSend) {
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
- onCmdQwContactInfoChanged: ({ data }) => {
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).then(() => {
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()