| ... |
... |
@@ -35,10 +35,8 @@ |
|
35
|
35
|
from gajim.common.const import MUCJoinedState
|
|
36
|
36
|
from gajim.common.helpers import AdditionalDataDict
|
|
37
|
37
|
from gajim.common.helpers import get_default_muc_config
|
|
38
|
|
-from gajim.common.helpers import to_user_string
|
|
39
|
38
|
from gajim.common.helpers import event_filter
|
|
40
|
39
|
from gajim.common.helpers import get_group_chat_nick
|
|
41
|
|
-from gajim.common.helpers import Observable
|
|
42
|
40
|
from gajim.common.structs import MUCData
|
|
43
|
41
|
from gajim.common.structs import MUCPresenceData
|
|
44
|
42
|
from gajim.common.nec import NetworkEvent
|
| ... |
... |
@@ -114,11 +112,12 @@ def __init__(self, con): |
|
114
|
112
|
# ('signed-in', ged.GUI1, self._on_signed_in),
|
|
115
|
113
|
])
|
|
116
|
114
|
|
|
117
|
|
- self._manager = MUCManager(self._account, self._log)
|
|
118
|
115
|
self._rejoin_muc = set()
|
|
119
|
116
|
self._join_timeouts = {}
|
|
120
|
117
|
self._rejoin_timeouts = {}
|
|
121
|
118
|
self._muc_service_jid = None
|
|
|
119
|
+ self._joined_users = defaultdict(dict)
|
|
|
120
|
+ self._mucs = {}
|
|
122
|
121
|
|
|
123
|
122
|
@property
|
|
124
|
123
|
def supported(self):
|
| ... |
... |
@@ -128,9 +127,6 @@ def supported(self): |
|
128
|
127
|
def service_jid(self):
|
|
129
|
128
|
return self._muc_service_jid
|
|
130
|
129
|
|
|
131
|
|
- def get_manager(self):
|
|
132
|
|
- return self._manager
|
|
133
|
|
-
|
|
134
|
130
|
def pass_disco(self, info):
|
|
135
|
131
|
for identity in info.identities:
|
|
136
|
132
|
if identity.category != 'conference':
|
| ... |
... |
@@ -142,6 +138,38 @@ def pass_disco(self, info): |
|
142
|
138
|
self._muc_service_jid = info.jid
|
|
143
|
139
|
raise nbxmpp.NodeProcessed
|
|
144
|
140
|
|
|
|
141
|
+ def get_muc_data(self, room_jid):
|
|
|
142
|
+ return self._mucs.get(room_jid)
|
|
|
143
|
+
|
|
|
144
|
+ def _get_mucs_with_state(self, states):
|
|
|
145
|
+ return [muc for muc in self._mucs.values() if muc.state in states]
|
|
|
146
|
+
|
|
|
147
|
+ def _set_muc_state(self, room_jid, state):
|
|
|
148
|
+ try:
|
|
|
149
|
+ muc = self._mucs[room_jid]
|
|
|
150
|
+ except KeyError:
|
|
|
151
|
+ raise ValueError('set_muc_state() called '
|
|
|
152
|
+ 'on unknown muc: %s' % room_jid)
|
|
|
153
|
+
|
|
|
154
|
+ if muc.state == state:
|
|
|
155
|
+ return
|
|
|
156
|
+
|
|
|
157
|
+ self._log.info('Set MUC state: %s %s', room_jid, state)
|
|
|
158
|
+
|
|
|
159
|
+ muc.state = state
|
|
|
160
|
+ contact = self._get_contact(room_jid, groupchat=True)
|
|
|
161
|
+ contact.notify('state-changed')
|
|
|
162
|
+
|
|
|
163
|
+ def reset_state(self):
|
|
|
164
|
+ for muc in self._mucs.values():
|
|
|
165
|
+ self._joined_users.pop(muc.jid, None)
|
|
|
166
|
+ self._set_muc_state(muc.jid, MUCJoinedState.NOT_JOINED)
|
|
|
167
|
+ room = self._get_contact(muc.jid)
|
|
|
168
|
+ room.set_not_joined()
|
|
|
169
|
+ room.notify('room-left')
|
|
|
170
|
+
|
|
|
171
|
+ self._joined_users.clear()
|
|
|
172
|
+
|
|
145
|
173
|
def _create_muc_data(self, room_jid, nick, password, config):
|
|
146
|
174
|
if not nick:
|
|
147
|
175
|
nick = get_group_chat_nick(self._account, room_jid)
|
| ... |
... |
@@ -160,10 +188,11 @@ def join(self, jid, nick=None, password=None, config=None): |
|
160
|
188
|
|
|
161
|
189
|
self._con.get_module('Contacts').add_contact(jid, groupchat=True)
|
|
162
|
190
|
|
|
163
|
|
- muc_data = self._manager.get(jid)
|
|
|
191
|
+ muc_data = self._mucs.get(jid)
|
|
164
|
192
|
if muc_data is None:
|
|
165
|
193
|
muc_data = self._create_muc_data(jid, nick, password, config)
|
|
166
|
|
- self._manager.add(muc_data)
|
|
|
194
|
+ self._mucs[jid] = muc_data
|
|
|
195
|
+ self._push_muc_added_event(jid)
|
|
167
|
196
|
|
|
168
|
197
|
if not muc_data.state.is_not_joined:
|
|
169
|
198
|
self._log.warning('Can’t join MUC %s, state: %s',
|
| ... |
... |
@@ -183,8 +212,15 @@ def create(self, muc_data): |
|
183
|
212
|
if not app.account_is_available(self._account):
|
|
184
|
213
|
return
|
|
185
|
214
|
|
|
186
|
|
- self._manager.add(muc_data)
|
|
|
215
|
+ self._mucs[muc_data.jid] = muc_data
|
|
187
|
216
|
self._create(muc_data)
|
|
|
217
|
+ self._push_muc_added_event(muc_data.jid)
|
|
|
218
|
+
|
|
|
219
|
+ def _push_muc_added_event(self, jid):
|
|
|
220
|
+ app.nec.push_incoming_event(
|
|
|
221
|
+ NetworkEvent('muc-added',
|
|
|
222
|
+ account=self._account,
|
|
|
223
|
+ jid=jid))
|
|
188
|
224
|
|
|
189
|
225
|
def _on_disco_result(self, task):
|
|
190
|
226
|
try:
|
| ... |
... |
@@ -196,7 +232,7 @@ def _on_disco_result(self, task): |
|
196
|
232
|
room.notify('room-join-failed', error)
|
|
197
|
233
|
return
|
|
198
|
234
|
|
|
199
|
|
- muc_data = self._manager.get(result.info.jid)
|
|
|
235
|
+ muc_data = self._mucs.get(result.info.jid)
|
|
200
|
236
|
if muc_data is None:
|
|
201
|
237
|
self._log.warning('MUC Data not found, join aborted')
|
|
202
|
238
|
return
|
| ... |
... |
@@ -215,12 +251,12 @@ def _join(self, muc_data): |
|
215
|
251
|
muc_x.setTagData('password', muc_data.password)
|
|
216
|
252
|
|
|
217
|
253
|
self._log.info('Join MUC: %s', muc_data.jid)
|
|
218
|
|
- self._manager.set_state(muc_data.jid, MUCJoinedState.JOINING)
|
|
|
254
|
+ self._set_muc_state(muc_data.jid, MUCJoinedState.JOINING)
|
|
219
|
255
|
self._con.send_stanza(presence)
|
|
220
|
256
|
|
|
221
|
257
|
def _rejoin(self, room_jid):
|
|
222
|
|
- muc_data = self._manager.get(room_jid)
|
|
223
|
|
- if muc_data.state == MUCJoinedState.NOT_JOINED:
|
|
|
258
|
+ muc_data = self._mucs[room_jid]
|
|
|
259
|
+ if muc_data.state.is_not_joined:
|
|
224
|
260
|
self._log.info('Rejoin %s', room_jid)
|
|
225
|
261
|
self._join(muc_data)
|
|
226
|
262
|
return True
|
| ... |
... |
@@ -234,7 +270,7 @@ def _create(self, muc_data): |
|
234
|
270
|
presence.setTag(Namespace.MUC + ' x')
|
|
235
|
271
|
|
|
236
|
272
|
self._log.info('Create MUC: %s', muc_data.jid)
|
|
237
|
|
- self._manager.set_state(muc_data.jid, MUCJoinedState.CREATING)
|
|
|
273
|
+ self._set_muc_state(muc_data.jid, MUCJoinedState.CREATING)
|
|
238
|
274
|
self._con.send_stanza(presence)
|
|
239
|
275
|
|
|
240
|
276
|
def leave(self, room_jid, reason=None):
|
| ... |
... |
@@ -242,11 +278,11 @@ def leave(self, room_jid, reason=None): |
|
242
|
278
|
|
|
243
|
279
|
self._con.get_module('Bookmarks').modify(room_jid, autojoin=False)
|
|
244
|
280
|
|
|
245
|
|
- muc_data = self._manager.get(room_jid)
|
|
|
281
|
+ muc_data = self._mucs.get(room_jid)
|
|
246
|
282
|
if muc_data is None:
|
|
247
|
283
|
return
|
|
248
|
284
|
|
|
249
|
|
- if muc_data.state == MUCJoinedState.NOT_JOINED:
|
|
|
285
|
+ if muc_data.state.is_not_joined:
|
|
250
|
286
|
return
|
|
251
|
287
|
|
|
252
|
288
|
self._remove_join_timeout(room_jid)
|
| ... |
... |
@@ -258,7 +294,7 @@ def leave(self, room_jid, reason=None): |
|
258
|
294
|
status=reason,
|
|
259
|
295
|
caps=False)
|
|
260
|
296
|
|
|
261
|
|
- self._manager.set_state(room_jid, MUCJoinedState.NOT_JOINED)
|
|
|
297
|
+ self._set_muc_state(room_jid, MUCJoinedState.NOT_JOINED)
|
|
262
|
298
|
room = self._get_contact(room_jid)
|
|
263
|
299
|
room.set_not_joined()
|
|
264
|
300
|
room.notify('room-left')
|
| ... |
... |
@@ -279,7 +315,7 @@ def _on_room_config(self, task): |
|
279
|
315
|
|
|
280
|
316
|
self._log.info('Configure room: %s', result.jid)
|
|
281
|
317
|
|
|
282
|
|
- muc_data = self._manager.get(result.jid)
|
|
|
318
|
+ muc_data = self._mucs[result.jid]
|
|
283
|
319
|
self._apply_config(result.form, muc_data.config)
|
|
284
|
320
|
self.set_config(result.jid,
|
|
285
|
321
|
result.form,
|
| ... |
... |
@@ -333,7 +369,7 @@ def _on_disco_result_after_config(self, task): |
|
333
|
369
|
return
|
|
334
|
370
|
|
|
335
|
371
|
jid = result.info.jid
|
|
336
|
|
- muc_data = self._manager.get(jid)
|
|
|
372
|
+ muc_data = self._mucs[jid]
|
|
337
|
373
|
self._room_join_complete(muc_data)
|
|
338
|
374
|
|
|
339
|
375
|
self._log.info('Configuration finished: %s', jid)
|
| ... |
... |
@@ -342,8 +378,8 @@ def _on_disco_result_after_config(self, task): |
|
342
|
378
|
room.notify('room-config-finished')
|
|
343
|
379
|
|
|
344
|
380
|
def update_presence(self):
|
|
345
|
|
- mucs = self._manager.get_mucs_with_state([MUCJoinedState.JOINED,
|
|
346
|
|
- MUCJoinedState.JOINING])
|
|
|
381
|
+ mucs = self._get_mucs_with_state([MUCJoinedState.JOINED,
|
|
|
382
|
+ MUCJoinedState.JOINING])
|
|
347
|
383
|
|
|
348
|
384
|
status, message, idle = self._con.get_presence_state()
|
|
349
|
385
|
for muc_data in mucs:
|
| ... |
... |
@@ -362,7 +398,7 @@ def change_nick(self, room_jid, new_nick): |
|
362
|
398
|
|
|
363
|
399
|
def _on_error_presence(self, _con, stanza, properties):
|
|
364
|
400
|
room_jid = properties.jid.bare
|
|
365
|
|
- muc_data = self._manager.get(room_jid)
|
|
|
401
|
+ muc_data = self._mucs.get(room_jid)
|
|
366
|
402
|
if muc_data is None:
|
|
367
|
403
|
return
|
|
368
|
404
|
|
| ... |
... |
@@ -383,25 +419,25 @@ def _on_error_presence(self, _con, stanza, properties): |
|
383
|
419
|
|
|
384
|
420
|
elif properties.error.condition == 'not-authorized':
|
|
385
|
421
|
self._remove_rejoin_timeout(room_jid)
|
|
386
|
|
- self._manager.set_state(room_jid, MUCJoinedState.NOT_JOINED)
|
|
|
422
|
+ self._set_muc_state(room_jid, MUCJoinedState.NOT_JOINED)
|
|
387
|
423
|
room.notify('room-password-required', properties)
|
|
388
|
424
|
|
|
389
|
425
|
else:
|
|
390
|
|
- self._manager.set_state(room_jid, MUCJoinedState.NOT_JOINED)
|
|
|
426
|
+ self._set_muc_state(room_jid, MUCJoinedState.NOT_JOINED)
|
|
391
|
427
|
if room_jid not in self._rejoin_muc:
|
|
392
|
428
|
room.notify('room-join-failed', properties.error)
|
|
393
|
429
|
|
|
394
|
430
|
elif muc_data.state == MUCJoinedState.CREATING:
|
|
395
|
|
- self._manager.set_state(room_jid, MUCJoinedState.NOT_JOINED)
|
|
|
431
|
+ self._set_muc_state(room_jid, MUCJoinedState.NOT_JOINED)
|
|
396
|
432
|
room.notify('room-creation-failed', properties)
|
|
397
|
433
|
|
|
398
|
434
|
elif muc_data.state == MUCJoinedState.CAPTCHA_REQUEST:
|
|
399
|
|
- self._manager.set_state(room_jid, MUCJoinedState.CAPTCHA_FAILED)
|
|
400
|
|
- self._manager.set_state(room_jid, MUCJoinedState.NOT_JOINED)
|
|
|
435
|
+ self._set_muc_state(room_jid, MUCJoinedState.CAPTCHA_FAILED)
|
|
|
436
|
+ self._set_muc_state(room_jid, MUCJoinedState.NOT_JOINED)
|
|
401
|
437
|
room.notify('room-captcha-error', properties.error)
|
|
402
|
438
|
|
|
403
|
439
|
elif muc_data.state == MUCJoinedState.CAPTCHA_FAILED:
|
|
404
|
|
- self._manager.set_state(room_jid, MUCJoinedState.NOT_JOINED)
|
|
|
440
|
+ self._set_muc_state(room_jid, MUCJoinedState.NOT_JOINED)
|
|
405
|
441
|
|
|
406
|
442
|
else:
|
|
407
|
443
|
room.notify('room-presence-error', properties)
|
| ... |
... |
@@ -411,19 +447,19 @@ def _on_muc_user_presence(self, _con, stanza, properties): |
|
411
|
447
|
return
|
|
412
|
448
|
|
|
413
|
449
|
room_jid = str(properties.muc_jid)
|
|
414
|
|
- if room_jid not in self._manager:
|
|
|
450
|
+ if room_jid not in self._mucs:
|
|
415
|
451
|
self._log.warning('Presence from unknown MUC')
|
|
416
|
452
|
self._log.warning(stanza)
|
|
417
|
453
|
return
|
|
418
|
454
|
|
|
419
|
|
- muc_data = self._manager.get(room_jid)
|
|
|
455
|
+ muc_data = self._mucs[room_jid]
|
|
420
|
456
|
occupant = self._get_contact(properties.jid, groupchat=True)
|
|
421
|
457
|
room = self._get_contact(properties.jid.bare)
|
|
422
|
458
|
|
|
423
|
459
|
if properties.is_muc_destroyed:
|
|
424
|
460
|
self._log.info('MUC destroyed: %s', room_jid)
|
|
425
|
461
|
self._remove_join_timeout(room_jid)
|
|
426
|
|
- self._manager.set_state(room_jid, MUCJoinedState.NOT_JOINED)
|
|
|
462
|
+ self._set_muc_state(room_jid, MUCJoinedState.NOT_JOINED)
|
|
427
|
463
|
room.set_not_joined()
|
|
428
|
464
|
room.notify('destroyed', properties)
|
|
429
|
465
|
return
|
| ... |
... |
@@ -444,16 +480,20 @@ def _on_muc_user_presence(self, _con, stanza, properties): |
|
444
|
480
|
new_occupant = room.add_resource(properties.muc_user.nick)
|
|
445
|
481
|
new_occupant.set_presence(occupant.presence)
|
|
446
|
482
|
|
|
447
|
|
- presence = self._manager.process_presence(properties)
|
|
|
483
|
+ presence = self._process_user_presence(properties)
|
|
448
|
484
|
occupant.update_presence(presence, properties)
|
|
449
|
485
|
|
|
|
486
|
+ # new_nick = properties.muc_user.nick
|
|
|
487
|
+ # nick = properties.muc_nickname
|
|
|
488
|
+ # presence_dict = self._joined_users[properties.jid.bare]
|
|
|
489
|
+ # presence_dict[new_nick] = presence_dict.pop(nick)
|
|
450
|
490
|
# self._manager.change_nickname
|
|
451
|
491
|
# TODO remove presence from manager
|
|
452
|
492
|
|
|
453
|
493
|
room.notify('user-nickname-changed', occupant, properties)
|
|
454
|
494
|
return
|
|
455
|
495
|
|
|
456
|
|
- is_joined = self._manager.is_joined(properties.jid)
|
|
|
496
|
+ is_joined = self._is_user_joined(properties.jid)
|
|
457
|
497
|
if not is_joined and properties.type.is_available:
|
|
458
|
498
|
if properties.is_muc_self_presence:
|
|
459
|
499
|
self._log.info('Self presence: %s', properties.jid)
|
| ... |
... |
@@ -470,12 +510,12 @@ def _on_muc_user_presence(self, _con, stanza, properties): |
|
470
|
510
|
|
|
471
|
511
|
self._start_join_timeout(room_jid)
|
|
472
|
512
|
|
|
473
|
|
- presence = self._manager.process_presence(properties)
|
|
|
513
|
+ presence = self._process_user_presence(properties)
|
|
474
|
514
|
occupant.update_presence(presence, properties)
|
|
475
|
515
|
return
|
|
476
|
516
|
|
|
477
|
517
|
if properties.is_muc_self_presence and properties.is_kicked:
|
|
478
|
|
- self._manager.set_state(room_jid, MUCJoinedState.NOT_JOINED)
|
|
|
518
|
+ self._set_muc_state(room_jid, MUCJoinedState.NOT_JOINED)
|
|
479
|
519
|
room.set_not_joined()
|
|
480
|
520
|
room.notify('kicked', properties)
|
|
481
|
521
|
status_codes = properties.muc_status_codes or []
|
| ... |
... |
@@ -488,9 +528,28 @@ def _on_muc_user_presence(self, _con, stanza, properties): |
|
488
|
528
|
# unavailable presence, because we left the MUC
|
|
489
|
529
|
return
|
|
490
|
530
|
|
|
491
|
|
- presence = self._manager.process_presence(properties)
|
|
|
531
|
+ presence = self._process_user_presence(properties)
|
|
492
|
532
|
occupant.update_presence(presence, properties)
|
|
493
|
533
|
|
|
|
534
|
+ def _process_user_presence(self, properties):
|
|
|
535
|
+ jid = properties.jid
|
|
|
536
|
+ muc_presence = MUCPresenceData.from_presence(properties)
|
|
|
537
|
+ if not muc_presence.available:
|
|
|
538
|
+ self._joined_users[jid.bare].pop(jid.resource)
|
|
|
539
|
+ else:
|
|
|
540
|
+ self._joined_users[jid.bare][jid.resource] = muc_presence
|
|
|
541
|
+ return muc_presence
|
|
|
542
|
+
|
|
|
543
|
+ def _is_user_joined(self, jid):
|
|
|
544
|
+ try:
|
|
|
545
|
+ self._joined_users[jid.bare][jid.resource]
|
|
|
546
|
+ except KeyError:
|
|
|
547
|
+ return False
|
|
|
548
|
+ return True
|
|
|
549
|
+
|
|
|
550
|
+ def get_joined_users(self, jid):
|
|
|
551
|
+ return list(self._joined_users[jid].keys())
|
|
|
552
|
+
|
|
494
|
553
|
def _start_rejoin_timeout(self, room_jid):
|
|
495
|
554
|
self._remove_rejoin_timeout(room_jid)
|
|
496
|
555
|
self._rejoin_muc.add(room_jid)
|
| ... |
... |
@@ -568,7 +627,7 @@ def _on_subject_change(self, _con, _stanza, properties): |
|
568
|
627
|
|
|
569
|
628
|
room_jid = properties.jid.bare
|
|
570
|
629
|
|
|
571
|
|
- muc_data = self._manager.get(room_jid)
|
|
|
630
|
+ muc_data = self._mucs.get(room_jid)
|
|
572
|
631
|
if muc_data is None:
|
|
573
|
632
|
self._log.warning('No MUCData found for %s', room_jid)
|
|
574
|
633
|
return
|
| ... |
... |
@@ -593,7 +652,7 @@ def _fake_subject_change(self, room_jid): |
|
593
|
652
|
|
|
594
|
653
|
def _room_join_complete(self, muc_data):
|
|
595
|
654
|
self._remove_join_timeout(muc_data.jid)
|
|
596
|
|
- self._manager.set_state(muc_data.jid, MUCJoinedState.JOINED)
|
|
|
655
|
+ self._set_muc_state(muc_data.jid, MUCJoinedState.JOINED)
|
|
597
|
656
|
self._remove_rejoin_timeout(muc_data.jid)
|
|
598
|
657
|
|
|
599
|
658
|
# We successfully joined a MUC, set add bookmark with autojoin
|
| ... |
... |
@@ -626,7 +685,7 @@ def _on_captcha_challenge(self, _con, _stanza, properties): |
|
626
|
685
|
self._log.warning('Ignore captcha challenge received from MAM')
|
|
627
|
686
|
raise nbxmpp.NodeProcessed
|
|
628
|
687
|
|
|
629
|
|
- muc_data = self._manager.get(properties.jid)
|
|
|
688
|
+ muc_data = self._mucs.get(properties.jid)
|
|
630
|
689
|
if muc_data is None:
|
|
631
|
690
|
return
|
|
632
|
691
|
|
| ... |
... |
@@ -639,7 +698,7 @@ def _on_captcha_challenge(self, _con, _stanza, properties): |
|
639
|
698
|
store_bob_data(properties.captcha.bob_data)
|
|
640
|
699
|
muc_data.captcha_id = properties.id
|
|
641
|
700
|
|
|
642
|
|
- self._manager.set_state(properties.jid, MUCJoinedState.CAPTCHA_REQUEST)
|
|
|
701
|
+ self._set_muc_state(properties.jid, MUCJoinedState.CAPTCHA_REQUEST)
|
|
643
|
702
|
self._remove_rejoin_timeout(properties.jid)
|
|
644
|
703
|
|
|
645
|
704
|
room = self._get_contact(properties.jid.bare)
|
| ... |
... |
@@ -648,7 +707,7 @@ def _on_captcha_challenge(self, _con, _stanza, properties): |
|
648
|
707
|
raise nbxmpp.NodeProcessed
|
|
649
|
708
|
|
|
650
|
709
|
def cancel_captcha(self, room_jid):
|
|
651
|
|
- muc_data = self._manager.get(room_jid)
|
|
|
710
|
+ muc_data = self._mucs.get(room_jid)
|
|
652
|
711
|
if muc_data is None:
|
|
653
|
712
|
return
|
|
654
|
713
|
|
| ... |
... |
@@ -656,11 +715,11 @@ def cancel_captcha(self, room_jid): |
|
656
|
715
|
self._log.warning('No captcha message id available')
|
|
657
|
716
|
return
|
|
658
|
717
|
self._nbxmpp('MUC').cancel_captcha(room_jid, muc_data.captcha_id)
|
|
659
|
|
- self._manager.set_state(room_jid, MUCJoinedState.CAPTCHA_FAILED)
|
|
660
|
|
- self._manager.set_state(room_jid, MUCJoinedState.NOT_JOINED)
|
|
|
718
|
+ self._set_muc_state(room_jid, MUCJoinedState.CAPTCHA_FAILED)
|
|
|
719
|
+ self._set_muc_state(room_jid, MUCJoinedState.NOT_JOINED)
|
|
661
|
720
|
|
|
662
|
721
|
def send_captcha(self, room_jid, form_node):
|
|
663
|
|
- self._manager.set_state(room_jid, MUCJoinedState.JOINING)
|
|
|
722
|
+ self._set_muc_state(room_jid, MUCJoinedState.JOINING)
|
|
664
|
723
|
self._nbxmpp('MUC').send_captcha(room_jid,
|
|
665
|
724
|
form_node,
|
|
666
|
725
|
callback=self._on_captcha_result)
|
| ... |
... |
@@ -669,10 +728,10 @@ def _on_captcha_result(self, task): |
|
669
|
728
|
try:
|
|
670
|
729
|
task.finish()
|
|
671
|
730
|
except StanzaError as error:
|
|
672
|
|
- muc_data = self._manager.get(error.jid)
|
|
|
731
|
+ muc_data = self._mucs.get(error.jid)
|
|
673
|
732
|
if muc_data is None:
|
|
674
|
733
|
return
|
|
675
|
|
- self._manager.set_state(error.jid, MUCJoinedState.CAPTCHA_FAILED)
|
|
|
734
|
+ self._set_muc_state(error.jid, MUCJoinedState.CAPTCHA_FAILED)
|
|
676
|
735
|
room = self._get_contact(error.jid)
|
|
677
|
736
|
room.notify('room-captcha-error', error)
|
|
678
|
737
|
|
| ... |
... |
@@ -744,7 +803,7 @@ def invite(self, room, jid, reason=None, continue_=False): |
|
744
|
803
|
if contact and contact.supports(Namespace.CONFERENCE):
|
|
745
|
804
|
type_ = InviteType.DIRECT
|
|
746
|
805
|
|
|
747
|
|
- password = self._manager.get(room).password
|
|
|
806
|
+ password = self._mucs[room].password
|
|
748
|
807
|
self._log.info('Invite %s to %s', jid, room)
|
|
749
|
808
|
return self._nbxmpp('MUC').invite(room, jid, reason, password,
|
|
750
|
809
|
continue_, type_)
|
| ... |
... |
@@ -758,81 +817,5 @@ def _on_account_disconnected(self, _event): |
|
758
|
817
|
self._remove_join_timeout(room_jid)
|
|
759
|
818
|
|
|
760
|
819
|
|
|
761
|
|
-class MUCManager(Observable):
|
|
762
|
|
- def __init__(self, account, logger):
|
|
763
|
|
- Observable.__init__(self)
|
|
764
|
|
- self._account = account
|
|
765
|
|
- self._log = logger
|
|
766
|
|
- self._mucs = {}
|
|
767
|
|
- self._joined_users = defaultdict(dict)
|
|
768
|
|
-
|
|
769
|
|
- def process_presence(self, properties):
|
|
770
|
|
- jid = properties.jid
|
|
771
|
|
- muc_presence = MUCPresenceData.from_presence(properties)
|
|
772
|
|
- if not muc_presence.available:
|
|
773
|
|
- self._joined_users[jid.bare].pop(jid.resource)
|
|
774
|
|
- else:
|
|
775
|
|
- self._joined_users[jid.bare][jid.resource] = muc_presence
|
|
776
|
|
- return muc_presence
|
|
777
|
|
-
|
|
778
|
|
- def change_nickname(self, properties):
|
|
779
|
|
- new_nick = properties.muc_user.nick
|
|
780
|
|
- nick = properties.muc_nickname
|
|
781
|
|
- presence_dict = self._joined_users[properties.jid.bare]
|
|
782
|
|
- presence_dict[new_nick] = presence_dict.pop(nick)
|
|
783
|
|
-
|
|
784
|
|
- def is_joined(self, jid):
|
|
785
|
|
- try:
|
|
786
|
|
- self._joined_users[jid.bare][jid.resource]
|
|
787
|
|
- except KeyError:
|
|
788
|
|
- return False
|
|
789
|
|
- return True
|
|
790
|
|
-
|
|
791
|
|
- def get_joined_users(self, jid):
|
|
792
|
|
- return list(self._joined_users[jid].keys())
|
|
793
|
|
-
|
|
794
|
|
- def add(self, muc):
|
|
795
|
|
- self._mucs[muc.jid] = muc
|
|
796
|
|
- self.notify('muc-added', self._account, muc.jid)
|
|
797
|
|
-
|
|
798
|
|
- def remove(self, muc):
|
|
799
|
|
- self._mucs.pop(muc.jid, None)
|
|
800
|
|
- self._joined_users.pop(muc.jid, None)
|
|
801
|
|
-
|
|
802
|
|
- def get(self, room_jid):
|
|
803
|
|
- return self._mucs.get(room_jid)
|
|
804
|
|
-
|
|
805
|
|
- def set_state(self, room_jid, state):
|
|
806
|
|
- muc = self._mucs.get(room_jid)
|
|
807
|
|
- if muc is not None:
|
|
808
|
|
- if muc.state == state:
|
|
809
|
|
- return
|
|
810
|
|
- self._log.info('Set MUC state: %s %s', room_jid, state)
|
|
811
|
|
-
|
|
812
|
|
- muc.state = state
|
|
813
|
|
- self.notify('state-changed',
|
|
814
|
|
- state,
|
|
815
|
|
- qualifiers=(self._account, room_jid))
|
|
816
|
|
-
|
|
817
|
|
- def get_joined_mucs(self):
|
|
818
|
|
- mucs = self._mucs.values()
|
|
819
|
|
- return [muc.jid for muc in mucs if muc.state == MUCJoinedState.JOINED]
|
|
820
|
|
-
|
|
821
|
|
- def get_mucs_with_state(self, states):
|
|
822
|
|
- return [muc for muc in self._mucs.values() if muc.state in states]
|
|
823
|
|
-
|
|
824
|
|
- def reset_state(self):
|
|
825
|
|
- client = app.get_client(self._account)
|
|
826
|
|
- for muc in self._mucs.values():
|
|
827
|
|
- self.set_state(muc.jid, MUCJoinedState.NOT_JOINED)
|
|
828
|
|
- self._joined_users.pop(muc.jid, None)
|
|
829
|
|
- room = client.get_module('Contacts').get_contact(muc.jid)
|
|
830
|
|
- room.set_not_joined()
|
|
831
|
|
- room.notify('room-left')
|
|
832
|
|
-
|
|
833
|
|
- def __contains__(self, room_jid):
|
|
834
|
|
- return room_jid in self._mucs
|
|
835
|
|
-
|
|
836
|
|
-
|
|
837
|
820
|
def get_instance(*args, **kwargs):
|
|
838
|
821
|
return MUC(*args, **kwargs), 'MUC'
|