From 43afd5dbe004629eed247bde1db73e6053aab2bd Mon Sep 17 00:00:00 2001 From: selfhoster1312 Date: Fri, 27 Feb 2026 19:26:55 +0100 Subject: [PATCH] feat: Allow setting OriginID when sending a message --- xmpp.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/xmpp.go b/xmpp.go index 6998f732..09bda298 100644 --- a/xmpp.go +++ b/xmpp.go @@ -1462,7 +1462,7 @@ type Chat struct { Ooburl string Oobdesc string Lang string - // Only for incoming messages, ID for outgoing messages will be generated. + // Allows to set the origin-id to a unique ID defined by the client. OriginID string // Only for incoming messages, ID for outgoing messages will be generated. StanzaID StanzaID @@ -1853,11 +1853,13 @@ func (c *Client) Send(chat Chat) (n int, err error) { } chat.Text = validUTF8(chat.Text) - id := getUUID() + if chat.OriginID == "" { + chat.OriginID = getUUID() + } stanza := fmt.Sprintf("%s%s"+ "%s%s\n", - xmlEscape(chat.Remote), xmlEscape(chat.Type), id, subtext, xmlEscape(chat.Text), - XMPPNS_SID_0, id, oobtext, thdtext) + xmlEscape(chat.Remote), xmlEscape(chat.Type), chat.OriginID, subtext, xmlEscape(chat.Text), + XMPPNS_SID_0, chat.OriginID, oobtext, thdtext) if c.LimitMaxBytes != 0 && len(stanza) > c.LimitMaxBytes { return 0, fmt.Errorf("stanza size (%v bytes) exceeds server limit (%v bytes)", len(stanza), c.LimitMaxBytes) @@ -1889,10 +1891,12 @@ func (c *Client) SendOOB(chat Chat) (n int, err error) { oobtext += `` + xmlEscape(chat.Oob.Desc) + `` } oobtext += `` - id := getUUID() + if chat.OriginID == "" { + chat.OriginID = getUUID() + } stanza := fmt.Sprintf(""+ "%s%s%s\n", - xmlEscape(chat.Remote), xmlEscape(chat.Type), id, XMPPNS_SID_0, id, + xmlEscape(chat.Remote), xmlEscape(chat.Type), chat.OriginID, XMPPNS_SID_0, chat.OriginID, oobtext, thdtext, xmlEscape(chat.Oob.Url)) if c.LimitMaxBytes != 0 && len(stanza) > c.LimitMaxBytes { return 0, fmt.Errorf("stanza size (%v bytes) exceeds server limit (%v bytes)",