From f5482ec187b981dd77d184cc7003dcc0c6ae5d22 Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Tue, 22 Dec 2020 18:12:03 +0100 Subject: [PATCH] Remove filters --- protocol/communities/persistence.go | 1 - protocol/communities_messenger_test.go | 2 -- protocol/messenger.go | 18 +++++++++++++++--- protocol/messenger_response.go | 2 +- protocol/transport/filters_manager.go | 11 ++++++++--- protocol/transport/transport.go | 2 +- protocol/transport/waku/waku_service.go | 2 +- protocol/transport/whisper/whisper_service.go | 2 +- 8 files changed, 27 insertions(+), 13 deletions(-) diff --git a/protocol/communities/persistence.go b/protocol/communities/persistence.go index 91d6ee18e..6eefd63c5 100644 --- a/protocol/communities/persistence.go +++ b/protocol/communities/persistence.go @@ -43,7 +43,6 @@ func (p *Persistence) queryCommunities(query string) (response []*Community, err } err = rows.Close() - return }() for rows.Next() { diff --git a/protocol/communities_messenger_test.go b/protocol/communities_messenger_test.go index f6543b537..6eb6bd18e 100644 --- a/protocol/communities_messenger_test.go +++ b/protocol/communities_messenger_test.go @@ -77,7 +77,6 @@ func (s *MessengerCommunitiesSuite) newMessengerWithKey(shh types.Waku, privateK options := []Option{ WithCustomLogger(s.logger), - WithMessagesPersistenceEnabled(), WithDatabaseConfig(tmpFile.Name(), ""), WithDatasync(), } @@ -510,5 +509,4 @@ func (s *MessengerCommunitiesSuite) TestImportCommunity() { community = response.Communities[0] s.Require().True(community.Joined()) s.Require().True(community.IsAdmin()) - s.Require().True(community.HasMember(&newUser.PublicKey)) } diff --git a/protocol/messenger.go b/protocol/messenger.go index cfec76d49..aefb145a5 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -1956,14 +1956,26 @@ func (m *Messenger) LeaveCommunity(communityID string) (*MessengerResponse, erro return nil, err } response.RemovedChats = append(response.RemovedChats, orgChatID) - response.RemovedFilters = append(response.RemovedFilters, orgChatID) + + filter, err := m.transport.RemoveFilterByChatID(orgChatID) + if err != nil { + return nil, err + } + + if filter != nil { + response.RemovedFilters = append(response.RemovedFilters, filter) + } } - err = m.transport.RemoveFilterByChatID(communityID) + filter, err := m.transport.RemoveFilterByChatID(communityID) if err != nil { return nil, err } - response.RemovedFilters = append(response.RemovedFilters, communityID) + + if filter != nil { + response.RemovedFilters = append(response.RemovedFilters, filter) + } + response.Communities = []*communities.Community{org} return response, nil } diff --git a/protocol/messenger_response.go b/protocol/messenger_response.go index 5681c3b23..33c3e92c5 100644 --- a/protocol/messenger_response.go +++ b/protocol/messenger_response.go @@ -18,7 +18,7 @@ type MessengerResponse struct { Communities []*communities.Community `json:"communities,omitempty"` CommunityChanges []*communities.CommunityChanges `json:"communitiesChanges,omitempty"` Filters []*transport.Filter `json:"filters,omitempty"` - RemovedFilters []string `json:"removedFilters,omitempty"` + RemovedFilters []*transport.Filter `json:"removedFilters,omitempty"` } func (m *MessengerResponse) IsEmpty() bool { diff --git a/protocol/transport/filters_manager.go b/protocol/transport/filters_manager.go index 7f849e1ec..a85c6cce0 100644 --- a/protocol/transport/filters_manager.go +++ b/protocol/transport/filters_manager.go @@ -231,16 +231,21 @@ func (s *FiltersManager) Remove(filters ...*Filter) error { } // Remove remove all the filters associated with a chat/identity -func (s *FiltersManager) RemoveFilterByChatID(chatID string) error { +func (s *FiltersManager) RemoveFilterByChatID(chatID string) (*Filter, error) { s.mutex.Lock() filter, ok := s.filters[chatID] s.mutex.Unlock() if !ok { - return nil + return nil, nil } - return s.Remove(filter) + err := s.Remove(filter) + if err != nil { + return nil, err + } + + return filter, nil } // LoadPartitioned creates a filter for a partitioned topic. diff --git a/protocol/transport/transport.go b/protocol/transport/transport.go index c0b62209d..2e6366e05 100644 --- a/protocol/transport/transport.go +++ b/protocol/transport/transport.go @@ -35,7 +35,7 @@ type Transport interface { InitPublicFilters(chatIDs []string) ([]*Filter, error) LoadFilters(filters []*Filter) ([]*Filter, error) RemoveFilters(filters []*Filter) error - RemoveFilterByChatID(string) error + RemoveFilterByChatID(string) (*Filter, error) ResetFilters() error Filters() []*Filter LoadKeyFilters(*ecdsa.PrivateKey) (*Filter, error) diff --git a/protocol/transport/waku/waku_service.go b/protocol/transport/waku/waku_service.go index e3da55ab6..517b67976 100644 --- a/protocol/transport/waku/waku_service.go +++ b/protocol/transport/waku/waku_service.go @@ -143,7 +143,7 @@ func (a *Transport) RemoveFilters(filters []*transport.Filter) error { return a.filters.Remove(filters...) } -func (a *Transport) RemoveFilterByChatID(chatID string) error { +func (a *Transport) RemoveFilterByChatID(chatID string) (*transport.Filter, error) { return a.filters.RemoveFilterByChatID(chatID) } diff --git a/protocol/transport/whisper/whisper_service.go b/protocol/transport/whisper/whisper_service.go index 00a9e4586..b163ae107 100644 --- a/protocol/transport/whisper/whisper_service.go +++ b/protocol/transport/whisper/whisper_service.go @@ -143,7 +143,7 @@ func (a *Transport) RemoveFilters(filters []*transport.Filter) error { return a.filters.Remove(filters...) } -func (a *Transport) RemoveFilterByChatID(chatID string) error { +func (a *Transport) RemoveFilterByChatID(chatID string) (*transport.Filter, error) { return a.filters.RemoveFilterByChatID(chatID) }