From f04e5c741cf02355f3faf55661d104aec63c4aa9 Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Mon, 25 Oct 2021 08:18:28 +0100 Subject: [PATCH] unblock contact endpoint --- VERSION | 2 +- protocol/messenger_contacts.go | 27 +++++++++++++++++++++++- protocol/messenger_installations_test.go | 2 +- services/ext/api.go | 8 +++++++ 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/VERSION b/VERSION index 78775e2f2..ae02209bb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.89.20 +0.90.0 diff --git a/protocol/messenger_contacts.go b/protocol/messenger_contacts.go index cfb6144e7..b46a36baa 100644 --- a/protocol/messenger_contacts.go +++ b/protocol/messenger_contacts.go @@ -204,7 +204,7 @@ func (m *Messenger) GetContactByID(pubKey string) *Contact { return contact } -func (m *Messenger) SetLocalNickname(pubKey string, nickname string) (*MessengerResponse, error) { +func (m *Messenger) SetContactLocalNickname(pubKey string, nickname string) (*MessengerResponse, error) { contact, ok := m.allContacts.Load(pubKey) if !ok { @@ -255,6 +255,31 @@ func (m *Messenger) BlockContact(contact *Contact) ([]*Chat, error) { return chats, nil } +func (m *Messenger) UnblockContact(contactID string) error { + contact, ok := m.allContacts.Load(contactID) + if !ok || !contact.Added { + return nil + } + + contact.Unblock() + contact.LastUpdatedLocally = m.getTimesource().GetCurrentTime() + + m.allContacts.Store(contact.ID, contact) + + err := m.syncContact(context.Background(), contact) + if err != nil { + return err + } + + // re-register for push notifications + err = m.reregisterForPushNotifications() + if err != nil { + return err + } + + return nil +} + // Send contact updates to all contacts added by us func (m *Messenger) SendContactUpdates(ctx context.Context, ensName, profileImage string) (err error) { myID := contactIDFromPublicKey(&m.identity.PublicKey) diff --git a/protocol/messenger_installations_test.go b/protocol/messenger_installations_test.go index 3cb6ff57b..5caf81628 100644 --- a/protocol/messenger_installations_test.go +++ b/protocol/messenger_installations_test.go @@ -147,7 +147,7 @@ func (s *MessengerInstallationSuite) TestSyncInstallation() { contact.LocalNickname = "Test Nickname" _, err = s.m.AddContact(context.Background(), contact.ID) s.Require().NoError(err) - _, err = s.m.SetLocalNickname(contact.ID, contact.LocalNickname) + _, err = s.m.SetContactLocalNickname(contact.ID, contact.LocalNickname) s.Require().NoError(err) // add chat diff --git a/services/ext/api.go b/services/ext/api.go index dee60de75..ed4319686 100644 --- a/services/ext/api.go +++ b/services/ext/api.go @@ -298,6 +298,10 @@ func (api *PublicAPI) BlockContact(parent context.Context, contact *protocol.Con return api.service.messenger.BlockContact(contact) } +func (api *PublicAPI) UnblockContact(parent context.Context, contactID string) error { + return api.service.messenger.UnblockContact(contactID) +} + func (api *PublicAPI) Contacts(parent context.Context) []*protocol.Contact { return api.service.messenger.Contacts() } @@ -592,6 +596,10 @@ func (api *PublicAPI) RemoveContact(ctx context.Context, pubKey string) (*protoc return api.service.messenger.RemoveContact(ctx, pubKey) } +func (api *PublicAPI) SetContactLocalNickname(ctx context.Context, pubKey, nickname string) (*protocol.MessengerResponse, error) { + return api.service.messenger.SetContactLocalNickname(pubKey, nickname) +} + func (api *PublicAPI) ClearHistory(request *requests.ClearHistory) (*protocol.MessengerResponse, error) { return api.service.messenger.ClearHistory(request) }