aboutsummaryrefslogtreecommitdiff
path: root/telegram
diff options
context:
space:
mode:
Diffstat (limited to 'telegram')
-rw-r--r--telegram/utils.go54
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)
}