@aochuang/client-sdk 1.0.305 → 1.0.307

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.
@@ -252,12 +252,18 @@ export default {
252
252
  this.filters.friendGroupEmpty = !this.filters.friendGroupEmpty
253
253
  },
254
254
  handleFriendRefreshClick () {
255
+ if (this.friendRefreshing) {
256
+ return
257
+ }
255
258
  this.friendRefreshing = true
256
259
  this.loadData().finally(() => {
257
260
  this.friendRefreshing = false
258
261
  })
259
262
  },
260
263
  handleRoomRefreshClick () {
264
+ if (this.roomRefreshing) {
265
+ return
266
+ }
261
267
  this.roomRefreshing = true
262
268
  this.loadData().finally(() => {
263
269
  this.roomRefreshing = false
@@ -190,45 +190,45 @@ export function formatShortSessionMessage (session, contextFn) {
190
190
  if (!session.lastMsgType) {
191
191
  return
192
192
  }
193
- if (session.lastMsgType === MESSAGE_TYPE.TEXT_WITH_AT) {
194
- const content = toJson(session.lastMsgContent)
195
- if (!contextFn) {
196
- throw new Error('缺少上下文函数')
197
- }
198
- if (content && content.text && content.text.indexOf('@所有人') >= 0) {
199
- const contextRs = contextFn()
200
- if (contextRs && contextRs.then) {
201
- return contextRs.then(rs => {
202
- // 有未读消息才需要高亮红色提示
203
- if (rs.session && rs.session.unreadMsgCount > 0) {
204
- return `<span style="color: #e2544b;">[@所有人]</span>${html2Escape(content.text)}`
205
- } else {
206
- return formatShortMessage(session.lastMsgType, session.lastMsgContent)
207
- }
208
- })
209
- } else {
210
- return formatShortMessage(session.lastMsgType, session.lastMsgContent)
211
- }
212
- } else if (content && content.atWechatIdsHash && content.atWechatIdsHash.length) {
213
- const contextRs = contextFn()
214
- if (contextRs && contextRs.then) {
215
- return contextRs.then(rs => {
216
- if (!rs.wechatAccount) {
217
- return formatShortMessage(session.lastMsgType, session.lastMsgContent)
218
- }
219
- // 有未读消息才需要高亮红色提示
220
- if (content.atWechatIdsHash.includes(rs.wechatAccount.wechatIdHash) && rs.session && rs.session.unreadMsgCount > 0) {
221
- return `<span style="color: #e2544b;">[有人@我]</span>${html2Escape(content.text)}`
222
- } else {
223
- return formatShortMessage(session.lastMsgType, session.lastMsgContent)
224
- }
225
- })
226
- } else {
227
- return formatShortMessage(session.lastMsgType, session.lastMsgContent)
228
- }
229
- } else {
230
- return formatShortMessage(session.lastMsgType, session.lastMsgContent)
193
+ const shortMessage = formatShortMessage(session.lastMsgType, session.lastMsgContent)
194
+ if (!session.unreadMsgCount) {
195
+ return shortMessage
196
+ }
197
+ const atMessages = getUnreadAtMessageContents(session)
198
+ .map(content => toJson(content))
199
+ .filter(content => content && content.text)
200
+ if (!atMessages.length) {
201
+ return shortMessage
202
+ }
203
+ if (atMessages.some(content => content.text.indexOf('@所有人') >= 0)) {
204
+ return `<span style="color: #e2544b; margin-right: 4px;">[@所有人]</span>${shortMessage}`
205
+ }
206
+ const atWechatIdsHash = atMessages.reduce((ids, content) => {
207
+ return ids.concat(Array.isArray(content.atWechatIdsHash) ? content.atWechatIdsHash : [])
208
+ }, [])
209
+ if (!atWechatIdsHash.length || !contextFn) {
210
+ return shortMessage
211
+ }
212
+ const contextRs = contextFn()
213
+ if (!contextRs || !contextRs.then) {
214
+ return shortMessage
215
+ }
216
+ return contextRs.then(rs => {
217
+ if (!rs.wechatAccount || !rs.session || !rs.session.unreadMsgCount) {
218
+ return shortMessage
231
219
  }
220
+ return atWechatIdsHash.includes(rs.wechatAccount.wechatIdHash)
221
+ ? `<span style="color: #e2544b; margin-right: 4px;">[有人@我]</span>${shortMessage}`
222
+ : shortMessage
223
+ })
224
+ }
225
+
226
+ function getUnreadAtMessageContents (session) {
227
+ const contents = (Array.isArray(session.lastAtMsgContent) ? session.lastAtMsgContent : [])
228
+ .map(item => typeof item === 'string' ? item : item && item.content)
229
+ .filter(Boolean)
230
+ if (session.lastMsgType === MESSAGE_TYPE.TEXT_WITH_AT && session.lastMsgContent) {
231
+ contents.push(session.lastMsgContent)
232
232
  }
233
- return formatShortMessage(session.lastMsgType, session.lastMsgContent)
234
- }
233
+ return contents.filter((content, index) => contents.indexOf(content) === index)
234
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aochuang/client-sdk",
3
- "version": "1.0.305",
3
+ "version": "1.0.307",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"