Commit 616466ac authored by Philipp Hörist's avatar Philipp Hörist
Browse files

[pgp] Adapt to Gajim event changes

parent 0019a6f8
# 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
......@@ -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'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment