core: uid is now set in extra in client.sendMessage:

By setting `uid` in extra, it can now be specified by frontends.
This commit is contained in:
Goffi 2026-07-04 07:51:59 +02:00
commit 7696afb3d8
5 changed files with 14 additions and 18 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -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,
},
]