From d2b54cb022f2a2c966a66b197af44cb2bbc687c2 Mon Sep 17 00:00:00 2001 From: wurstsalat Date: Mon, 22 Aug 2022 20:21:07 +0200 Subject: imprv: MessageActionsBox: Disable encryption button if MUC is public Fixes #10959 --- gajim/common/modules/contacts.py | 9 +++++++++ gajim/data/gui/message_actions_box.ui | 3 +-- gajim/gtk/message_actions_box.py | 22 +++++++++++++++++++--- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/gajim/common/modules/contacts.py b/gajim/common/modules/contacts.py index 6eb4e1bc6..e8e65fb39 100644 --- a/gajim/common/modules/contacts.py +++ b/gajim/common/modules/contacts.py @@ -671,6 +671,15 @@ class GroupchatContact(CommonContact): return False return disco_info.is_irc + @property + def encryption_available(self) -> bool: + disco_info = self.get_disco() + if disco_info is None: + return True + + return (disco_info.muc_is_members_only and + disco_info.muc_is_nonanonymous) + def get_config_value(self, field_name: str) -> Any: disco_info = self.get_disco() assert disco_info is not None diff --git a/gajim/data/gui/message_actions_box.ui b/gajim/data/gui/message_actions_box.ui index 29e94a00b..8a7c852bf 100644 --- a/gajim/data/gui/message_actions_box.ui +++ b/gajim/data/gui/message_actions_box.ui @@ -1,5 +1,5 @@ - + @@ -91,7 +91,6 @@ True True True - Choose encryption none diff --git a/gajim/gtk/message_actions_box.py b/gajim/gtk/message_actions_box.py index 42a6be24b..10fcb31c2 100644 --- a/gajim/gtk/message_actions_box.py +++ b/gajim/gtk/message_actions_box.py @@ -219,9 +219,25 @@ class MessageActionsBox(Gtk.Grid, ged.EventHelper): self._set_settings_menu(contact) - encryption = self._contact.settings.get('encryption') - self._set_encryption_state(encryption) - self._set_encryption_details(encryption) + encryption_available = True + if isinstance(self._contact, GroupchatContact): + encryption_available = self._contact.encryption_available + if not encryption_available: + self._ui.encryption_details_button.set_visible(False) + self._ui.encryption_menu_button.set_sensitive(False) + self._ui.encryption_image.set_from_icon_name( + 'channel-insecure-symbolic', Gtk.IconSize.MENU) + self._ui.encryption_menu_button.set_tooltip_text( + _('This is a public group chat. ' + 'Encryption is not available.')) + + if encryption_available: + self._ui.encryption_menu_button.set_sensitive(True) + self._ui.encryption_menu_button.set_tooltip_text( + _('Choose encryption')) + encryption = self._contact.settings.get('encryption') + self._set_encryption_state(encryption) + self._set_encryption_details(encryption) self._set_chatstate(True) -- cgit v1.2.3