aboutsummaryrefslogtreecommitdiff
path: root/telegram/utils.go
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2024-01-29 12:28:15 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2024-01-29 12:28:15 +0300
commitea004b7f7c11fa0ddf560317fd9d6f9b2869144a (patch)
tree96157b08b5db8fde4088fde0cf1515be0c73bf6a /telegram/utils.go
parentc141c4ad2bebe51562be0a7cfe0671f34b0a49fb (diff)
Reflect Telegram edits natively by nativeedits option
Diffstat (limited to 'telegram/utils.go')
-rw-r--r--telegram/utils.go29
1 files changed, 24 insertions, 5 deletions
diff --git a/telegram/utils.go b/telegram/utils.go
index 966c5c2..2082645 100644
--- a/telegram/utils.go
+++ b/telegram/utils.go
@@ -911,14 +911,17 @@ func (c *Client) countCharsInLines(lines *[]string) (count int) {
return
}
+func (c *Client) isCarbonsEnabled() bool {
+ return gateway.MessageOutgoingPermissionVersion > 0 && c.Session.Carbons
+}
+
func (c *Client) messageToPrefix(message *client.Message, previewString string, fileString string) (string, *gateway.Reply) {
isPM, err := c.IsPM(message.ChatId)
if err != nil {
log.Errorf("Could not determine if chat is PM: %v", err)
}
- isCarbonsEnabled := gateway.MessageOutgoingPermissionVersion > 0 && c.Session.Carbons
// with carbons, hide for all messages in PM and only for outgoing in group chats
- hideSender := isCarbonsEnabled && (message.IsOutgoing || isPM)
+ hideSender := c.isCarbonsEnabled() && (message.IsOutgoing || isPM)
prefix := []string{}
// message direction
@@ -1007,7 +1010,7 @@ func (c *Client) ensureDownloadFile(file *client.File) *client.File {
// ProcessIncomingMessage transfers a message to XMPP side and marks it as read on Telegram side
func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message) {
- isCarbon := gateway.MessageOutgoingPermissionVersion > 0 && c.Session.Carbons && message.IsOutgoing
+ isCarbon := c.isCarbonsEnabled() && message.IsOutgoing
jids := c.getCarbonFullJids(isCarbon, "")
var text, oob, auxText string
@@ -1083,11 +1086,12 @@ func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message) {
sChatId := strconv.FormatInt(chatId, 10)
for _, jid := range jids {
- gateway.SendMessageWithOOB(jid, sChatId, text, sId, c.xmpp, reply, oob, isCarbon, c.Session.Receipts)
+ gateway.SendMessageWithOOB(jid, sChatId, text, sId, c.xmpp, reply, oob, "", isCarbon, c.Session.Receipts)
if auxText != "" {
- gateway.SendMessage(jid, sChatId, auxText, sId, c.xmpp, reply, isCarbon, c.Session.Receipts)
+ gateway.SendMessage(jid, sChatId, auxText, sId, c.xmpp, reply, "", isCarbon, c.Session.Receipts)
}
}
+ c.UpdateLastChatMessageId(chatId, sId)
}
// MarkAsRead marks a message as read
@@ -1588,6 +1592,21 @@ func (c *Client) hasLastMessageHashChanged(chatId, messageId int64, content clie
return !ok || oldHash != newHash
}
+func (c *Client) UpdateLastChatMessageId(chatId int64, messageId string) {
+ c.locks.lastMsgIdsLock.Lock()
+ defer c.locks.lastMsgIdsLock.Unlock()
+
+ c.lastMsgIds[chatId] = messageId
+}
+
+func (c *Client) getLastChatMessageId(chatId int64) (string, bool) {
+ c.locks.lastMsgIdsLock.RLock()
+ defer c.locks.lastMsgIdsLock.RUnlock()
+
+ xmppId, ok := c.lastMsgIds[chatId]
+ return xmppId, ok
+}
+
func (c *Client) getFormatter() formatter.MarkupModeType {
return formatter.MarkupModeXEP0393
}