diff options
author | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2023-11-12 00:10:23 +0300 |
---|---|---|
committer | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2023-11-12 00:10:23 +0300 |
commit | 576acba0d18717da5abc5a232cf92c23c9b8a550 (patch) | |
tree | e6527fc83726c07ba1a96cea54fb8b63b82aff27 /telegram/utils.go | |
parent | 67b8ad57f0aab1a033cbd8bcc8e75cf23342f5f9 (diff) |
Migrate to TDLib 1.8.21
Diffstat (limited to 'telegram/utils.go')
-rw-r--r-- | telegram/utils.go | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/telegram/utils.go b/telegram/utils.go index 6edea31..b22f156 100644 --- a/telegram/utils.go +++ b/telegram/utils.go @@ -343,20 +343,28 @@ func (c *Client) formatSender(message *client.Message) string { } func (c *Client) getMessageReply(message *client.Message) (reply *gateway.Reply, replyMsg *client.Message) { - if message.ReplyToMessageId != 0 { + if message.ReplyTo != nil && message.ReplyTo.MessageReplyToType() == client.TypeMessageReplyToMessage { + replyTo, _ := message.ReplyTo.(*client.MessageReplyToMessage) + // TODO: support replies from other chats + if message.ChatId != replyTo.ChatId { + log.Warn("Reply from other/unknown chat") + log.Debugf("replyTo: %#v", replyTo) + return + } + var err error replyMsg, err = c.client.GetMessage(&client.GetMessageRequest{ ChatId: message.ChatId, - MessageId: message.ReplyToMessageId, + MessageId: replyTo.MessageId, }) if err != nil { log.Errorf("<error fetching message: %s>", err.Error()) return } - replyId, err := gateway.IdsDB.GetByTgIds(c.Session.Login, c.jid, message.ChatId, message.ReplyToMessageId) + replyId, err := gateway.IdsDB.GetByTgIds(c.Session.Login, c.jid, message.ChatId, replyTo.MessageId) if err != nil { - replyId = strconv.FormatInt(message.ReplyToMessageId, 10) + replyId = strconv.FormatInt(replyTo.MessageId, 10) } reply = &gateway.Reply{ Author: fmt.Sprintf("%v@%s", c.getSenderId(replyMsg), gateway.Jid.Full()), @@ -417,30 +425,27 @@ func (c *Client) formatMessage(chatID int64, messageID int64, preview bool, mess } func (c *Client) formatForward(fwd *client.MessageForwardInfo) string { - switch fwd.Origin.MessageForwardOriginType() { - case client.TypeMessageForwardOriginUser: - originUser := fwd.Origin.(*client.MessageForwardOriginUser) + switch fwd.Origin.MessageOriginType() { + case client.TypeMessageOriginUser: + originUser := fwd.Origin.(*client.MessageOriginUser) return c.formatContact(originUser.SenderUserId) - case client.TypeMessageForwardOriginChat: - originChat := fwd.Origin.(*client.MessageForwardOriginChat) + case client.TypeMessageOriginChat: + originChat := fwd.Origin.(*client.MessageOriginChat) var signature string if originChat.AuthorSignature != "" { signature = fmt.Sprintf(" (%s)", originChat.AuthorSignature) } return c.formatContact(originChat.SenderChatId) + signature - case client.TypeMessageForwardOriginHiddenUser: - originUser := fwd.Origin.(*client.MessageForwardOriginHiddenUser) + case client.TypeMessageOriginHiddenUser: + originUser := fwd.Origin.(*client.MessageOriginHiddenUser) return originUser.SenderName - case client.TypeMessageForwardOriginChannel: - channel := fwd.Origin.(*client.MessageForwardOriginChannel) + case client.TypeMessageOriginChannel: + channel := fwd.Origin.(*client.MessageOriginChannel) var signature string if channel.AuthorSignature != "" { signature = fmt.Sprintf(" (%s)", channel.AuthorSignature) } return c.formatContact(channel.ChatId) + signature - case client.TypeMessageForwardOriginMessageImport: - originImport := fwd.Origin.(*client.MessageForwardOriginMessageImport) - return originImport.SenderName } return "Unknown forward type" } @@ -890,11 +895,12 @@ func (c *Client) messageToPrefix(message *client.Message, previewString string, } } // reply to - if message.ReplyToMessageId != 0 { + if message.ReplyTo != nil && message.ReplyTo.MessageReplyToType() == client.TypeMessageReplyToMessage { + replyTo, _ := message.ReplyTo.(*client.MessageReplyToMessage) if len(prefix) > 0 { replyStart = c.countCharsInLines(&prefix) + (len(prefix)-1)*len(messageHeaderSeparator) } - replyLine := "reply: " + c.formatMessage(message.ChatId, message.ReplyToMessageId, true, replyMsg) + replyLine := "reply: " + c.formatMessage(message.ChatId, replyTo.MessageId, true, replyMsg) prefix = append(prefix, replyLine) replyEnd = replyStart + utf8.RuneCountInString(replyLine) if len(prefix) > 0 { @@ -1116,7 +1122,7 @@ func (c *Client) ProcessOutgoingMessage(chatID int64, text string, returnJid str tgMessage, err := c.client.SendMessage(&client.SendMessageRequest{ ChatId: chatID, - ReplyToMessageId: reply, + ReplyTo: &client.InputMessageReplyToMessage{MessageId: reply}, InputMessageContent: content, }) if err != nil { |