@aochuang/client-sdk 1.0.299 → 1.0.300

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aochuang/client-sdk",
3
- "version": "1.0.299",
3
+ "version": "1.0.300",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -394,6 +394,9 @@ export default class ClientChatSession {
394
394
  if (!data.wechatAccountId) {
395
395
  throw new Error('缺少必须参数wechatAccountId')
396
396
  }
397
+ if (!Array.isArray(data.lastAtMsgContent)) {
398
+ data.lastAtMsgContent = []
399
+ }
397
400
  if (this.onBeforeAddSession && this.onBeforeAddSession({
398
401
  data
399
402
  }) === false) {
@@ -46,6 +46,32 @@ function isAutoReadMessage (data) {
46
46
  return !!(data && data.id && data.id.indexOf('AUTO-READ-') === 0)
47
47
  }
48
48
 
49
+ function getAtMessageContent (data) {
50
+ if (!data || data.isSend || !data.content) {
51
+ return null
52
+ }
53
+ try {
54
+ const content = JSON.parse(data.content)
55
+ if (!content || (!Array.isArray(content.atIds) || !content.atIds.length) && (!content.text || content.text.indexOf('@所有人') < 0)) {
56
+ return null
57
+ }
58
+ return {
59
+ id: data.id,
60
+ content: data.content
61
+ }
62
+ } catch (e) {
63
+ return null
64
+ }
65
+ }
66
+
67
+ function appendLastAtMsgContent (lastAtMsgContent, atMessage) {
68
+ const messages = Array.isArray(lastAtMsgContent) ? lastAtMsgContent : []
69
+ if (!atMessage || messages.some(item => item && item.id === atMessage.id)) {
70
+ return messages
71
+ }
72
+ return messages.concat(atMessage)
73
+ }
74
+
49
75
  class ClientChat {
50
76
  data = Vue.observable({
51
77
  connectStatus: CONNECT_STATUS.Normal
@@ -252,6 +278,9 @@ class ClientChat {
252
278
  // 还要更新未读消息数量
253
279
  }
254
280
  options.onSessionReadChange = ({ session, oldUnreadMsgCount }) => {
281
+ instance.updateSession(session.conversationId, {
282
+ lastAtMsgContent: []
283
+ })
255
284
  const isMute = session.mute
256
285
  this.account.updateAccountUnreadMessageNum(session.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => {
257
286
  // 如果是免打扰的会话
@@ -514,6 +543,7 @@ class ClientChat {
514
543
  onAddMessageSuccess: ({ data }) => {
515
544
  const accountId = options.getLoginAccountIdMethod ? options.getLoginAccountIdMethod() : data.accountId
516
545
  let sessionId = createSessionId(accountId, data.wechatChatroomId)
546
+ const atMessage = getAtMessageContent(data)
517
547
  // 更新会话
518
548
  if (!sessionId) {
519
549
  return
@@ -550,6 +580,9 @@ class ClientChat {
550
580
  rs.data.lastMsgId = data.id
551
581
  rs.data.lastUpdateTime = data.updateDate
552
582
  }
583
+ if (rs && rs.data && atMessage && !(this.sessionManage.currentSession && this.sessionManage.currentSession.conversationId === sessionId)) {
584
+ rs.data.lastAtMsgContent = appendLastAtMsgContent(rs.data.lastAtMsgContent, atMessage)
585
+ }
553
586
  return rs
554
587
  }).then((rs) => {
555
588
  // 更新账号未读消息数量
@@ -596,6 +629,9 @@ class ClientChat {
596
629
  this.session.setSessionRead(sessionId)
597
630
  } else {
598
631
  nextSession.unreadMsgCount = session.unreadMsgCount + 1
632
+ if (atMessage) {
633
+ nextSession.lastAtMsgContent = appendLastAtMsgContent(session.lastAtMsgContent, atMessage)
634
+ }
599
635
  // 更新账号未读消息数量
600
636
  this.account.updateAccountUnreadMessageNum(session.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => {
601
637
  if (session.mute) {
@@ -75,8 +75,9 @@ export function createSessionData (message) {
75
75
  lastMsgType: message.msgType,
76
76
  lastUpdateTime: message.wechatTime,
77
77
  targetId,
78
+ lastAtMsgContent: [],
78
79
  unreadMsgCount: 0,
79
80
  wechatAccountId: message.wechatAccountId
80
81
  }
81
82
  return nextSession
82
- }
83
+ }