Remove filters

This commit is contained in:
Andrea Maria Piana 2020-12-22 18:12:03 +01:00
parent 06dcf0cea9
commit f5482ec187
8 changed files with 27 additions and 13 deletions

View File

@ -43,7 +43,6 @@ func (p *Persistence) queryCommunities(query string) (response []*Community, err
}
err = rows.Close()
return
}()
for rows.Next() {

View File

@ -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))
}

View File

@ -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
}

View File

@ -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 {

View File

@ -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.

View File

@ -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)

View File

@ -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)
}

View File

@ -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)
}