diff --git a/omemo/modules/events.py b/omemo/modules/events.py new file mode 100644 index 0000000..fe394d4 --- /dev/null +++ b/omemo/modules/events.py @@ -0,0 +1,28 @@ +# 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 . + +from __future__ import annotations + +from typing import Any + +from dataclasses import dataclass +from dataclasses import field + +from gajim.common.events import ApplicationEvent + + +@dataclass +class OMEMONewFingerprint(ApplicationEvent): + name: str = field(init=False, default='omemo-new-fingerprint') + chat_control: Any diff --git a/omemo/modules/omemo.py b/omemo/modules/omemo.py index 5d69002..128c60c 100644 --- a/omemo/modules/omemo.py +++ b/omemo/modules/omemo.py @@ -31,7 +31,7 @@ from nbxmpp.modules.util import is_error from gajim.common import app from gajim.common import configpaths -from gajim.common.nec import NetworkEvent +from gajim.common.events import MessageNotSent from gajim.common.const import EncryptionData from gajim.common.const import Trust as GajimTrust from gajim.common.modules.base import BaseModule @@ -47,6 +47,7 @@ from omemo.backend.state import MessageNotForDevice from omemo.backend.state import DecryptionFailed from omemo.backend.state import DuplicateMessage from omemo.backend.util import Trust +from omemo.modules.events import OMEMONewFingerprint from omemo.modules.util import prepare_stanza @@ -157,15 +158,12 @@ class OMEMO(BaseModule): 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( - NetworkEvent('message-not-sent', - conn=conn, - jid=event.jid, - message=event.message, - error=_('Encryption error'), - time_=time.time(), - session=session)) + app.ged.raise_event( + MessageNotSent(client=conn, + jid=event.jid, + message=event.message, + error=_('Encryption error'), + time=time.time())) return create_omemo_message(event.stanza, omemo_message, @@ -441,8 +439,7 @@ class OMEMO(BaseModule): # the Chat Window is Open ctrl = app.window.get_control(self._account, jid) if ctrl: - app.nec.push_incoming_event( - NetworkEvent('omemo-new-fingerprint', chat_control=ctrl)) + app.ged.raise_event(OMEMONewFingerprint(chat_control=ctrl)) def set_devicelist(self, devicelist=None): devicelist_ = set([self.backend.own_device])