From 22ed41a960e0bee59800c2b96a5fae7675a98d1d Mon Sep 17 00:00:00 2001 From: Ales Verbic Date: Mon, 22 Jan 2024 22:41:12 -0500 Subject: [PATCH] fix: update refreshing FCM tokens Signed-off-by: Ales Verbic --- output/push/push.go | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/output/push/push.go b/output/push/push.go index 7ef0a67..3443b1e 100644 --- a/output/push/push.go +++ b/output/push/push.go @@ -188,25 +188,19 @@ func (p *PushOutput) Start() error { return nil } -// AddNewFcmTokens adds only the new FCM tokens to the fcmTokens slice -func (p *PushOutput) AddNewFcmTokens() { +// refreshFcmTokens adds only the new FCM tokens to the fcmTokens slice +func (p *PushOutput) refreshFcmTokens() { tokenMap := GetFcmTokens() - existingTokens := make(map[string]bool, len(p.fcmTokens)) - for _, token := range p.fcmTokens { - existingTokens[token] = true - } - - for _, newToken := range tokenMap { - if _, exists := existingTokens[newToken]; !exists { - p.fcmTokens = append(p.fcmTokens, newToken) - } + p.fcmTokens = p.fcmTokens[:0] + for token := range tokenMap { + p.fcmTokens = append(p.fcmTokens, token) } } func (p *PushOutput) processFcmNotifications(title, body string) { // Fetch new FCM tokens and add to p.fcmTokens - p.AddNewFcmTokens() + p.refreshFcmTokens() // If no FCM tokens exist, log and exit if len(p.fcmTokens) == 0 {