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.
This commit is contained in:
Andrea Maria Piana 2020-09-16 15:19:47 +02:00
parent 9e148eab89
commit a759d9dd67
1 changed files with 11 additions and 7 deletions

View File

@ -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
}