diff --git a/xmpp/extensions/extensions.go b/xmpp/extensions/extensions.go index 2509cf8..6b21da9 100644 --- a/xmpp/extensions/extensions.go +++ b/xmpp/extensions/extensions.go @@ -221,6 +221,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 @@ -301,6 +307,11 @@ func (ClientMessage) Name() string { return "message" } +// 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{ @@ -386,4 +397,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 4d5dcda..29131b9 100644 --- a/xmpp/handlers.go +++ b/xmpp/handlers.go @@ -149,12 +149,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 var err error @@ -230,12 +233,16 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) { } */ session.AddToEditOutbox(replace.Id, resource) } 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 { // 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, tgMessageId, msg.Id) + log.Errorf("Failed to save ids %v/%v %v", toID, tgMessageId, messageId) } } } else {