diff --git a/libervia/backend/core/core_types.py b/libervia/backend/core/core_types.py index 4f5a3e40..7d6c147a 100644 --- a/libervia/backend/core/core_types.py +++ b/libervia/backend/core/core_types.py @@ -286,7 +286,6 @@ class SatXMPPEntity(ABC): subject=None, mess_type="auto", extra=None, - uid=None, no_trigger=False, ): """Send a message to an entity diff --git a/libervia/backend/core/main.py b/libervia/backend/core/main.py index 4ed8007c..f5ac4ea0 100644 --- a/libervia/backend/core/main.py +++ b/libervia/backend/core/main.py @@ -1223,7 +1223,7 @@ class LiberviaBackend(service.Service): mess_type="auto", extra_s="", profile_key=C.PROF_KEY_NONE, - ): + ) -> defer.Deferred[None]: client = self.get_client(profile_key) to_jid = jid.JID(to_jid_s) d = client.sendMessage( @@ -1231,7 +1231,7 @@ class LiberviaBackend(service.Service): ) # sendMessage returns message data, but we must return nothing. d.addCallback(lambda __: None) - return d + return cast(defer.Deferred[None], d) def _set_presence(self, to="", show="", statuses=None, profile_key=C.PROF_KEY_NONE): return self.presence_set(jid.JID(to) if to else None, show, statuses, profile_key) diff --git a/libervia/backend/core/xmpp.py b/libervia/backend/core/xmpp.py index 7464ee71..b4804b8d 100644 --- a/libervia/backend/core/xmpp.py +++ b/libervia/backend/core/xmpp.py @@ -879,9 +879,8 @@ class SatXMPPEntity(core_types.SatXMPPEntity): subject: dict[str, str] | None = None, mess_type: str = "auto", extra: dict[str, Any] | None = None, - uid: str | None = None, no_trigger: bool = False, - ) -> defer.Deferred: + ) -> defer.Deferred[MessageData]: r"""Send a message to an entity @param to_jid: destinee of the message @@ -893,9 +892,7 @@ class SatXMPPEntity(core_types.SatXMPPEntity): @param extra: extra data. Key can be: - info_type: information type, can be TODO - @param uid: unique id: - should be unique at least in this XMPP session - if None, an uuid will be generated + - uid: unique id, if not provided an uuid will be generated @param no_trigger: if True, sendMessage[suffix] trigger will no be used useful when a message need to be sent without any modification /!\ this will also skip encryption methods! @@ -904,13 +901,14 @@ class SatXMPPEntity(core_types.SatXMPPEntity): subject = {} if extra is None: extra = {} + uid = extra.get("uid") or str(uuid.uuid4()) assert mess_type in C.MESS_TYPE_ALL data = { # dict is similar to the one used in client.onMessage "from": self.jid, "to": to_jid, - "uid": uid or str(uuid.uuid4()), + "uid": uid, "message": message, "subject": subject, "type": mess_type, @@ -1041,7 +1039,7 @@ class SatXMPPEntity(core_types.SatXMPPEntity): """ if data["type"] != C.MESS_TYPE_GROUPCHAT: # we don't send groupchat message to bridge, as we get them back - # and they will be added the + # and they will be added then. # we need a message to send something if self.is_message_printable(data): diff --git a/libervia/backend/plugins/plugin_comp_email_gateway/__init__.py b/libervia/backend/plugins/plugin_comp_email_gateway/__init__.py index 20544a37..8a5ed6e2 100644 --- a/libervia/backend/plugins/plugin_comp_email_gateway/__init__.py +++ b/libervia/backend/plugins/plugin_comp_email_gateway/__init__.py @@ -992,12 +992,12 @@ class EmailGatewayComponent(GetDataHandler): except Exception: log.exception("Can't parse mailing list email.") else: + extra["uid"] = message_id await client.sendMessage( user_jid, {"": body}, {"": subject} if subject else None, extra=extra, - uid=message_id, ) def parse_references(self, email: EmailMessage) -> list[str]: diff --git a/tests/unit/test_email_gateway.py b/tests/unit/test_email_gateway.py index f984dda9..da61a155 100644 --- a/tests/unit/test_email_gateway.py +++ b/tests/unit/test_email_gateway.py @@ -164,7 +164,7 @@ class TestEmailGatewayComponent: assert call_args[1] == {"": "Hello, world!\n"} assert call_args[2] == None client.sendMessage.assert_called_once_with( - to_jid, {"": "Hello, world!\n"}, None, extra={}, uid=None + to_jid, {"": "Hello, world!\n"}, None, extra={"uid": None} ) @ed @@ -207,9 +207,9 @@ class TestEmailGatewayComponent: "delivered": True, } ], - } + }, + "uid": None, }, - uid=None, ) @ed @@ -275,8 +275,7 @@ class TestEmailGatewayComponent: to_jid, {"": "Hello, world!\n"}, None, - extra={"headers": {"keywords": "test, example", "urgency": "high"}}, - uid=None, + extra={"headers": {"keywords": "test, example", "urgency": "high"}, "uid": None}, ) @@ -316,7 +315,7 @@ class TestPubsubService: "media_subtype": "octet-stream", "size": 123, "hash_algo": "sha-256", - "file_hash": "0123456789abcdef", + "file_hash": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", "created": 123, }, { @@ -326,7 +325,7 @@ class TestPubsubService: "media_subtype": "octet-stream", "size": 456, "hash_algo": "sha-256", - "file_hash": "0123456789abcdef", + "file_hash": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", "created": 123, }, ]