From 9dea0aaee3ce0ebb29c6898c771a383dfbd6bb52 Mon Sep 17 00:00:00 2001 From: John Ngei Date: Thu, 20 Apr 2023 13:52:08 +0300 Subject: [PATCH] Remove contact from the contact list of contacts the blocked contact * Remove contact from the user's list of contacts when the contact is blocked by the user * added test for removed blocked contact --- VERSION | 2 +- protocol/contact.go | 1 + protocol/messenger_contacts.go | 5 +++++ protocol/messenger_test.go | 3 +++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index d6dd27387..b4416c95b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.146.2 +0.146.3 diff --git a/protocol/contact.go b/protocol/contact.go index de9ddea1b..bb50e1c50 100644 --- a/protocol/contact.go +++ b/protocol/contact.go @@ -155,6 +155,7 @@ func (c Contact) PublicKey() (*ecdsa.PublicKey, error) { func (c *Contact) Block(clock uint64) { c.Blocked = true c.DismissContactRequest(clock) + c.Removed = true } func (c *Contact) BlockDesktop() { diff --git a/protocol/messenger_contacts.go b/protocol/messenger_contacts.go index c05ba5320..63528ff3d 100644 --- a/protocol/messenger_contacts.go +++ b/protocol/messenger_contacts.go @@ -669,6 +669,11 @@ func (m *Messenger) blockContact(contactID string, isDesktopFunc bool) ([]*Chat, return nil, err } + err = m.sendRetractContactRequest(contact) + if err != nil { + return nil, err + } + m.allContacts.Store(contact.ID, contact) for _, chat := range chats { m.allChats.Store(chat.ID, chat) diff --git a/protocol/messenger_test.go b/protocol/messenger_test.go index 997d0bd35..4b904bf6e 100644 --- a/protocol/messenger_test.go +++ b/protocol/messenger_test.go @@ -1378,6 +1378,9 @@ func (s *MessengerSuite) TestBlockContact() { response, err := s.m.BlockContact(contact.ID) s.Require().NoError(err) + blockedContacts := s.m.BlockedContacts() + s.Require().True(blockedContacts[0].Removed) + chats := response.Chats() var actualChat2, actualChat3 *Chat