Philipp Hörist pushed to branch master at gajim / gajim
Commits:
8aed5d2d by lovetox at 2022-08-12T17:54:53+02:00
refactor: Simplify showing current encryption state
- - - - -
4 changed files:
- gajim/gtk/control.py
- gajim/gtk/conversation/rows/message.py
- gajim/gtk/conversation/view.py
- gajim/gtk/message_actions_box.py
Changes:
=====================================
gajim/gtk/control.py
=====================================
@@ -175,7 +175,6 @@ def switch_contact(self, contact: Union[BareContact,
self._roster.switch_contact(contact)
self.encryption = self.get_encryption_state()
- self.conversation_view.encryption_enabled = self.encryption is not None
if isinstance(contact, GroupchatParticipant):
contact.multi_connect({
@@ -293,7 +292,6 @@ def mark_as_read(self, send_marker: bool = True) -> None:
def set_encryption_state(self, encryption: Optional[str]) -> None:
self.encryption = encryption
- self.conversation_view.encryption_enabled = encryption is not None
self.contact.settings.set('encryption', self.encryption or '')
def get_encryption_state(self) -> Optional[str]:
=====================================
gajim/gtk/conversation/rows/message.py
=====================================
@@ -74,7 +74,6 @@ def __init__(self,
display_marking: Optional[Displaymarking] = None,
marker: Optional[str] = None,
error: Union[CommonError, StanzaError, None] = None,
- encryption_enabled: bool = False,
log_line_id: Optional[int] = None) -> None:
BaseRow.__init__(self, account)
@@ -144,8 +143,7 @@ def __init__(self,
if kind in ('incoming', 'incoming_queue', 'outgoing'):
if additional_data is not None:
- encryption_img = self._get_encryption_image(
- additional_data, encryption_enabled)
+ encryption_img = self._get_encryption_image(additional_data)
if encryption_img:
self._meta_box.pack_start(encryption_img, False, True, 0)
@@ -344,12 +342,12 @@ def _on_retract(reason: str) -> None:
def _get_encryption_image(self,
additional_data: AdditionalDataDict,
- encryption_enabled: bool = False
) -> Optional[Gtk.Image]:
+
details = self._get_encryption_details(additional_data)
if details is None:
# Message was not encrypted
- if not encryption_enabled:
+ if not self._contact.settings.get('encryption'):
return None
icon = 'channel-insecure-symbolic'
color = 'unencrypted-color'
=====================================
gajim/gtk/conversation/view.py
=====================================
@@ -75,8 +75,6 @@ def __init__(self) -> None:
self._contact = None
self._client = None
- self.encryption_enabled: bool = False
-
# Keeps track of the number of rows shown in ConversationView
self._row_count: int = 0
self._max_row_count: int = 100
@@ -265,7 +263,6 @@ def add_message(self,
display_marking=display_marking,
marker=marker,
error=error,
- encryption_enabled=self.encryption_enabled,
log_line_id=log_line_id)
if message_id is not None:
=====================================
gajim/gtk/message_actions_box.py
=====================================
@@ -120,11 +120,6 @@ def __init__(self) -> None:
self._connect_actions()
- def _get_encryption_state(self) -> tuple[bool, str]:
- assert self._contact is not None
- encryption = self._contact.settings.get('encryption')
- return bool(encryption), encryption
-
def get_current_contact(self) -> ChatContactT:
assert self._contact is not None
return self._contact
@@ -322,7 +317,6 @@ def _change_encryption(self,
return
self._set_encryption_state(new_state)
- # self.conversation_view.encryption_enabled = encryption is not None
contact = self.get_current_contact()
contact.settings.set('encryption', new_state)
@@ -514,9 +508,10 @@ def _on_buffer_changed(self, textbuffer: Gtk.TextBuffer)
-> None:
send_message_action = app.window.get_action('send-message')
send_message_action.set_enabled(has_text)
- encryption_enabled, encryption_name = self._get_encryption_state()
+ assert self._contact is not None
+ encryption_name = self._contact.settings.get('encryption')
- if has_text and encryption_enabled:
+ if has_text and encryption_name:
app.plugin_manager.extension_point('typing' + encryption_name,
self)
assert self._contact
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/8aed5d2dd79004df46c9567f802c43cec780ce1a
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/8aed5d2dd79004df46c9567f802c43cec780ce1a
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