diff options
author | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2022-03-12 20:25:53 +0300 |
---|---|---|
committer | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2022-03-12 20:25:53 +0300 |
commit | 022a12ce3174ebc53ad7be712fd37077145aaffc (patch) | |
tree | 8d99a186b4f621c2abcb63b6b61ed24be7ac86e8 /telegram/utils.go | |
parent | c6556eb6b86d4267bb35b7a27c34a0046668e3b9 (diff) |
Add /forward command
Diffstat (limited to 'telegram/utils.go')
-rw-r--r-- | telegram/utils.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/telegram/utils.go b/telegram/utils.go index 9b72242..3511de0 100644 --- a/telegram/utils.go +++ b/telegram/utils.go @@ -694,6 +694,59 @@ func (c *Client) messageToPrefix(message *client.Message, fileString string) str return strings.Join(prefix, " | ") } +// ProcessIncomingMessage transfers a message to XMPP side and marks it as read on Telegram side +func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message) { + var text string + content := message.Content + if content != nil && content.MessageContentType() == client.TypeMessageChatChangePhoto { + chat, err := c.client.GetChat(&client.GetChatRequest{ + ChatId: chatId, + }) + if err == nil { + c.cache.SetChat(chatId, chat) + go c.ProcessStatusUpdate(chatId, "", "", gateway.SPImmed(true)) + text = "<Chat photo has changed>" + } + } else { + text = c.messageToText(message, false) + file := c.contentToFile(content) + + // download file (if one) + if file != nil { + newFile, err := c.DownloadFile(file.Id, 1, true) + if err == nil { + file = newFile + } + } + // OTR support (I do not know why would you need it, seriously) + if !(strings.HasPrefix(text, "?OTR") || c.Session.RawMessages) { + var prefix strings.Builder + prefix.WriteString(c.messageToPrefix(message, c.formatFile(file))) + if text != "" { + // \n if it is groupchat and message is not empty + if chatId < 0 { + prefix.WriteString("\n") + } else if chatId > 0 { + prefix.WriteString(" | ") + } + + prefix.WriteString(text) + } + + text = prefix.String() + } + } + + // mark message as read + c.client.ViewMessages(&client.ViewMessagesRequest{ + ChatId: chatId, + MessageIds: []int64{message.Id}, + ForceRead: true, + }) + // forward message to XMPP + gateway.SendMessage(c.jid, strconv.FormatInt(chatId, 10), text, c.xmpp) +} + // ProcessOutgoingMessage executes commands or sends messages to mapped chats func (c *Client) ProcessOutgoingMessage(chatID int64, text string, returnJid string) client.InputMessageContent { if !c.Online() { |