From 274fb09ed4374c0732b1a7763a3c675037948822 Mon Sep 17 00:00:00 2001 From: Wim Date: Sat, 23 May 2020 19:15:26 +0200 Subject: Fix forward from hidden users (telegram). Closes #1131 (#1143) Use ForwardDate to check if a message is forwarded. If we have a nil ForwardedFrom then make this an unknown user. --- bridge/telegram/handlers.go | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'bridge') diff --git a/bridge/telegram/handlers.go b/bridge/telegram/handlers.go index 56fd6540..f73c8b0f 100644 --- a/bridge/telegram/handlers.go +++ b/bridge/telegram/handlers.go @@ -39,22 +39,32 @@ func (b *Btelegram) handleGroups(rmsg *config.Message, message *tgbotapi.Message // handleForwarded handles forwarded messages func (b *Btelegram) handleForwarded(rmsg *config.Message, message *tgbotapi.Message) { - if message.ForwardFrom != nil { - usernameForward := "" - if b.GetBool("UseFirstName") { - usernameForward = message.ForwardFrom.FirstName - } - if usernameForward == "" { - usernameForward = message.ForwardFrom.UserName - if usernameForward == "" { - usernameForward = message.ForwardFrom.FirstName - } - } + if message.ForwardDate == 0 { + return + } + + if message.ForwardFrom == nil { + rmsg.Text = "Forwarded from " + unknownUser + ": " + rmsg.Text + return + } + + usernameForward := "" + if b.GetBool("UseFirstName") { + usernameForward = message.ForwardFrom.FirstName + } + + if usernameForward == "" { + usernameForward = message.ForwardFrom.UserName if usernameForward == "" { - usernameForward = unknownUser + usernameForward = message.ForwardFrom.FirstName } - rmsg.Text = "Forwarded from " + usernameForward + ": " + rmsg.Text } + + if usernameForward == "" { + usernameForward = unknownUser + } + + rmsg.Text = "Forwarded from " + usernameForward + ": " + rmsg.Text } // handleQuoting handles quoting of previous messages -- cgit v1.2.3