diff options
author | lovetox <philipp@hoerist.com> | 2022-01-04 00:03:01 +0300 |
---|---|---|
committer | lovetox <philipp@hoerist.com> | 2022-01-04 00:09:50 +0300 |
commit | 616466aceb3ead1f82aa7feccf9b8edfa238c023 (patch) | |
tree | 7b6b77fb9a36647387c51e9881d7fd73a5aa4f89 /pgp/modules | |
parent | 0019a6f8d6997213a20d2f3972bb3cc73caa1982 (diff) |
[pgp] Adapt to Gajim event changes
Diffstat (limited to 'pgp/modules')
-rw-r--r-- | pgp/modules/events.py | 35 | ||||
-rw-r--r-- | pgp/modules/pgp_legacy.py | 25 |
2 files changed, 46 insertions, 14 deletions
diff --git a/pgp/modules/events.py b/pgp/modules/events.py new file mode 100644 index 0000000..fc03533 --- /dev/null +++ b/pgp/modules/events.py @@ -0,0 +1,35 @@ +# This file is part of OMEMO Gajim Plugin. +# +# OMEMO Gajim Plugin is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published +# by the Free Software Foundation; version 3 only. +# +# OMEMO Gajim Plugin is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with OMEMO Gajim Plugin. If not, see <http://www.gnu.org/licenses/>. + +from __future__ import annotations + +from typing import Any, Callable + +from dataclasses import dataclass +from dataclasses import field + +from gajim.common.events import ApplicationEvent + + +@dataclass +class PGPNotTrusted(ApplicationEvent): + name: str = field(init=False, default='pgp-not-trusted') + on_yes: Callable[..., Any] + on_no: Callable[..., Any] + + +@dataclass +class PGPFileEncryptionError(ApplicationEvent): + name: str = field(init=False, default='pgp-file-encryption-error') + error: str diff --git a/pgp/modules/pgp_legacy.py b/pgp/modules/pgp_legacy.py index 049e666..ba34a3c 100644 --- a/pgp/modules/pgp_legacy.py +++ b/pgp/modules/pgp_legacy.py @@ -24,13 +24,15 @@ from nbxmpp.structs import StanzaHandler from gi.repository import GLib from gajim.common import app -from gajim.common.nec import NetworkEvent +from gajim.common.events import MessageNotSent from gajim.common.const import EncryptionData from gajim.common.modules.base import BaseModule from gajim.plugins.plugins_i18n import _ from pgp.backend.python_gnupg import PGP +from pgp.modules.events import PGPFileEncryptionError +from pgp.modules.events import PGPNotTrusted from pgp.modules.util import prepare_stanza from pgp.backend.store import KeyStore from pgp.exceptions import SignError @@ -191,23 +193,19 @@ class PGPLegacy(BaseModule): def on_no(): self._raise_message_not_sent(con, event, error) - app.nec.push_incoming_event( - NetworkEvent('pgp-not-trusted', on_yes=on_yes, on_no=on_no)) + app.ged.raise_event(PGPNotTrusted(on_yes=on_yes, on_no=on_no)) else: self._raise_message_not_sent(con, event, error) @staticmethod def _raise_message_not_sent(con, event, error): - session = event.session if hasattr(event, 'session') else None - app.nec.push_incoming_event( - NetworkEvent('message-not-sent', - conn=con, - jid=event.jid, - message=event.message, - error=_('Encryption error: %s') % error, - time_=time.time(), - session=session)) + app.ged.raise_event( + MessageNotSent(client=con, + jid=event.jid, + message=event.message, + error=_('Encryption error: %s') % error, + time=time.time())) def _create_pgp_legacy_message(self, stanza, payload): stanza.setBody(self._get_info_message()) @@ -297,8 +295,7 @@ class PGPLegacy(BaseModule): @staticmethod def _on_file_encryption_error(error): - app.nec.push_incoming_event( - NetworkEvent('pgp-file-encryption-error', error=error)) + app.ged.raise_event(PGPFileEncryptionError(error=error)) def get_instance(*args, **kwargs): return PGPLegacy(*args, **kwargs), 'PGPLegacy' |