From 82a2d1e8e0e7b313df61eca4861850defc45a714 Mon Sep 17 00:00:00 2001 From: Bohdan Horbeshko Date: Tue, 2 Jun 2026 21:43:08 -0400 Subject: [PATCH] Support reply ID accounting for SFS uploads --- xmpp/extensions/extensions.go | 17 +++++++++++++++++ xmpp/handlers.go | 13 ++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/xmpp/extensions/extensions.go b/xmpp/extensions/extensions.go index 9d8914a..d2cdc0c 100644 --- a/xmpp/extensions/extensions.go +++ b/xmpp/extensions/extensions.go @@ -490,6 +490,12 @@ type EntityTime struct { ResultSet *stanza.ResultSet `xml:"set,omitempty"` } +// AttachTo is from XEP-0367 +type AttachTo struct { + XMLName xml.Name `xml:"urn:xmpp:message-attaching:1 attach-to"` + Id string `xml:"id,attr"` +} + // Namespace is a namespace! func (c PresenceNickExtension) Namespace() string { return c.XMLName.Space @@ -720,6 +726,11 @@ func (c MAM2Metadata) GetSet() *stanza.ResultSet { return c.ResultSet } +// Namespace is a namespace! +func (c AttachTo) Namespace() string { + return c.XMLName.Space +} + // NewReplyFallback initializes a fallback range func NewReplyFallback(start uint64, end uint64) Fallback { return Fallback{ @@ -919,4 +930,10 @@ func init() { "urn:xmpp:time", "time", }, EntityTime{}) + + // attach-to + stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{ + "urn:xmpp:message-attaching:1", + "attach-to", + }, AttachTo{}) } diff --git a/xmpp/handlers.go b/xmpp/handlers.go index a0f7670..e08f8b4 100644 --- a/xmpp/handlers.go +++ b/xmpp/handlers.go @@ -233,12 +233,15 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) { var reply extensions.Reply var fallback extensions.Fallback var replace extensions.Replace + var attachTo extensions.AttachTo msg.Get(&reply) msg.Get(&fallback) msg.Get(&replace) + msg.Get(&attachTo) log.Debugf("reply: %#v", reply) log.Debugf("fallback: %#v", fallback) log.Debugf("replace: %#v", replace) + log.Debugf("attachTo: %#v", attachTo) var replyId int64 text := msg.Body @@ -314,12 +317,16 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) { } */ session.AddToEditOutbox(replace.Id, resource) } else { - err = gateway.IdsDB.Set(session.Session.Login, bare, toID, tgMessage.Id, msg.Id) + messageId := msg.Id + if attachTo.Id != "" { + messageId = attachTo.Id + } + err = gateway.IdsDB.Set(session.Session.Login, bare, toID, tgMessage.Id, messageId) if err == nil { // session.AddToOutbox(msg.Id, resource) - session.UpdateLastChatMessageId(toID, msg.Id) + session.UpdateLastChatMessageId(toID, messageId) } else { - log.Errorf("Failed to save ids %v/%v %v", toID, tgMessage.Id, msg.Id) + log.Errorf("Failed to save ids %v/%v %v", toID, tgMessage.Id, messageId) } }