diff options
author | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2022-01-10 12:29:50 +0300 |
---|---|---|
committer | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2022-01-10 12:29:50 +0300 |
commit | 77f9c9f74e9cb2b8e73ac3b51b7b17541884489e (patch) | |
tree | ee5d7b965333f55d8e03591ace293b76fa6974bf /telegram | |
parent | 9f04ed51bd26923afec70f086bdeba934fec32ba (diff) |
ForwardInfo refactoring
Diffstat (limited to 'telegram')
-rw-r--r-- | telegram/utils.go | 54 |
1 files changed, 30 insertions, 24 deletions
diff --git a/telegram/utils.go b/telegram/utils.go index 7cc6256..0a70af8 100644 --- a/telegram/utils.go +++ b/telegram/utils.go @@ -271,6 +271,32 @@ func (c *Client) formatMessage(chatID int64, messageID int64, preview bool, mess return str.String() } +func (c *Client) formatForward(fwd *client.MessageForwardInfo) string { + switch fwd.Origin.MessageForwardOriginType() { + case client.TypeMessageForwardOriginUser: + originUser := fwd.Origin.(*client.MessageForwardOriginUser) + return c.formatContact(originUser.SenderUserID) + case client.TypeMessageForwardOriginChat: + originChat := fwd.Origin.(*client.MessageForwardOriginChat) + 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) + return originUser.SenderName + case client.TypeMessageForwardOriginChannel: + channel := fwd.Origin.(*client.MessageForwardOriginChannel) + var signature string + if channel.AuthorSignature != "" { + signature = fmt.Sprintf(" (%s)", channel.AuthorSignature) + } + return c.formatContact(channel.ChatID)+signature + } + return "Unknown forward type" +} + func (c *Client) formatContent(file *client.File, filename string) string { if file == nil { return "" @@ -447,34 +473,14 @@ func (c *Client) messageToPrefix(message *client.Message, fileString string) str } prefix = append(prefix, c.formatContact(senderId)) } - if message.ForwardInfo != nil { - switch message.ForwardInfo.Origin.MessageForwardOriginType() { - case client.TypeMessageForwardOriginUser: - originUser := message.ForwardInfo.Origin.(*client.MessageForwardOriginUser) - prefix = append(prefix, "fwd: "+c.formatContact(originUser.SenderUserID)) - case client.TypeMessageForwardOriginChat: - originChat := message.ForwardInfo.Origin.(*client.MessageForwardOriginChat) - var signature string - if originChat.AuthorSignature != "" { - signature = fmt.Sprintf(" (%s)", originChat.AuthorSignature) - } - prefix = append(prefix, "fwd: "+c.formatContact(originChat.SenderChatID)+signature) - case client.TypeMessageForwardOriginHiddenUser: - originUser := message.ForwardInfo.Origin.(*client.MessageForwardOriginHiddenUser) - prefix = append(prefix, fmt.Sprintf("fwd: anonymous (%s)", originUser.SenderName)) - case client.TypeMessageForwardOriginChannel: - channel := message.ForwardInfo.Origin.(*client.MessageForwardOriginChannel) - var signature string - if channel.AuthorSignature != "" { - signature = fmt.Sprintf(" (%s)", channel.AuthorSignature) - } - prefix = append(prefix, "fwd: "+c.formatContact(channel.ChatID)+signature) - } - } // reply to if message.ReplyToMessageID != 0 { prefix = append(prefix, "reply: "+c.formatMessage(message.ChatID, message.ReplyToMessageID, true, nil)) } + if message.ForwardInfo != nil { + prefix = append(prefix, "fwd: "+c.formatForward(message.ForwardInfo)) + } + // file if fileString != "" { prefix = append(prefix, "file: "+fileString) } |