search.js
1.97 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import {formatUserInfo} from './userInfo'
export function resetSearchResult ({state, commit}) {
commit('updateSearchlist', {
type: 'user',
list: []
})
commit('updateSearchlist', {
type: 'team',
list: []
})
}
export function searchUsers ({state, commit}, obj) {
let {accounts, done} = obj
const nim = state.nim
if (!Array.isArray(accounts)) {
accounts = [accounts]
}
nim.getUsers({
accounts,
done: function searchUsersDone (error, users) {
if (error) {
alert(error)
return
}
commit('updateSearchlist', {
type: 'user',
list: users
})
let updateUsers = users.filter(item => {
let account = item.account
if (item.account === state.userUID) {
return false
}
let userInfo = state.userInfos[account] || {}
if (userInfo.isFriend) {
return false
}
return true
})
updateUsers = updateUsers.map(item => {
return formatUserInfo(item)
})
commit('updateUserInfo', updateUsers)
if (done instanceof Function) {
done(users)
}
}
})
}
export function searchTeam ({ state, commit }, obj) {
let { teamId, done } = obj
const nim = state.nim
nim.getTeam({
teamId: teamId,
done: function searchTeamDone (error, teams) {
if (error) {
if (error.code === 803) {
// 群不存在或未发生变化
teams = []
} else {
alert(error)
return
}
}
if (!Array.isArray(teams)) {
teams = [teams]
}
teams.forEach(team => {
if (team.avatar && team.avatar.indexOf('nim.nosdn.127') > 0 && team.avatar.indexOf('?imageView') === -1) {
team.avatar = team.avatar + '?imageView&thumbnail=300y300'
}
})
commit('updateSearchlist', {
type: 'team',
list: teams
})
if (done instanceof Function) {
done(teams)
}
}
})
}