fix(contacts): add contact to ban and unban responses (#3558)

This commit is contained in:
Jonathan Rainville 2023-06-01 13:26:12 -04:00 committed by GitHub
parent af1327f95d
commit 3f00869e1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 20 deletions

View File

@ -1 +1 @@
0.154.2
0.154.3

View File

@ -642,15 +642,15 @@ func (m *Messenger) SetContactLocalNickname(request *requests.SetContactLocalNic
return response, nil
}
func (m *Messenger) blockContact(contactID string, isDesktopFunc bool) ([]*Chat, error) {
func (m *Messenger) blockContact(contactID string, isDesktopFunc bool) (*Contact, []*Chat, error) {
contact, err := m.BuildContact(&requests.BuildContact{PublicKey: contactID})
if err != nil {
return nil, err
return nil, nil, err
}
_, clock, err := m.getOneToOneAndNextClock(contact)
if err != nil {
return nil, err
return nil, nil, err
}
contact.Block(clock)
@ -659,12 +659,12 @@ func (m *Messenger) blockContact(contactID string, isDesktopFunc bool) ([]*Chat,
chats, err := m.persistence.BlockContact(contact, isDesktopFunc)
if err != nil {
return nil, err
return nil, nil, err
}
err = m.sendRetractContactRequest(contact)
if err != nil {
return nil, err
return nil, nil, err
}
m.allContacts.Store(contact.ID, contact)
@ -679,26 +679,27 @@ func (m *Messenger) blockContact(contactID string, isDesktopFunc bool) ([]*Chat,
err = m.syncContact(context.Background(), contact, m.dispatchMessage)
if err != nil {
return nil, err
return nil, nil, err
}
// re-register for push notifications
err = m.reregisterForPushNotifications()
if err != nil {
return nil, err
return nil, nil, err
}
return chats, nil
return contact, chats, nil
}
func (m *Messenger) BlockContact(contactID string) (*MessengerResponse, error) {
response := &MessengerResponse{}
chats, err := m.blockContact(contactID, false)
contact, chats, err := m.blockContact(contactID, false)
if err != nil {
return nil, err
}
response.AddChats(chats)
response.AddContact(contact)
response, err = m.DeclineAllPendingGroupInvitesFromUser(response, contactID)
if err != nil {
@ -717,11 +718,12 @@ func (m *Messenger) BlockContact(contactID string) (*MessengerResponse, error) {
func (m *Messenger) BlockContactDesktop(contactID string) (*MessengerResponse, error) {
response := &MessengerResponse{}
chats, err := m.blockContact(contactID, true)
contact, chats, err := m.blockContact(contactID, true)
if err != nil {
return nil, err
}
response.AddChats(chats)
response.AddContact(contact)
response, err = m.DeclineAllPendingGroupInvitesFromUser(response, contactID)
if err != nil {
@ -736,15 +738,16 @@ func (m *Messenger) BlockContactDesktop(contactID string) (*MessengerResponse, e
return response, nil
}
func (m *Messenger) UnblockContact(contactID string) error {
func (m *Messenger) UnblockContact(contactID string) (*MessengerResponse, error) {
response := &MessengerResponse{}
contact, ok := m.allContacts.Load(contactID)
if !ok || !contact.Blocked {
return nil
return response, nil
}
_, clock, err := m.getOneToOneAndNextClock(contact)
if err != nil {
return err
return nil, err
}
contact.Unblock(clock)
@ -753,23 +756,25 @@ func (m *Messenger) UnblockContact(contactID string) error {
err = m.persistence.SaveContact(contact, nil)
if err != nil {
return err
return nil, err
}
m.allContacts.Store(contact.ID, contact)
response.AddContact(contact)
err = m.syncContact(context.Background(), contact, m.dispatchMessage)
if err != nil {
return err
return nil, err
}
// re-register for push notifications
err = m.reregisterForPushNotifications()
if err != nil {
return err
return nil, err
}
return nil
return response, nil
}
// Send contact updates to all contacts added by us

View File

@ -651,8 +651,11 @@ func (s *MessengerSuite) TestRetrieveBlockedContact() {
requireMessageArrival(theirMessenger, true)
// Unblock contact
err = s.m.UnblockContact(blockedContact.ID)
response, err := s.m.UnblockContact(blockedContact.ID)
s.Require().NoError(err)
s.Require().NotNil(response)
s.Require().Equal(false, response.Contacts[0].Blocked)
s.Require().Equal(true, response.Contacts[0].Removed)
// Unblocked contact sends message, we should receive it
_, err = theirMessenger.SendChatMessage(context.Background(), theirMessage)

View File

@ -327,7 +327,7 @@ func (api *PublicAPI) BlockContactDesktop(parent context.Context, contactID stri
return api.service.messenger.BlockContactDesktop(contactID)
}
func (api *PublicAPI) UnblockContact(parent context.Context, contactID string) error {
func (api *PublicAPI) UnblockContact(parent context.Context, contactID string) (*protocol.MessengerResponse, error) {
return api.service.messenger.UnblockContact(contactID)
}