From 3110398b51a930e8fab4e882e8cedb9fb19f7f08 Mon Sep 17 00:00:00 2001 From: Gustavo Murayama Date: Fri, 29 Nov 2024 15:24:05 -0300 Subject: [PATCH] fix(firebase): ttl nil pointer (#65) --- extensions/firebase/client/firebase.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/extensions/firebase/client/firebase.go b/extensions/firebase/client/firebase.go index 9a28b90..617e9d7 100644 --- a/extensions/firebase/client/firebase.go +++ b/extensions/firebase/client/firebase.go @@ -4,12 +4,13 @@ import ( "context" "encoding/json" "errors" + "time" + firebase "firebase.google.com/go/v4" "firebase.google.com/go/v4/messaging" "github.com/sirupsen/logrus" "github.com/topfreegames/pusher/interfaces" "google.golang.org/api/option" - "time" ) type firebaseClientImpl struct { @@ -122,12 +123,13 @@ func toFirebaseMessage(message interfaces.Message) messaging.Message { if message.Notification.TitleLocArgs != "" { firebaseMessage.Android.Notification.TitleLocArgs = []string{message.Notification.TitleLocArgs} } - } - if message.TimeToLive != nil { - secs := int(*message.TimeToLive) - ttl := time.Duration(secs) * time.Second - firebaseMessage.Android.TTL = &ttl + if message.TimeToLive != nil { + secs := int(*message.TimeToLive) + ttl := time.Duration(secs) * time.Second + // Add TTL only if there is a Notification, otherwise fails with nil pointer + firebaseMessage.Android.TTL = &ttl + } } return firebaseMessage