index.js 1.4 KB
Newer Older
DCloud_JSON's avatar
DCloud_JSON 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
import {default as createObservable,$watch} from '@/uni_modules/uni-im/sdk/utils/createObservable.js';
import data from './data';
const observable = createObservable(data);

$watch(() => observable.conversation.dataList, (conversationDataList,old) => {
  // console.log('会话数据变化',{conversationDataList,old})
  // 会话数据排序
  conversationDataList.sort(function(a, b) {
    if (a.pinned != b.pinned) {
      return a.pinned ? -1 : 1;
    }
    if (a.customIndex || b.customIndex) {
      let aIndex = a.customIndex || a.time
      let bIndex = b.customIndex || b.time
      return bIndex - aIndex
    }
    return b.time - a.time
  })
  
  // 异步存到storage// TODO 暂时不离线存储会话数据
  /*const {uid} = uniCloud.getCurrentUserInfo();
  if (uid) {
    uni.setStorage({
      key: 'uni-im-conversation-list' + '_uid:' + uid,
      data: conversationList.map(item => {
        let _item = {}
        for (let key in item) {
          if (!["msgManager"].includes(key)) {
            _item[key] = item[key]
          }
          // 清空防止 localStorage 的数据量过大。// 记录最后一个消息,用于会话列表显示last_msg_note,更多消息启动后再从缓存中读取
          if (key === "msgList" && item.msgList.length != 0) {
            _item[key] = [item.msgList[item.msgList.length - 1]]
          }
        }
        return _item
      })
    })
  }*/
},{
  deep: true,
  immediate: true
})

export default observable;