From a759d9dd676e680bafd3f25c693a61605b39b7a2 Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Wed, 16 Sep 2020 15:19:47 +0200 Subject: [PATCH] Fix push notification & mentions The code had an issue where it would not register a chat if just joined as re-register push notifications was called before the chat had been added. This commit fixes the behavior by making sure that the chat just joined is included. --- protocol/messenger.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/protocol/messenger.go b/protocol/messenger.go index e8cc759c1..6a0bc753d 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -1377,13 +1377,9 @@ func (m *Messenger) saveChat(chat *Chat) error { } // We check if it's a new chat, or chat.Active has changed - if chat.Public() && (!ok && chat.Active) || (ok && chat.Active != previousChat.Active) { - // Re-register for push notifications, as we want to receive mentions - if err := m.reregisterForPushNotifications(); err != nil { - return err - } - - } + // we check here, but we only re-register once the chat has been + // saved an added + shouldRegisterForPushNotifications := chat.Public() && (!ok && chat.Active) || (ok && chat.Active != previousChat.Active) err := m.persistence.SaveChat(*chat) if err != nil { @@ -1391,6 +1387,14 @@ func (m *Messenger) saveChat(chat *Chat) error { } m.allChats[chat.ID] = chat + if shouldRegisterForPushNotifications { + // Re-register for push notifications, as we want to receive mentions + if err := m.reregisterForPushNotifications(); err != nil { + return err + } + + } + return nil }