Support reply ID accounting for SFS uploads

This commit is contained in:
Bohdan Horbeshko 2026-06-02 21:43:08 -04:00
parent eee277e36e
commit 7d9f20d007
2 changed files with 27 additions and 3 deletions

View file

@ -221,6 +221,12 @@ type EntityTime struct {
ResultSet *stanza.ResultSet `xml:"set,omitempty"` 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! // Namespace is a namespace!
func (c PresenceNickExtension) Namespace() string { func (c PresenceNickExtension) Namespace() string {
return c.XMLName.Space return c.XMLName.Space
@ -301,6 +307,11 @@ func (ClientMessage) Name() string {
return "message" return "message"
} }
// Namespace is a namespace!
func (c AttachTo) Namespace() string {
return c.XMLName.Space
}
// NewReplyFallback initializes a fallback range // NewReplyFallback initializes a fallback range
func NewReplyFallback(start uint64, end uint64) Fallback { func NewReplyFallback(start uint64, end uint64) Fallback {
return Fallback{ return Fallback{
@ -386,4 +397,10 @@ func init() {
"urn:xmpp:time", "urn:xmpp:time",
"time", "time",
}, EntityTime{}) }, EntityTime{})
// attach-to
stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
"urn:xmpp:message-attaching:1",
"attach-to",
}, AttachTo{})
} }

View file

@ -149,12 +149,15 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) {
var reply extensions.Reply var reply extensions.Reply
var fallback extensions.Fallback var fallback extensions.Fallback
var replace extensions.Replace var replace extensions.Replace
var attachTo extensions.AttachTo
msg.Get(&reply) msg.Get(&reply)
msg.Get(&fallback) msg.Get(&fallback)
msg.Get(&replace) msg.Get(&replace)
msg.Get(&attachTo)
log.Debugf("reply: %#v", reply) log.Debugf("reply: %#v", reply)
log.Debugf("fallback: %#v", fallback) log.Debugf("fallback: %#v", fallback)
log.Debugf("replace: %#v", replace) log.Debugf("replace: %#v", replace)
log.Debugf("attachTo: %#v", attachTo)
var replyId int64 var replyId int64
var err error var err error
@ -230,12 +233,16 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) {
} */ } */
session.AddToEditOutbox(replace.Id, resource) session.AddToEditOutbox(replace.Id, resource)
} else { } else {
err = gateway.IdsDB.Set(session.Session.Login, bare, toID, tgMessageId, msg.Id) messageId := msg.Id
if attachTo.Id != "" {
messageId = attachTo.Id
}
err = gateway.IdsDB.Set(session.Session.Login, bare, toID, tgMessageId, messageId)
if err == nil { if err == nil {
// session.AddToOutbox(msg.Id, resource) // session.AddToOutbox(msg.Id, resource)
session.UpdateLastChatMessageId(toID, msg.Id) session.UpdateLastChatMessageId(toID, messageId)
} else { } else {
log.Errorf("Failed to save ids %v/%v %v", toID, tgMessageId, msg.Id) log.Errorf("Failed to save ids %v/%v %v", toID, tgMessageId, messageId)
} }
} }
} else { } else {