Decline pending group invites from user, when user is blocked (#2455)
This commit is contained in:
parent
258cbb694f
commit
83c3849899
|
@ -366,6 +366,11 @@ func (db sqlitePersistence) DismissAllActivityCenterNotifications() error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (db sqlitePersistence) DismissAllActivityCenterNotificationsFromUser(userPublicKey string) error {
|
||||
_, err := db.db.Exec(`UPDATE activity_center_notifications SET dismissed = 1 WHERE NOT dismissed AND NOT accepted AND author = ?`, userPublicKey)
|
||||
return err
|
||||
}
|
||||
|
||||
func (db sqlitePersistence) DismissActivityCenterNotifications(ids []types.HexBytes) error {
|
||||
|
||||
idsArgs := make([]interface{}, 0, len(ids))
|
||||
|
|
|
@ -319,7 +319,7 @@ func (m *Messenger) SetContactLocalNickname(request *requests.SetContactLocalNic
|
|||
return response, nil
|
||||
}
|
||||
|
||||
func (m *Messenger) BlockContact(contactID string) ([]*Chat, error) {
|
||||
func (m *Messenger) blockContact(contactID string) ([]*Chat, error) {
|
||||
contact, ok := m.allContacts.Load(contactID)
|
||||
if !ok {
|
||||
var err error
|
||||
|
@ -358,6 +358,28 @@ func (m *Messenger) BlockContact(contactID string) ([]*Chat, error) {
|
|||
return chats, nil
|
||||
}
|
||||
|
||||
func (m *Messenger) BlockContact(contactID string) (*MessengerResponse, error) {
|
||||
response := &MessengerResponse{}
|
||||
|
||||
chats, err := m.blockContact(contactID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response.AddChats(chats)
|
||||
|
||||
response, err = m.DeclineAllPendingGroupInvitesFromUser(response, contactID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = m.persistence.DismissAllActivityCenterNotificationsFromUser(contactID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (m *Messenger) UnblockContact(contactID string) error {
|
||||
contact, ok := m.allContacts.Load(contactID)
|
||||
if !ok || !contact.Blocked {
|
||||
|
|
|
@ -365,11 +365,14 @@ func (m *Messenger) HandleSyncInstallationContact(state *ReceivedMessageState, m
|
|||
if message.Blocked != contact.Blocked {
|
||||
if message.Blocked {
|
||||
state.AllContacts.Store(contact.ID, contact)
|
||||
chats, err := m.BlockContact(contact.ID)
|
||||
response, err := m.BlockContact(contact.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = state.Response.Merge(response)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
state.Response.AddChats(chats)
|
||||
} else {
|
||||
contact.Unblock()
|
||||
}
|
||||
|
|
|
@ -1433,14 +1433,15 @@ func (s *MessengerSuite) TestBlockContact() {
|
|||
s.Require().NoError(err)
|
||||
|
||||
response, err := s.m.BlockContact(contact.ID)
|
||||
chats := response.Chats()
|
||||
s.Require().NoError(err)
|
||||
|
||||
var actualChat2, actualChat3 *Chat
|
||||
for idx := range response {
|
||||
if response[idx].ID == chat2.ID {
|
||||
actualChat2 = response[idx]
|
||||
} else if response[idx].ID == chat3.ID {
|
||||
actualChat3 = response[idx]
|
||||
for idx := range chats {
|
||||
if chats[idx].ID == chat2.ID {
|
||||
actualChat2 = chats[idx]
|
||||
} else if chats[idx].ID == chat3.ID {
|
||||
actualChat3 = chats[idx]
|
||||
}
|
||||
}
|
||||
// The new unviewed count is updated
|
||||
|
|
|
@ -293,7 +293,7 @@ func (api *PublicAPI) UnmuteChat(parent context.Context, chatID string) error {
|
|||
return api.service.messenger.UnmuteChat(chatID)
|
||||
}
|
||||
|
||||
func (api *PublicAPI) BlockContact(parent context.Context, contactID string) ([]*protocol.Chat, error) {
|
||||
func (api *PublicAPI) BlockContact(parent context.Context, contactID string) (*protocol.MessengerResponse, error) {
|
||||
api.log.Info("blocking contact", "contact", contactID)
|
||||
return api.service.messenger.BlockContact(contactID)
|
||||
}
|
||||
|
|
|
@ -428,7 +428,7 @@ func (api *NimbusPublicAPI) SaveContact(parent context.Context, contact *protoco
|
|||
return api.service.messenger.SaveContact(contact)
|
||||
}
|
||||
|
||||
func (api *NimbusPublicAPI) BlockContact(parent context.Context, contact *protocol.Contact) ([]*protocol.Chat, error) {
|
||||
func (api *NimbusPublicAPI) BlockContact(parent context.Context, contact *protocol.Contact) (*protocol.MessengerResponse, error) {
|
||||
api.log.Info("blocking contact", "contact", contact.ID)
|
||||
return api.service.messenger.BlockContact(contact)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue