notification.js
5.7 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/**
* 群通知处理
*/
YX.fn.notification = function() {
}
YX.fn.messageHandler = function(msg,callback) {
if (msg.type === 'robot') {
this.doMsg(msg)
return
}
var type = msg.attach.type,
team = msg.attach.team
switch (type) {
case 'addTeamMembers': // 添加成员
this.addTeamMembersNotification(msg,callback)
break
case 'removeTeamMembers': // 移除成员
this.removeMembersNotification(msg,callback)
break
case 'addTeamManagers':
case 'removeTeamManagers':
if (this.crtSessionType === 'team' && this.crtSession) {
this.getTeamMembers(team.teamId, function () {
this.cache.isCurSessionTeamManager = this.cache.isTeamManager(userUID, this.crtSessionAccount)
this.buildSessions()
this.doChatUI(this.crtSession)
}.bind(this))
this.cache.addMsgs(msg)
}
break
case 'leaveTeam': // 离开群
this.leaveTeamNotification(msg,callback)
break
case 'updateTeam': // 更新群
this.updateTeamNotification(msg,callback)
break
case 'acceptTeamInvite': // 接受入群邀请
this.acceptTeamInviteNotification(msg,callback)
break
case 'passTeamApply': // 群主/管理员 通过加群邀请
this.passTeamApplyNotification(msg,callback)
break
case 'dismissTeam':
this.dismissTeamNotification(msg,callback)
break
case 'updateTeamMute':
this.updateTeamMuteNotification(msg,callback)
break
case 201: // 白板互动结束后的回单
break
case 202: // 白板互动未接受时,发起方结束,被邀请方收到的回单
break
case 'rejectWhiteboard': // 拒绝白板邀请的回单
break
case 'whiteboardRejected': // 白板邀请被拒绝的回单
break
case 'cancelWhiteBoardBeforeAccept': // // 白板互动未接受时,发起方结束,发起方收到的回单
break
default: // 其他
if (window.yunXin.WB.session.length !== 0 && (type === 'rejectNetcall' || type === 'netcallRejected')) return
console.log("type-->" + type)
this.cache.addMsgs(msg)
callback()
break
}
}
/**
* 添加成员
*/
YX.fn.addTeamMembersNotification = function(msg,callback) {
var team = msg.attach.team
this.cache.addTeam(team)
this.cache.addTeamMembers(team.teamId, msg.attach.members)
var accounts = msg.attach.accounts,
array=[],
that=this
for(var i=0; i<accounts.length; i++){
if(!this.cache.getUserById(accounts[i])){
array.push(accounts[i])
}
}
if(array.length>0){
this.mysdk.getUsers(array,function(err,data){
for (var i = data.length - 1; i >= 0; i--) {
that.cache.updatePersonlist(data[i])
}
//蛋疼的异步处理,必须确保用户消息缓存在本地,再进行UI展示
that.cache.addMsgs(msg)
//再次重绘
that.buildSessions()
callback()
})
}else{
this.cache.addMsgs(msg)
callback()
}
}
/**
* 群主/管理员 移除成员
* @param team: 群(普通/高级)对象
* @param msg: 消息对象
*/
YX.fn.removeMembersNotification = function(msg,callback) {
var accounts = msg.attach.accounts,
array=[],
kickme = false,
that = this
for(var i=0; i<accounts.length; i++){
if(!this.cache.getUserById(accounts[i])){
array.push(accounts[i])
}
if (accounts[i]===userUID) {
kickme = true
}
}
this.cache.removeTeamMembers(msg.attach.team.teamId, accounts)
if(array.length>0){
this.mysdk.getUsers(array,function(err,data){
for (var i = data.length - 1; i >= 0; i--) {
that.cache.updatePersonlist(data[i])
}
//蛋疼的异步处理,必须确保用户消息缓存在本地,再进行UI展示
that.cache.addMsgs(msg)
if(kickme){
that.cache.removeTeamById(msg.to)
}
//再次重绘
that.buildSessions()
callback()
})
}else{
if(kickme){
this.cache.removeTeamById(msg.to)
}
this.cache.addMsgs(msg)
callback()
}
},
/**
* 退群
*/
YX.fn.leaveTeamNotification = function(msg,callback) {
if(msg.from===userUID){
// 从漫游消息中删除
var teamId = msg.to
this.cache.removeTeamById(teamId)
this.buildTeams()
if($('#j-chatEditor').data('to') === msg.to) {
$('#j-chatEditor').data({to:""})
$('#j-rightPanel').addClass('hide')
}
}
this.cache.addMsgs(msg)
callback()
}
/**
* 更新群名字
*/
YX.fn.updateTeamNotification = function(msg,callback) {
var team = msg.attach.team
var teamName = team.name
if(teamName){
if($('#j-chatEditor').data('to') === msg.to){
$('#j-nickName').text(teamName)
}
}
this.cache.updateTeam(msg.to,team)
this.buildTeams()
this.cache.addMsgs(msg)
callback()
}
/**
* 用户接受入群邀请
*/
YX.fn.acceptTeamInviteNotification = function(msg,callback) {
if(msg.from===userUID){
this.cache.addTeam(msg.attach.team)
this.buildTeams()
this.buildSessions()
}
this.cache.addMsgs(msg)
callback()
}
/**
* 群主/管理员 同意入群邀请
*/
YX.fn.passTeamApplyNotification = function(msg,callback) {
if(msg.from===msg.attach.account||msg.attach.account===userUID){
this.cache.addTeam(msg.attach.team)
this.buildTeams()
this.buildSessions()
}
this.cache.addMsgs(msg)
callback()
}
/**
* 解散群
*/
YX.fn.dismissTeamNotification = function(msg,callback) {
this.cache.addMsgs(msg)
var teamId = msg.target
this.cache.removeTeamById(teamId)
this.buildTeams()
callback()
}
/**
* 禁言群成员
*/
YX.fn.updateTeamMuteNotification = function(msg,callback) {
this.cache.addMsgs(msg)
this.cache.updateTeamMemberMute(msg.target,msg.attach.account,msg.attach.mute)
callback()
}