Register public and community chats for push notifications after creation
This commit is contained in:
parent
048511cc99
commit
8d7f26eb60
|
@ -4078,14 +4078,12 @@ func (m *Messenger) pushNotificationOptions() *pushnotificationclient.Registrati
|
||||||
if chat.Muted {
|
if chat.Muted {
|
||||||
mutedChatIDs = append(mutedChatIDs, chat.ID)
|
mutedChatIDs = append(mutedChatIDs, chat.ID)
|
||||||
}
|
}
|
||||||
if chat.Active && chat.Public() {
|
if chat.Active && (chat.Public() || chat.CommunityChat()) {
|
||||||
publicChatIDs = append(publicChatIDs, chat.ID)
|
publicChatIDs = append(publicChatIDs, chat.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
m.logger.Info("FOOBAR", zap.Any("pubchat", publicChatIDs))
|
|
||||||
return &pushnotificationclient.RegistrationOptions{
|
return &pushnotificationclient.RegistrationOptions{
|
||||||
ContactIDs: contactIDs,
|
ContactIDs: contactIDs,
|
||||||
MutedChatIDs: mutedChatIDs,
|
MutedChatIDs: mutedChatIDs,
|
||||||
|
|
|
@ -100,6 +100,11 @@ func (m *Messenger) CreatePublicChat(request *requests.CreatePublicChat) (*Messe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = m.reregisterForPushNotifications()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
response := &MessengerResponse{}
|
response := &MessengerResponse{}
|
||||||
response.AddChat(chat)
|
response.AddChat(chat)
|
||||||
|
|
||||||
|
@ -294,7 +299,7 @@ func (m *Messenger) saveChats(chats []*Chat) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) saveChat(chat *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() {
|
if chat.OneToOne() {
|
||||||
name, identicon, err := generateAliasAndIdenticon(chat.ID)
|
name, identicon, err := generateAliasAndIdenticon(chat.ID)
|
||||||
if err != nil {
|
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)
|
err := m.persistence.SaveChat(*chat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -324,14 +324,6 @@ func (m *Messenger) saveChat(chat *Chat) error {
|
||||||
// TODO(samyoul) remove storing of an updated reference pointer?
|
// TODO(samyoul) remove storing of an updated reference pointer?
|
||||||
m.allChats.Store(chat.ID, chat)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -456,7 +456,17 @@ func (m *Messenger) CreateCommunityChat(communityID types.HexBytes, c *protobuf.
|
||||||
return nil, err
|
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) {
|
func (m *Messenger) EditCommunityChat(communityID types.HexBytes, chatID string, c *protobuf.CommunityChat) (*MessengerResponse, error) {
|
||||||
|
|
Loading…
Reference in New Issue