IM登录完善,同步好友数据的时候,同步群组数据

This commit is contained in:
2022-02-16 11:19:53 +08:00
parent ad58731a78
commit f9dfd6b08d
4 changed files with 27 additions and 12 deletions

View File

@@ -6,7 +6,8 @@ import listeners from './listeners.js'
import {
getFriends,
getUserInfo,
getImToken
getImToken,
getMyGroups
} from '@/apis/interfaces/im.js'
const initIm = (KEY) => {
@@ -58,7 +59,7 @@ const connect = (token, userInfo, callback) => {
// 设置未读消息数量
setNotifyBadge()
// 首次运行获取好友列表
const FK = 'IFT_' + userInfo.targetId
const FK = 'ZHK_' + userInfo.targetId
uni.getStorage({
key: FK,
@@ -70,12 +71,14 @@ const connect = (token, userInfo, callback) => {
})
})
},
fail: () => {
// 程序是首次运行,初始化加载好友信息
getFriends().then(res => {
res.map(item => {
store.dispatch('initContact', item)
})
fail: () => {
// 程序是首次运行,初始化加载好友和群组信息
Promise.all([getFriends(), getMyGroups()]).then(result => {
result.map(contacts => {
contacts.map(item => {
store.dispatch('initContact', item)
})
})
uni.setStorageSync(FK, userInfo.targetId)
})
}
@@ -206,8 +209,8 @@ const newMessage = (msg) => {
status
}) => {
if (code === 0) {
if (status) {
uni.vibrateLong()
if (status) {
uni.vibrateLong()
triTone()
}
}