aboutsummaryrefslogtreecommitdiff
path: root/telegram/utils.go
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2022-02-01 03:58:50 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2022-02-01 03:58:50 +0300
commit2bd15ce6f26687e1b7e5a84254eeb52f042719b3 (patch)
treeacc1d5372fd8ffb32e1d7ff3b1cadcf02b767fab /telegram/utils.go
parent3cdb625c5edb90ad6c55bacc2daea51385952750 (diff)
Fix SIGSEGV when a message sender is nil
Diffstat (limited to 'telegram/utils.go')
-rw-r--r--telegram/utils.go16
1 files changed, 9 insertions, 7 deletions
diff --git a/telegram/utils.go b/telegram/utils.go
index fad1bc0..cd83874 100644
--- a/telegram/utils.go
+++ b/telegram/utils.go
@@ -252,13 +252,15 @@ func (c *Client) formatMessage(chatID int64, messageID int64, preview bool, mess
var str strings.Builder
var senderId int64
- switch message.SenderId.MessageSenderType() {
- case client.TypeMessageSenderUser:
- senderUser, _ := message.SenderId.(*client.MessageSenderUser)
- senderId = senderUser.UserId
- case client.TypeMessageSenderChat:
- senderChat, _ := message.SenderId.(*client.MessageSenderChat)
- senderId = senderChat.ChatId
+ if message.SenderId != nil {
+ switch message.SenderId.MessageSenderType() {
+ case client.TypeMessageSenderUser:
+ senderUser, _ := message.SenderId.(*client.MessageSenderUser)
+ senderId = senderUser.UserId
+ case client.TypeMessageSenderChat:
+ senderChat, _ := message.SenderId.(*client.MessageSenderChat)
+ senderId = senderChat.ChatId
+ }
}
str.WriteString(fmt.Sprintf("%v | %s | ", message.Id, c.formatContact(senderId)))
if !preview {