Philipp Hörist pushed to branch newcontrol at gajim / gajim


Commits:
c15e1ab1 by lovetox at 2022-07-19T00:04:23+02:00
Make password join work

- - - - -


4 changed files:

- gajim/common/const.py
- gajim/common/modules/muc.py
- gajim/gtk/chat_function_page.py
- gajim/gtk/chat_stack.py


Changes:

=====================================
gajim/common/const.py
=====================================
@@ -246,6 +246,7 @@ class MUCJoinedState(Enum):
     CREATING = 'creating'
     CAPTCHA_REQUEST = 'captcha in progress'
     CAPTCHA_FAILED = 'captcha failed'
+    PASSWORD_REQUEST = 'password request'
 
     def __str__(self):
         return self.name
@@ -274,6 +275,10 @@ def is_captcha_request(self):
     def is_captcha_failed(self):
         return self == MUCJoinedState.CAPTCHA_FAILED
 
+    @property
+    def is_password_request(self):
+        return self == MUCJoinedState.PASSWORD_REQUEST
+
 
 class ClientState(IntEnum):
     DISCONNECTING = 0


=====================================
gajim/common/modules/muc.py
=====================================
@@ -262,7 +262,8 @@ def join(self,
             # join a different nickname, so update MUCData here.
             muc_data.nick = nick
 
-        if not muc_data.state.is_not_joined:
+        if muc_data.state not in (MUCJoinedState.NOT_JOINED,
+                                  MUCJoinedState.PASSWORD_REQUEST):
             self._log.warning('Can’t join MUC %s, state: %s',
                               jid, muc_data.state)
             return
@@ -497,8 +498,7 @@ def _on_error_presence(self,
 
             elif properties.error.condition == 'not-authorized':
                 self._remove_rejoin_timeout(room_jid)
-                muc_data.error = 'password-request'
-                self._set_muc_state(room_jid, MUCJoinedState.NOT_JOINED)
+                self._set_muc_state(room_jid, MUCJoinedState.PASSWORD_REQUEST)
                 room.notify('room-password-required', properties)
 
             else:
@@ -774,6 +774,9 @@ def _fake_subject_change(self, room_jid: str) -> None:
         room = self._get_contact(room_jid)
         room.notify('room-joined')
 
+    def cancel_password_request(self, room_jid: str) -> None:
+        self._set_muc_state(room_jid, MUCJoinedState.NOT_JOINED)
+
     def _room_join_complete(self, muc_data: MUCData):
         self._remove_join_timeout(muc_data.jid)
         self._set_muc_state(muc_data.jid, MUCJoinedState.JOINED)


=====================================
gajim/gtk/chat_function_page.py
=====================================
@@ -156,6 +156,7 @@ def set_mode(self,
             self._confirm_button.get_style_context().add_class(
                 'suggested-action')
             self._widget = InputWidget(self._contact, mode)
+            self._widget.connect('changed', self._on_ready)
 
         elif mode == 'captcha-request':
             self._confirm_button.set_label(_('Join'))
@@ -259,14 +260,19 @@ def _on_confirm_clicked(self, _button: Gtk.Button) -> 
None:
         self.emit('finish', False)
 
     def _on_cancel_clicked(self, _button: Gtk.Button) -> None:
+        assert self._client is not None
+        assert self._contact is not None
+
         if self._mode == 'captcha-request':
-            assert self._client is not None
-            assert self._contact is not None
             self._client.get_module('MUC').cancel_captcha(
                 self._contact.jid)
             self.emit('finish', True)
             return
 
+        if self._mode == 'password-request':
+            self._client.get_module('MUC').cancel_password_request(
+                self._contact.jid)
+
         if self._mode in (
                 'join-failed',
                 'creation-failed',


=====================================
gajim/gtk/chat_stack.py
=====================================
@@ -135,10 +135,11 @@ def show_chat(self, account: str, jid: JID) -> None:
                     self._show_chat_function_page('captcha-request')
                     return
 
+                if muc_data.state.is_password_request:
+                    self._show_chat_function_page('password-request')
+                    return
+
                 if not muc_data.state.is_joined:
-                    if muc_data.error == 'password-request':
-                        self._show_chat_function_page('password-request')
-                        return
                     if muc_data.error == 'captcha-failed':
                         self._show_chat_function_page(
                             'captcha-error', muc_data.error_text)



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/c15e1ab1232dc3d52b700fe92503f5977d93e11b

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/c15e1ab1232dc3d52b700fe92503f5977d93e11b
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to