aboutsummaryrefslogtreecommitdiff
path: root/xmpp/handlers.go
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2023-06-05 11:22:13 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2023-06-05 11:22:13 +0300
commit7215d11d7973b9896c6223938649c75165fa3ae7 (patch)
tree0aa0bf028cc899a283eb55654ee7618eba167681 /xmpp/handlers.go
parenta5c90340ad2da16a68ddcbfa3d9573f0664067ca (diff)
XEP-0308 message editing
Diffstat (limited to 'xmpp/handlers.go')
-rw-r--r--xmpp/handlers.go43
1 files changed, 42 insertions, 1 deletions
diff --git a/xmpp/handlers.go b/xmpp/handlers.go
index 5178acd..51fd831 100644
--- a/xmpp/handlers.go
+++ b/xmpp/handlers.go
@@ -102,10 +102,13 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) {
if ok {
var reply extensions.Reply
var fallback extensions.Fallback
+ var replace extensions.Replace
msg.Get(&reply)
msg.Get(&fallback)
+ msg.Get(&replace)
log.Debugf("reply: %#v", reply)
log.Debugf("fallback: %#v", fallback)
+ log.Debugf("replace: %#v", replace)
var replyId int64
var err error
@@ -138,8 +141,46 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) {
text = text[:start] + text[end:]
}
}
+ var replaceId int64
+ if replace.Id != "" {
+ chatId, msgId, err := gateway.IdsDB.GetByXmppId(session.Session.Login, bare, replace.Id)
+ if err == nil {
+ if chatId != toID {
+ gateway.SendTextMessage(msg.From, strconv.FormatInt(toID, 10), "<ERROR: Chat mismatch>", component)
+ return
+ }
+ replaceId = msgId
+ log.Debugf("replace tg: %#v %#v", chatId, msgId)
+ } else {
+ gateway.SendTextMessage(msg.From, strconv.FormatInt(toID, 10), "<ERROR: Could not find matching message to edit>", component)
+ return
+ }
+ }
- session.ProcessOutgoingMessage(toID, text, msg.From, msg.Id, replyId)
+ tgMessageId := session.ProcessOutgoingMessage(toID, text, msg.From, replyId, replaceId)
+ if tgMessageId != 0 {
+ if replaceId != 0 {
+ // not needed (is it persistent among clients though?)
+ /* err = gateway.IdsDB.ReplaceIdPair(session.Session.Login, bare, replace.Id, msg.Id, tgMessageId)
+ if err != nil {
+ log.Errorf("Failed to replace id %v with %v %v", replace.Id, msg.Id, tgMessageId)
+ } */
+ } else {
+ err = gateway.IdsDB.Set(session.Session.Login, bare, toID, tgMessageId, msg.Id)
+ if err != nil {
+ log.Errorf("Failed to save ids %v/%v %v", toID, tgMessageId, msg.Id)
+ }
+ }
+ } else {
+ /*
+ // if a message failed to edit on Telegram side, match new XMPP ID with old Telegram ID anyway
+ if replaceId != 0 {
+ err = gateway.IdsDB.ReplaceXmppId(session.Session.Login, bare, replace.Id, msg.Id)
+ if err != nil {
+ log.Errorf("Failed to replace id %v with %v", replace.Id, msg.Id)
+ }
+ } */
+ }
return
} else {
toJid, err := stanza.NewJid(msg.To)