Philipp Hörist pushed to branch master at gajim / gajim
Commits: 761d4068 by Philipp Hörist at 2019-08-21T21:08:24Z MUC: Refactor MUC creation
Clearly separate join and creation even though this is not the case protocol wise
- - - - -
5 changed files:
- gajim/common/const.py - gajim/common/modules/mam.py - gajim/common/modules/muc.py - gajim/groupchat_control.py - gajim/gui_interface.py
Changes:
===================================== gajim/common/const.py ===================================== @@ -205,6 +205,7 @@ class MUCJoinedState(Enum): JOINED = 'joined' NOT_JOINED = 'not joined' JOINING = 'joining' + CREATING = 'creating' CAPTCHA_REQUEST = 'captcha in progress' CAPTCHA_FAILED = 'captcha failed'
===================================== gajim/common/modules/mam.py ===================================== @@ -112,6 +112,11 @@ class MAM(BaseModule): if properties.type.is_groupchat: archive_jid = properties.jid.getBare() disco_info = app.logger.get_last_disco_info(archive_jid) + if disco_info is None: + # This is the case on MUC creation + # After MUC configuration we receive a configuration change + # message before we had the chance to disco the new MUC + return namespace = disco_info.mam_namespace timestamp = properties.timestamp if namespace is None:
===================================== gajim/common/modules/muc.py ===================================== @@ -149,6 +149,13 @@ class MUC(BaseModule): else: self._join(muc_data)
+ def create(self, muc_data): + if not app.account_is_connected(self._account): + return + + self._muc_data[muc_data.jid] = muc_data + self._create(muc_data) + def _on_disco_result(self, result): if is_error_result(result): self._log.info('Disco %s failed: %s', result.jid, result.get_text()) @@ -179,6 +186,20 @@ class MUC(BaseModule): self._set_muc_state(muc_data.jid, MUCJoinedState.JOINING) self._con.connection.send(presence)
+ def _create(self, muc_data): + show = helpers.get_xmpp_show(app.SHOW_LIST[self._con.connected]) + + presence = self._con.get_module('Presence').get_presence( + muc_data.occupant_jid, + show=show, + status=self._con.status) + + presence.setTag(nbxmpp.NS_MUC + ' x') + + self._log.info('Create MUC: %s', muc_data.jid) + self._set_muc_state(muc_data.jid, MUCJoinedState.CREATING) + self._con.connection.send(presence) + def leave(self, room_jid, reason=None): self._log.info('Leave MUC: %s', room_jid) self._remove_join_timeout(room_jid) @@ -236,13 +257,8 @@ class MUC(BaseModule): error=result)) return
- self._log.info('Configuration finished: %s', result.jid) - app.nec.push_incoming_event(NetworkEvent( - 'muc-configuration-finished', - account=self._account, - room_jid=result.jid)) - - self._con.get_module('Discovery').disco_muc(result.jid) + self._con.get_module('Discovery').disco_muc( + result.jid, callback=self._on_disco_result_after_config)
# If this is an automatic room creation try: @@ -258,6 +274,19 @@ class MUC(BaseModule): for jid in invites: self.invite(result.jid, jid)
+ def _on_disco_result_after_config(self, result): + if is_error_result(result): + self._log.info('Disco %s failed: %s', result.jid, result.get_text()) + return + + self._room_join_complete(self._get_muc_data(result.jid)) + + self._log.info('Configuration finished: %s', result.jid) + app.nec.push_incoming_event(NetworkEvent( + 'muc-configuration-finished', + account=self._account, + room_jid=result.jid)) + def update_presence(self, auto=False): mucs = self.get_mucs_with_state([MUCJoinedState.JOINED, MUCJoinedState.JOINING]) @@ -345,6 +374,14 @@ class MUC(BaseModule): room_jid=room_jid, error=properties.error))
+ elif muc_data.state == MUCJoinedState.CREATING: + self._set_muc_state(room_jid, MUCJoinedState.NOT_JOINED) + app.nec.push_incoming_event( + NetworkEvent('muc-creation-failed', + account=self._account, + room_jid=room_jid, + error=properties.error)) + elif muc_data.state == MUCJoinedState.CAPTCHA_REQUEST: app.nec.push_incoming_event( NetworkEvent('muc-captcha-error', @@ -407,15 +444,19 @@ class MUC(BaseModule): if properties.is_muc_self_presence: self._log.info('Self presence: %s', properties.jid) if muc_data.state == MUCJoinedState.JOINING: - self._start_join_timeout(room_jid) if (properties.is_nickname_modified or muc_data.nick != properties.muc_nickname): muc_data.nick = properties.muc_nickname self._log.info('Server modified nickname to: %s', properties.muc_nickname) + + elif muc_data.state == MUCJoinedState.CREATING: + if properties.is_new_room: + self.configure_room(room_jid) + + self._start_join_timeout(room_jid) self._raise_muc_event('muc-self-presence', properties) - if properties.is_new_room: - self.configure_room(room_jid) + else: self._log.info('User joined: %s', properties.jid) self._raise_muc_event('muc-user-joined', properties) @@ -592,19 +633,21 @@ class MUC(BaseModule):
muc_data = self._get_muc_data(room_jid) if muc_data.state == MUCJoinedState.JOINING: - self._remove_join_timeout(room_jid) - self._set_muc_state(room_jid, MUCJoinedState.JOINED) - + self._room_join_complete(muc_data) app.nec.push_incoming_event( NetworkEvent('muc-joined', account=self._account, - room_jid=room_jid)) + room_jid=muc_data.jid)) + + def _room_join_complete(self, muc_data): + self._remove_join_timeout(muc_data.jid) + self._set_muc_state(muc_data.jid, MUCJoinedState.JOINED)
- # We successfully joined a MUC, set add bookmark with autojoin - self._con.get_module('Bookmarks').modify(muc_data.jid, - autojoin=True, - password=muc_data.password, - nick=muc_data.nick) + # We successfully joined a MUC, set add bookmark with autojoin + self._con.get_module('Bookmarks').modify(muc_data.jid, + autojoin=True, + password=muc_data.password, + nick=muc_data.nick)
def _on_voice_request(self, _con, _stanza, properties): if not properties.is_voice_request:
===================================== gajim/groupchat_control.py ===================================== @@ -305,6 +305,7 @@ class GroupchatControl(ChatControlBase): settings_menu.set_menu_model(self.control_menu)
self._event_handlers = [ + ('muc-creation-failed', ged.GUI1, self._on_muc_creation_failed), ('muc-joined', ged.GUI1, self._on_muc_joined), ('muc-join-failed', ged.GUI1, self._on_muc_join_failed), ('muc-user-joined', ged.GUI1, self._on_user_joined), @@ -325,6 +326,7 @@ class GroupchatControl(ChatControlBase): ('muc-voice-approval', ged.GUI1, self._on_voice_approval), ('muc-disco-update', ged.GUI1, self._on_disco_update), ('muc-configuration-finished', ged.GUI1, self._on_configuration_finished), + ('muc-configuration-failed', ged.GUI1, self._on_configuration_failed), ('gc-message-received', ged.GUI1, self._nec_gc_message_received), ('mam-decrypted-message-received', ged.GUI1, self._nec_mam_decrypted_message_received), ('update-gc-avatar', ged.GUI1, self._nec_update_avatar), @@ -1695,8 +1697,15 @@ class GroupchatControl(ChatControlBase):
@event_filter(['account', 'room_jid']) def _on_configuration_finished(self, _event): + self.got_connected() + self._show_page('groupchat') self.add_info_message(_('A new group chat has been created'))
+ @event_filter(['account', 'room_jid']) + def _on_configuration_failed(self, _event): + self.xml.error_label.set_text(to_user_string(event.error)) + self._show_page('error') + @event_filter(['account', 'room_jid']) def _on_nickname_changed(self, event): nick = event.properties.muc_nickname @@ -1950,6 +1959,11 @@ class GroupchatControl(ChatControlBase): self._show_page('error') self.autorejoin = False
+ @event_filter(['account', 'room_jid']) + def _on_muc_creation_failed(self, event): + self.xml.error_label.set_text(to_user_string(event.error)) + self._show_page('error') + @event_filter(['account', 'room_jid']) def _on_presence_error(self, event): error_message = to_user_string(event.properties.error)
===================================== gajim/gui_interface.py ===================================== @@ -1564,7 +1564,7 @@ class Interface: def create_groupchat(self, account, room_jid, config=None): muc_data = self._create_muc_data(account, room_jid, None, config) self.create_groupchat_control(account, room_jid, muc_data) - app.connections[account].get_module('MUC').join(muc_data) + app.connections[account].get_module('MUC').create(muc_data)
def show_or_join_groupchat(self, account, room_jid, **kwargs): if self.show_groupchat(account, room_jid):
View it on GitLab: https://dev.gajim.org/gajim/gajim/commit/761d4068afdc43fd71cc177ccd69a865acd...