diff --git a/VERSION b/VERSION index 4e4efce63..ade3f49f9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.154.2 +0.154.3 diff --git a/protocol/messenger_contacts.go b/protocol/messenger_contacts.go index b8cce9df8..618624047 100644 --- a/protocol/messenger_contacts.go +++ b/protocol/messenger_contacts.go @@ -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 diff --git a/protocol/messenger_test.go b/protocol/messenger_test.go index 9b7a8b851..b20fe888b 100644 --- a/protocol/messenger_test.go +++ b/protocol/messenger_test.go @@ -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) diff --git a/services/ext/api.go b/services/ext/api.go index d16e5f7a4..a55da1ae8 100644 --- a/services/ext/api.go +++ b/services/ext/api.go @@ -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) }