diff options
Diffstat (limited to 'telegram/handlers.go')
-rw-r--r-- | telegram/handlers.go | 92 |
1 files changed, 51 insertions, 41 deletions
diff --git a/telegram/handlers.go b/telegram/handlers.go index 425309e..6266292 100644 --- a/telegram/handlers.go +++ b/telegram/handlers.go @@ -56,30 +56,28 @@ func (c *Client) cleanTempFile(path string) { } func (c *Client) sendMarker(chatId, messageId int64, typ gateway.MarkerType) { - if xmppId, err := gateway.IdsDB.GetByTgIds(c.Session.Login, c.jid, chatId, messageId); err == nil { - resource := c.getFromOutbox(xmppId) - - var stringType string - if typ == gateway.MarkerTypeReceived { - stringType = "received" - } else if typ == gateway.MarkerTypeDisplayed { - stringType = "displayed" - } - log.WithFields(log.Fields{ - "xmppId": xmppId, - "resource": resource, - }).Debugf("marker: %s", stringType) - - if resource != "" { - gateway.SendMessageMarker( - c.jid+"/"+resource, - strconv.FormatInt(chatId, 10), - c.xmpp, - typ, - xmppId, - ) - } + xmppId, err := gateway.IdsDB.GetByTgIds(c.Session.Login, c.jid, chatId, messageId) + if err != nil { + xmppId = strconv.FormatInt(messageId, 10) + } + + var stringType string + if typ == gateway.MarkerTypeReceived { + stringType = "received" + } else if typ == gateway.MarkerTypeDisplayed { + stringType = "displayed" } + log.WithFields(log.Fields{ + "xmppId": xmppId, + }).Debugf("marker: %s", stringType) + + gateway.SendMessageMarker( + c.jid, + strconv.FormatInt(chatId, 10), + c.xmpp, + typ, + xmppId, + ) } func (c *Client) updateHandler() { @@ -306,38 +304,48 @@ func (c *Client) updateMessageContent(update *client.UpdateMessageContent) { } if ok && lastXmppId == xmppId { replaceId = xmppId - message, err := c.client.GetMessage(&client.GetMessageRequest{ - ChatId: update.ChatId, - MessageId: update.MessageId, - }) - if err == nil { - isCarbon = c.isCarbonsEnabled() && message.IsOutgoing - } else { - log.Errorf("No message %v/%v found, cannot reliably determine if it's a carbon", update.ChatId, update.MessageId) - } } else { log.Infof("Mismatching message ids: %v %v, falling back to separate edit message", lastXmppId, xmppId) } } - text := formatter.Format( - textContent.Text.Text, - textContent.Text.Entities, - markupFunction, - ) + message, messageErr := c.client.GetMessage(&client.GetMessageRequest{ + ChatId: update.ChatId, + MessageId: update.MessageId, + }) + var prefix string + if messageErr == nil { + isCarbon = c.isCarbonsEnabled() && message.IsOutgoing + // reply correction support in clients is suboptimal yet, so cut them out for now + prefix, _ = c.messageToPrefix(message, "", "", true) + } else { + log.Errorf("No message %v/%v found, cannot reliably determine if it's a carbon", update.ChatId, update.MessageId) + } + + var text strings.Builder if replaceId == "" { var editChar string if c.Session.AsciiArrows { - editChar = "e " + editChar = "e" } else { - editChar = "✎ " + editChar = "✎" } - text = editChar + fmt.Sprintf("%v | %s", update.MessageId, text) + text.WriteString(fmt.Sprintf("%s %v | ", editChar, update.MessageId)) + } else if prefix != "" { + text.WriteString(prefix) + text.WriteString(c.getPrefixSeparator(update.ChatId)) } + text.WriteString(formatter.Format( + textContent.Text.Text, + textContent.Text.Entities, + markupFunction, + )) + + sChatId := strconv.FormatInt(update.ChatId, 10) for _, jid := range jids { - gateway.SendMessage(jid, strconv.FormatInt(update.ChatId, 10), text, "e"+sId, c.xmpp, nil, replaceId, isCarbon, false) + gateway.SendMessage(jid, sChatId, text.String(), "e"+sId, c.xmpp, nil, replaceId, isCarbon, false) } } } @@ -373,6 +381,8 @@ func (c *Client) updateMessageSendSucceeded(update *client.UpdateMessageSendSucc log.Errorf("failed to replace %v with %v: %v", update.OldMessageId, update.Message.Id, err.Error()) } + c.updateLastMessageHash(update.Message.ChatId, update.Message.Id, update.Message.Content) + c.sendMarker(update.Message.ChatId, update.Message.Id, gateway.MarkerTypeReceived) // clean uploaded files |