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

@@ -39,6 +39,11 @@
smsAuth smsAuth
} from "@/apis/interfaces/auth"; } from "@/apis/interfaces/auth";
import userAuth from "@/public/userAuth"; import userAuth from "@/public/userAuth";
import {
getImToken
} from '@/apis/interfaces/im.js'
import im from '@/utils/im/index.js'
export default { export default {
data() { data() {
return { return {
@@ -59,6 +64,11 @@
"setToken", "setToken",
res.token_type + " " + res.access_token res.token_type + " " + res.access_token
); );
// 在这里登录成功链接IM服务
getImToken().then(res => {
console.log('在这获取IM-TOKEN', res);
im.connect(res.token, res.userInfo, () => {})
})
this.$Router.back(); this.$Router.back();
}).catch((err) => { }).catch((err) => {
uni.showToast({ uni.showToast({

View File

@@ -105,9 +105,11 @@ class userAuth {
openid: authResult.authResult.openid openid: authResult.authResult.openid
}).then(res => { }).then(res => {
uni.closeAuthView() uni.closeAuthView()
store.commit('setToken', res.token_type + ' ' + res.access_token) store.commit('setToken', res.token_type + ' ' + res
.access_token)
// 在这里登录成功链接IM服务 // 在这里登录成功链接IM服务
getImToken().then(res => { getImToken().then(res => {
console.log('在这获取IM-TOKEN', res);
im.connect(res.token, res.userInfo) im.connect(res.token, res.userInfo)
}) })
resolve() resolve()

View File

@@ -34,7 +34,7 @@ export default {
} }
}, },
mutations: { mutations: {
updateContactInfo(state, contactInfo) { updateContactInfo(state, contactInfo) {
Vue.set(state.contacts, contactInfo.targetId, contactInfo) Vue.set(state.contacts, contactInfo.targetId, contactInfo)
}, },
setSenderInfo(state, contactInfo) { setSenderInfo(state, contactInfo) {

View File

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