Register public and community chats for push notifications after creation

This commit is contained in:
Roman Volosovskyi 2021-09-01 12:03:45 +03:00
parent 048511cc99
commit 8d7f26eb60
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
4 changed files with 19 additions and 19 deletions

View File

@ -1 +1 @@
0.85.0
0.85.1

View File

@ -4078,14 +4078,12 @@ func (m *Messenger) pushNotificationOptions() *pushnotificationclient.Registrati
if chat.Muted {
mutedChatIDs = append(mutedChatIDs, chat.ID)
}
if chat.Active && chat.Public() {
if chat.Active && (chat.Public() || chat.CommunityChat()) {
publicChatIDs = append(publicChatIDs, chat.ID)
}
return true
})
m.logger.Info("FOOBAR", zap.Any("pubchat", publicChatIDs))
return &pushnotificationclient.RegistrationOptions{
ContactIDs: contactIDs,
MutedChatIDs: mutedChatIDs,

View File

@ -100,6 +100,11 @@ func (m *Messenger) CreatePublicChat(request *requests.CreatePublicChat) (*Messe
}
}
err = m.reregisterForPushNotifications()
if err != nil {
return nil, err
}
response := &MessengerResponse{}
response.AddChat(chat)
@ -294,7 +299,7 @@ func (m *Messenger) saveChats(chats []*Chat) error {
}
func (m *Messenger) saveChat(chat *Chat) error {
previousChat, ok := m.allChats.Load(chat.ID)
_, ok := m.allChats.Load(chat.ID)
if chat.OneToOne() {
name, identicon, err := generateAliasAndIdenticon(chat.ID)
if err != nil {
@ -312,11 +317,6 @@ func (m *Messenger) saveChat(chat *Chat) error {
}
}
// We check if it's a new chat, or chat.Active has changed
// 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 {
return err
@ -324,14 +324,6 @@ func (m *Messenger) saveChat(chat *Chat) error {
// TODO(samyoul) remove storing of an updated reference pointer?
m.allChats.Store(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
}

View File

@ -456,7 +456,17 @@ func (m *Messenger) CreateCommunityChat(communityID types.HexBytes, c *protobuf.
return nil, err
}
return &response, m.saveChats(chats)
err = m.saveChats(chats)
if err != nil {
return nil, err
}
err = m.reregisterForPushNotifications()
if err != nil {
return nil, err
}
return &response, nil
}
func (m *Messenger) EditCommunityChat(communityID types.HexBytes, chatID string, c *protobuf.CommunityChat) (*MessengerResponse, error) {