aboutsummaryrefslogtreecommitdiff
path: root/telegram/handlers.go
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2023-07-16 15:19:11 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2023-07-16 15:19:11 +0300
commit563cb2d624598efdd3819daef00c64079d8a20e1 (patch)
treec19d0d96bc3c68c151d627b1f65091ec081dda67 /telegram/handlers.go
parente954c73bd2d881bc448b6bb2b3cb3a4ad37d0139 (diff)
Avoid webpage preview updates being sent as message edits
Diffstat (limited to 'telegram/handlers.go')
-rw-r--r--telegram/handlers.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/telegram/handlers.go b/telegram/handlers.go
index abc1f5d..93ac284 100644
--- a/telegram/handlers.go
+++ b/telegram/handlers.go
@@ -104,6 +104,13 @@ func (c *Client) updateHandler() {
}
c.updateNewMessage(typedUpdate)
log.Debugf("%#v", typedUpdate.Message)
+ case client.TypeUpdateMessageEdited:
+ typedUpdate, ok := update.(*client.UpdateMessageEdited)
+ if !ok {
+ uhOh()
+ }
+ c.updateMessageEdited(typedUpdate)
+ log.Debugf("%#v", typedUpdate)
case client.TypeUpdateMessageContent:
typedUpdate, ok := update.(*client.UpdateMessageContent)
if !ok {
@@ -229,6 +236,11 @@ func (c *Client) updateNewMessage(update *client.UpdateNewMessage) {
}()
}
+// message content edited
+func (c *Client) updateMessageEdited(update *client.UpdateMessageEdited) {
+ c.addToEditQueue(update.ChatId, update.MessageId)
+}
+
// message content updated
func (c *Client) updateMessageContent(update *client.UpdateMessageContent) {
markupFunction := formatter.EntityToXEP0393
@@ -244,6 +256,14 @@ func (c *Client) updateMessageContent(update *client.UpdateMessageContent) {
}
log.Infof("ignoredResource: %v", ignoredResource)
+ if !c.deleteFromEditQueue(update.ChatId, update.MessageId) {
+ log.WithFields(log.Fields{
+ "chatId": update.ChatId,
+ "messageId": update.MessageId,
+ }).Infof("Content update with no preceding message edit, ignoring")
+ return
+ }
+
jids := c.getCarbonFullJids(true, ignoredResource)
if len(jids) == 0 {
log.Info("The only resource is ignored, aborting")