Philipp Hörist pushed to branch master at gajim / gajim
Commits: 5f77a254 by Philipp Hörist at 2023-04-17T20:58:16+02:00 refactor: Don’t pass nbxmpp errors and properties to GUI layer
Process as much as possible in the common module
- - - - -
4 changed files:
- gajim/common/events.py - gajim/common/modules/muc.py - gajim/gtk/chat_stack.py - gajim/gtk/control.py
Changes:
===================================== gajim/common/events.py ===================================== @@ -711,7 +711,7 @@ class MUCRoomConfigFinished(ApplicationEvent): class MUCRoomPresenceError(ApplicationEvent): name: str = field(init=False, default='muc-room-presence-error') timestamp: float - error: Any + error: str
@dataclass
===================================== gajim/common/modules/muc.py ===================================== @@ -306,7 +306,8 @@ def _on_disco_result(self, task: Task) -> None: self._log.info('Disco %s failed: %s', error.jid, error.get_text())
room = self._get_contact(error.jid.bare) - room.notify('room-join-failed', error) + error_text = helpers.to_user_string(error) + room.notify('room-join-failed', error_text) return
muc_data = self._mucs.get(result.info.jid) @@ -400,7 +401,8 @@ def _on_room_config(self, task: Task) -> None: self._log.info(error)
room = self._get_contact(error.jid.bare) - room.notfiy('room-config-failed', error) + error_text = helpers.to_user_string(error) + room.notfiy('room-config-failed', error_text) return
self._log.info('Configure room: %s', result.jid) @@ -433,7 +435,8 @@ def _on_config_result(self, task: Task) -> None: self._log.info(error)
room = self._get_contact(error.jid.bare) - room.notfiy('room-config-failed', error) + error_text = helpers.to_user_string(error) + room.notfiy('room-config-failed', error_text) return
self._con.get_module('Discovery').disco_muc( @@ -507,7 +510,7 @@ def _on_error_presence(self, elif properties.error.condition == 'not-authorized': self._remove_rejoin_timeout(room_jid) self._set_muc_state(room_jid, MUCJoinedState.PASSWORD_REQUEST) - room.notify('room-password-required', properties) + room.notify('room-password-required')
else: self._set_muc_state(room_jid, MUCJoinedState.NOT_JOINED) @@ -516,14 +519,14 @@ def _on_error_presence(self, assert isinstance(properties.error, CommonError) muc_data.error_text = helpers.to_user_string( properties.error) - room.notify('room-join-failed', properties.error) + room.notify('room-join-failed', muc_data.error_text)
elif muc_data.state == MUCJoinedState.CREATING: self._set_muc_state(room_jid, MUCJoinedState.NOT_JOINED) muc_data.error = 'creation-failed' assert isinstance(properties.error, CommonError) muc_data.error_text = helpers.to_user_string(properties.error) - room.notify('room-creation-failed', properties) + room.notify('room-creation-failed', muc_data.error_text)
elif muc_data.state == MUCJoinedState.CAPTCHA_REQUEST: self._set_muc_state(room_jid, MUCJoinedState.CAPTCHA_FAILED) @@ -531,18 +534,19 @@ def _on_error_presence(self, muc_data.error = 'captcha-failed' assert isinstance(properties.error, CommonError) muc_data.error_text = helpers.to_user_string(properties.error) - room.notify('room-captcha-error', properties.error) + room.notify('room-captcha-error', muc_data.error_text)
elif muc_data.state == MUCJoinedState.CAPTCHA_FAILED: self._set_muc_state(room_jid, MUCJoinedState.NOT_JOINED)
else: + error = helpers.to_user_string(properties.error) event = events.MUCRoomPresenceError( timestamp=time.time(), - error=properties.error) + error=error) assert isinstance(room, GroupchatContact) app.storage.events.store(room, event) - room.notify('room-presence-error', properties) + room.notify('room-presence-error', event)
def _on_muc_user_presence(self, _con: types.xmppClient, @@ -940,7 +944,7 @@ def _on_captcha_challenge(self, self._remove_rejoin_timeout(properties.jid)
room = self._get_contact(properties.jid.bare) - room.notify('room-captcha-challenge', properties) + room.notify('room-captcha-challenge')
raise nbxmpp.NodeProcessed
@@ -974,7 +978,8 @@ def _on_captcha_result(self, task: Task) -> None: return self._set_muc_state(error.jid, MUCJoinedState.CAPTCHA_FAILED) room = self._get_contact(error.jid) - room.notify('room-captcha-error', error) + error_text = helpers.to_user_string(error) + room.notify('room-captcha-error', error_text)
def _on_config_change(self, _con: types.xmppClient,
===================================== gajim/gtk/chat_stack.py ===================================== @@ -26,9 +26,7 @@ from gi.repository import Gio from gi.repository import GLib from gi.repository import Gtk -from nbxmpp.errors import StanzaError from nbxmpp.protocol import JID -from nbxmpp.structs import MessageProperties
from gajim.common import app from gajim.common import events @@ -266,16 +264,14 @@ def show_chat(self, account: str, jid: JID) -> None:
def _on_room_password_required(self, _contact: GroupchatContact, - _signal_name: str, - _properties: MessageProperties + _signal_name: str ) -> None:
self._show_chat_function_page(FunctionMode.PASSWORD_REQUEST)
def _on_room_captcha_challenge(self, contact: GroupchatContact, - _signal_name: str, - _properties: MessageProperties + _signal_name: str ) -> None:
self._show_chat_function_page(FunctionMode.CAPTCHA_REQUEST) @@ -283,39 +279,34 @@ def _on_room_captcha_challenge(self, def _on_room_captcha_error(self, _contact: GroupchatContact, _signal_name: str, - error: StanzaError + error: str ) -> None:
- error_text = helpers.to_user_string(error) - self._show_chat_function_page(FunctionMode.CAPTCHA_ERROR, error_text) + self._show_chat_function_page(FunctionMode.CAPTCHA_ERROR, error)
def _on_room_creation_failed(self, _contact: GroupchatContact, _signal_name: str, - properties: MessageProperties + error: str ) -> None:
- assert properties.error is not None - error_text = helpers.to_user_string(properties.error) - self._show_chat_function_page(FunctionMode.CREATION_FAILED, error_text) + self._show_chat_function_page(FunctionMode.CREATION_FAILED, error)
def _on_room_join_failed(self, _contact: GroupchatContact, _signal_name: str, - error: StanzaError + error: str ) -> None:
- self._show_chat_function_page( - FunctionMode.JOIN_FAILED, helpers.to_user_string(error)) + self._show_chat_function_page(FunctionMode.JOIN_FAILED, error)
def _on_room_config_failed(self, _contact: GroupchatContact, _signal_name: str, - error: StanzaError + error: str ) -> None:
- self._show_chat_function_page( - FunctionMode.CONFIG_FAILED, helpers.to_user_string(error)) + self._show_chat_function_page(FunctionMode.CONFIG_FAILED)
def _on_muc_state_changed(self, contact: GroupchatContact,
===================================== gajim/gtk/control.py ===================================== @@ -39,7 +39,6 @@ from gajim.common.ged import EventHelper from gajim.common.helpers import AdditionalDataDict from gajim.common.helpers import get_retraction_text -from gajim.common.helpers import to_user_string from gajim.common.i18n import _ from gajim.common.modules.contacts import BareContact from gajim.common.modules.contacts import GroupchatContact @@ -1077,8 +1076,7 @@ def _process_muc_room_presence_error(self, event: events.MUCRoomPresenceError ) -> None:
- error_message = to_user_string(event.error) - self.add_info_message(_('Error: %s') % error_message) + self.add_info_message(_('Error: %s') % event.error)
def _on_room_destroyed(self, _contact: GroupchatContact,
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/5f77a2545226bc9d0e0782e44744af3cc...