From 0277f63129c39f22226f00ac04a982fa5b4ddd9a Mon Sep 17 00:00:00 2001 From: wurstsalat Date: Thu, 21 Oct 2021 17:28:58 +0200 Subject: [PATCH] [omemo] Adapt to Gajim changes --- omemo/backend/devices.py | 1 + omemo/gtk/config.py | 2 +- omemo/gtk/key.py | 2 +- omemo/modules/omemo.py | 11 +++++------ omemo/plugin.py | 23 +++++++++++------------ 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/omemo/backend/devices.py b/omemo/backend/devices.py index a3885d9..651c693 100644 --- a/omemo/backend/devices.py +++ b/omemo/backend/devices.py @@ -82,6 +82,7 @@ class DeviceManager: def get_devices_for_encryption(self, jid): devices_for_encryption = [] + # TODO: if app.contacts.get_groupchat_contact(self._account, jid) is not None: devices_for_encryption = self._get_devices_for_muc_encryption(jid) else: diff --git a/omemo/gtk/config.py b/omemo/gtk/config.py index 63d28d4..6a9c4e6 100644 --- a/omemo/gtk/config.py +++ b/omemo/gtk/config.py @@ -67,7 +67,7 @@ class OMEMOConfigDialog(GajimPluginConfigDialog): return False def update_account_store(self): - for account in sorted(app.contacts.get_accounts()): + for account in sorted(app.settings.get_active_accounts()): if account in self.disabled_accounts: continue if account == 'Local': diff --git a/omemo/gtk/key.py b/omemo/gtk/key.py index 9f2f972..e9af7fa 100644 --- a/omemo/gtk/key.py +++ b/omemo/gtk/key.py @@ -69,7 +69,7 @@ class KeyDialog(Gtk.Dialog): self._groupchat = groupchat self._contact = contact self._windows = windows - self._account = self._contact.account.name + self._account = self._contact.account self._plugin = plugin self._omemo = self._plugin.get_omemo(self._account) self._own_jid = app.get_jid_from_account(self._account) diff --git a/omemo/modules/omemo.py b/omemo/modules/omemo.py index b39cb02..ce046b0 100644 --- a/omemo/modules/omemo.py +++ b/omemo/modules/omemo.py @@ -156,9 +156,7 @@ class OMEMO(BaseModule): callback(event) return - to_jid = app.get_jid_without_resource(event.jid) - - omemo_message = self.backend.encrypt(to_jid, event.message) + omemo_message = self.backend.encrypt(event.jid, event.message) if omemo_message is None: session = event.session if hasattr(event, 'session') else None app.nec.push_incoming_event( @@ -265,6 +263,7 @@ class OMEMO(BaseModule): # History Message from MUC return properties.muc_ofrom.bare + # TODO: contact = app.contacts.get_gc_contact(self._account, room_jid, resource) if contact is not None: return JID.from_string(contact.jid).bare @@ -341,13 +340,14 @@ class OMEMO(BaseModule): def is_contact_in_roster(self, jid): if jid == self._own_jid: return True + # TODO: contact = app.contacts.get_first_contact_from_jid(self._account, jid) if contact is None: return False return contact.sub == 'both' def on_muc_disco_update(self, event): - self._check_if_omemo_capable(event.room_jid) + self._check_if_omemo_capable(event.jid) def on_muc_joined(self, event): self._check_if_omemo_capable(event.room_jid) @@ -440,8 +440,7 @@ class OMEMO(BaseModule): # Trigger dialog to trust new Fingerprints if # the Chat Window is Open - ctrl = app.interface.msg_win_mgr.get_control( - jid, self._account) + ctrl = app.window.get_control(self._account, jid) if ctrl: app.nec.push_incoming_event( NetworkEvent('omemo-new-fingerprint', chat_control=ctrl)) diff --git a/omemo/plugin.py b/omemo/plugin.py index 662d817..f582147 100644 --- a/omemo/plugin.py +++ b/omemo/plugin.py @@ -28,11 +28,12 @@ from gi.repository import Gdk from nbxmpp.namespaces import Namespace -from gajim import dialogs from gajim.common import app, ged + +from gajim.gui.dialogs import ErrorDialog + from gajim.plugins import GajimPlugin from gajim.plugins.plugins_i18n import _ -from gajim.groupchat_control import GroupchatControl AXOLOTL_MISSING = 'You are missing Python3-Axolotl or use an outdated version' PROTOBUF_MISSING = "OMEMO can't import Google Protobuf, you can find help in " \ @@ -91,7 +92,7 @@ class OmemoPlugin(GajimPlugin): 'omemo-new-fingerprint': (ged.PRECORE, self._on_new_fingerprints), 'signed-in': (ged.PRECORE, self._on_signed_in), 'muc-disco-update': (ged.GUI1, self._on_muc_disco_update), - 'muc-joined': (ged.GUI1, self._on_muc_joined), + 'room-joined': (ged.GUI1, self._on_muc_joined), } self.modules = [omemo] self.config_dialog = OMEMOConfigDialog(self) @@ -236,10 +237,10 @@ class OmemoPlugin(GajimPlugin): contact = chat_control.contact omemo = self.get_omemo(account) self.new_fingerprints_available(chat_control) - if isinstance(chat_control, GroupchatControl): + if chat_control.is_groupchat: room = chat_control.room_jid if not omemo.is_omemo_groupchat(room): - dialogs.ErrorDialog( + ErrorDialog( _('Bad Configuration'), _('To use OMEMO in a Groupchat, the Groupchat should be' ' non-anonymous and members-only.')) @@ -279,7 +280,7 @@ class OmemoPlugin(GajimPlugin): jid = chat_control.contact.jid account = chat_control.account omemo = self.get_omemo(account) - if isinstance(chat_control, GroupchatControl): + if chat_control.is_groupchat: for jid_ in omemo.backend.get_muc_members(chat_control.room_jid, without_self=False): fingerprints = omemo.backend.storage.getNewFingerprints(jid_) @@ -287,7 +288,7 @@ class OmemoPlugin(GajimPlugin): self._show_fingerprint_window( chat_control, fingerprints) break - elif not isinstance(chat_control, GroupchatControl): + else: fingerprints = omemo.backend.storage.getNewFingerprints(jid) if fingerprints: self._show_fingerprint_window( @@ -297,13 +298,11 @@ class OmemoPlugin(GajimPlugin): contact = chat_control.contact account = chat_control.account omemo = self.get_omemo(account) - transient = chat_control.parent_win.window if 'dialog' not in self._windows: - is_groupchat = isinstance(chat_control, GroupchatControl) self._windows['dialog'] = \ - KeyDialog(self, contact, transient, - self._windows, groupchat=is_groupchat) + KeyDialog(self, contact, app.window, + self._windows, groupchat=chat_control.is_groupchat) if fingerprints: log.debug('%s => Showing Fingerprint Prompt for %s', account, contact.jid) @@ -326,4 +325,4 @@ class OmemoPlugin(GajimPlugin): msg = _('You have undecided fingerprints') if msg is None: return - chat_control.add_status_message(msg) + chat_control.add_info_message(msg)