@aochuang/client-sdk 1.0.378 → 1.0.379-wework

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