aboutsummaryrefslogtreecommitdiff
path: root/telegram/utils.go
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2024-04-27 07:31:21 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2024-04-27 07:31:21 +0300
commita3f6d5f77402bf4a4d3fa01297f9fd78cc69a3b3 (patch)
tree41458be4520e15c1de22d9c1dba8d37c54c48c73 /telegram/utils.go
parent2459b14948e71a5db640b63a41720f2b197f3fd4 (diff)
Support nativeedits for rawmessages=falsev1.9.3
Diffstat (limited to 'telegram/utils.go')
-rw-r--r--telegram/utils.go60
1 files changed, 35 insertions, 25 deletions
diff --git a/telegram/utils.go b/telegram/utils.go
index 7ab5765..4509d1a 100644
--- a/telegram/utils.go
+++ b/telegram/utils.go
@@ -915,7 +915,7 @@ 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) {
+func (c *Client) messageToPrefix(message *client.Message, previewString string, fileString string, suppressReply bool) (string, *gateway.Reply) {
isPM, err := c.IsPM(message.ChatId)
if err != nil {
log.Errorf("Could not determine if chat is PM: %v", err)
@@ -953,27 +953,32 @@ func (c *Client) messageToPrefix(message *client.Message, previewString string,
}
// reply to
- preview := true
- reply, tgReply := c.getMessageReply(message, preview, false)
+ var reply *gateway.Reply
+ if !suppressReply {
+ preview := true
+ gwReply, tgReply := c.getMessageReply(message, preview, false)
- if tgReply != nil {
- var replyStart, replyEnd int
+ if tgReply != nil {
+ reply = gwReply
- if len(prefix) > 0 {
- replyStart = c.countCharsInLines(&prefix) + (len(prefix)-1)*len(messageHeaderSeparator)
- }
+ var replyStart, replyEnd int
+
+ if len(prefix) > 0 {
+ replyStart = c.countCharsInLines(&prefix) + (len(prefix)-1)*len(messageHeaderSeparator)
+ }
- replyLine := "reply: " + c.formatMessageContent(preview, tgReply)
- prefix = append(prefix, replyLine)
+ replyLine := "reply: " + c.formatMessageContent(preview, tgReply)
+ prefix = append(prefix, replyLine)
- replyEnd = replyStart + utf8.RuneCountInString(replyLine)
- if len(prefix) > 0 {
- replyEnd += len(messageHeaderSeparator)
- }
+ replyEnd = replyStart + utf8.RuneCountInString(replyLine)
+ if len(prefix) > 0 {
+ replyEnd += len(messageHeaderSeparator)
+ }
- if reply != nil {
- reply.Start = uint64(replyStart)
- reply.End = uint64(replyEnd)
+ if reply != nil {
+ reply.Start = uint64(replyStart)
+ reply.End = uint64(replyEnd)
+ }
}
}
@@ -1008,6 +1013,17 @@ func (c *Client) ensureDownloadFile(file *client.File) *client.File {
return file
}
+// \n if it is groupchat and message is not empty
+func (c *Client) getPrefixSeparator(chatId int64) string {
+ var separator string
+ if chatId < 0 {
+ separator = "\n"
+ } else if chatId > 0 {
+ separator = " | "
+ }
+ return separator
+}
+
// 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 := c.isCarbonsEnabled() && message.IsOutgoing
@@ -1051,21 +1067,15 @@ func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message) {
} else if !c.Session.RawMessages {
var newText strings.Builder
- prefix, prefixReply := c.messageToPrefix(message, previewName, fileName)
+ prefix, prefixReply := c.messageToPrefix(message, previewName, fileName, false)
reply = prefixReply
replyObtained = true
newText.WriteString(prefix)
if text != "" {
- // \n if it is groupchat and message is not empty
if prefix != "" {
- if chatId < 0 {
- newText.WriteString("\n")
- } else if chatId > 0 {
- newText.WriteString(" | ")
- }
+ newText.WriteString(c.getPrefixSeparator(chatId))
}
-
newText.WriteString(text)
}
text = newText.String()