[pgp] Adapt to Gajim event changes

This commit is contained in:
lovetox
2022-01-03 22:03:01 +01:00
parent 0019a6f8d6
commit 616466aceb
2 changed files with 46 additions and 14 deletions

35
pgp/modules/events.py Normal file
View File

@@ -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

View File

@@ -24,13 +24,15 @@ from nbxmpp.structs import StanzaHandler
from gi.repository import GLib from gi.repository import GLib
from gajim.common import app 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.const import EncryptionData
from gajim.common.modules.base import BaseModule from gajim.common.modules.base import BaseModule
from gajim.plugins.plugins_i18n import _ from gajim.plugins.plugins_i18n import _
from pgp.backend.python_gnupg import PGP 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.modules.util import prepare_stanza
from pgp.backend.store import KeyStore from pgp.backend.store import KeyStore
from pgp.exceptions import SignError from pgp.exceptions import SignError
@@ -191,23 +193,19 @@ class PGPLegacy(BaseModule):
def on_no(): def on_no():
self._raise_message_not_sent(con, event, error) self._raise_message_not_sent(con, event, error)
app.nec.push_incoming_event( app.ged.raise_event(PGPNotTrusted(on_yes=on_yes, on_no=on_no))
NetworkEvent('pgp-not-trusted', on_yes=on_yes, on_no=on_no))
else: else:
self._raise_message_not_sent(con, event, error) self._raise_message_not_sent(con, event, error)
@staticmethod @staticmethod
def _raise_message_not_sent(con, event, error): def _raise_message_not_sent(con, event, error):
session = event.session if hasattr(event, 'session') else None app.ged.raise_event(
app.nec.push_incoming_event( MessageNotSent(client=con,
NetworkEvent('message-not-sent', jid=event.jid,
conn=con, message=event.message,
jid=event.jid, error=_('Encryption error: %s') % error,
message=event.message, time=time.time()))
error=_('Encryption error: %s') % error,
time_=time.time(),
session=session))
def _create_pgp_legacy_message(self, stanza, payload): def _create_pgp_legacy_message(self, stanza, payload):
stanza.setBody(self._get_info_message()) stanza.setBody(self._get_info_message())
@@ -297,8 +295,7 @@ class PGPLegacy(BaseModule):
@staticmethod @staticmethod
def _on_file_encryption_error(error): def _on_file_encryption_error(error):
app.nec.push_incoming_event( app.ged.raise_event(PGPFileEncryptionError(error=error))
NetworkEvent('pgp-file-encryption-error', error=error))
def get_instance(*args, **kwargs): def get_instance(*args, **kwargs):
return PGPLegacy(*args, **kwargs), 'PGPLegacy' return PGPLegacy(*args, **kwargs), 'PGPLegacy'