头像本地缓存
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import * as RongIMLib from '@rongcloud/imlib-uni'
|
||||
import store from '@/store/index.js'
|
||||
import {
|
||||
getFriends
|
||||
getFriends,
|
||||
getUserInfo
|
||||
} from '@/apis/interfaces/im.js'
|
||||
|
||||
const initIm = (KEY) => {
|
||||
@@ -18,12 +19,12 @@ const setNotifyBadge = (count) => {
|
||||
if (code === 0) {
|
||||
if (count > 0) {
|
||||
uni.setTabBarBadge({
|
||||
index: 2,
|
||||
index: 3,
|
||||
text: String(count > 99 ? '99+' : count)
|
||||
})
|
||||
} else {
|
||||
uni.removeTabBarBadge({
|
||||
index: 2
|
||||
index: 3
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -43,10 +44,18 @@ const connect = (token, userInfo) => {
|
||||
store.dispatch('setSenderInfo', userInfo)
|
||||
|
||||
setNotifyBadge()
|
||||
}
|
||||
|
||||
const disconnect = () => {
|
||||
RongIMLib.disconnect()
|
||||
|
||||
const model = uni.model.friendModel
|
||||
|
||||
model.find((err, results) => {
|
||||
results.map(item => {
|
||||
store.dispatch('updateFriends', item)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const disconnect = () => {
|
||||
RongIMLib.disconnect()
|
||||
}
|
||||
|
||||
const addListeners = () => {
|
||||
@@ -76,9 +85,19 @@ const newMessage = (msg) => {
|
||||
|
||||
setNotifyBadge()
|
||||
|
||||
if (!store.getters.hasUser(msg.targetId)) {
|
||||
syncUserInfo(msg.targetId)
|
||||
}
|
||||
|
||||
store.dispatch('newMessage', msg)
|
||||
}
|
||||
|
||||
function syncUserInfo(targetId) {
|
||||
getUserInfo(targetId).then(res => {
|
||||
store.dispatch('updateFriends', res)
|
||||
})
|
||||
}
|
||||
|
||||
// 播放状态
|
||||
let tipState = false
|
||||
|
||||
@@ -133,7 +152,10 @@ const sendMsg = (conversationType, targetId, content, callback) => {
|
||||
*/
|
||||
const syncFriends = () => {
|
||||
getFriends().then(res => {
|
||||
store.dispatch('updateFriends', res)
|
||||
res.map(item => {
|
||||
console.log('item', item);
|
||||
store.dispatch('updateFriends', item)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -142,5 +164,6 @@ export default {
|
||||
connect,
|
||||
sendMsg,
|
||||
setNotifyBadge,
|
||||
syncFriends
|
||||
syncFriends,
|
||||
syncUserInfo
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user