Skip to content

Commit 22ed41a

Browse files
committed
fix: update refreshing FCM tokens
Signed-off-by: Ales Verbic <[email protected]>
1 parent cda0ca8 commit 22ed41a

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

output/push/push.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -188,25 +188,19 @@ func (p *PushOutput) Start() error {
188188
return nil
189189
}
190190

191-
// AddNewFcmTokens adds only the new FCM tokens to the fcmTokens slice
192-
func (p *PushOutput) AddNewFcmTokens() {
191+
// refreshFcmTokens adds only the new FCM tokens to the fcmTokens slice
192+
func (p *PushOutput) refreshFcmTokens() {
193193
tokenMap := GetFcmTokens()
194-
existingTokens := make(map[string]bool, len(p.fcmTokens))
195194

196-
for _, token := range p.fcmTokens {
197-
existingTokens[token] = true
198-
}
199-
200-
for _, newToken := range tokenMap {
201-
if _, exists := existingTokens[newToken]; !exists {
202-
p.fcmTokens = append(p.fcmTokens, newToken)
203-
}
195+
p.fcmTokens = p.fcmTokens[:0]
196+
for token := range tokenMap {
197+
p.fcmTokens = append(p.fcmTokens, token)
204198
}
205199
}
206200

207201
func (p *PushOutput) processFcmNotifications(title, body string) {
208202
// Fetch new FCM tokens and add to p.fcmTokens
209-
p.AddNewFcmTokens()
203+
p.refreshFcmTokens()
210204

211205
// If no FCM tokens exist, log and exit
212206
if len(p.fcmTokens) == 0 {

0 commit comments

Comments
 (0)