chatroomInfos.js
1.72 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import store from '../'
import config from '../../configs'
// 用于demo记录封面
export function initChatroomInfos ({state, commit}, obj) {
commit('initChatroomInfos', obj)
}
export function getChatroomInfo ({state, commit, dispatch}) {
const chatroom = state.currChatroom
if (chatroom) {
chatroom.getChatroom({
done: function getChatroomDone (error, info) {
if (error) {
alert(error.message)
return
}
info = info.chatroom || {creator: ''}
let creator = info.creator
chatroom.getChatroomMembersInfo({
accounts: [creator],
done: function getChatroomMembersInfoDone (error, user) {
if (error) {
alert(error.message)
return
}
commit('getChatroomInfo', Object.assign(info, {actor: user.members[0]}))
}
})
}
})
}
}
export function getChatroomMembers ({state, commit, dispatch}) {
// 先拉管理员
getChatroomMembersLocal (false, function (obj) {
commit('updateChatroomMembers', Object.assign(obj, {type: 'put'}))
// 再拉成员列表
getChatroomMembersLocal (true, function (obj) {
commit('updateChatroomMembers', Object.assign(obj, {type: 'put'}))
})
})
}
function getChatroomMembersLocal (isGuest, callback) {
const chatroom = store.state.currChatroom
if (chatroom) {
chatroom.getChatroomMembers({
guest: isGuest,
limit: 100,
done: function getChatroomMembersDone (error, obj) {
if (error) {
alert(error.message)
return
}
callback(obj)
}
})
}
}
export function clearChatroomMembers ({state, commit}) {
commit('updateChatroomMembers', {type: 'destroy'})
}