fix: don't unsubscribe from community when kicked

There's two scenarios in which we're leaving a community:
We either get kicked or we leave ourselves.

In case of leaving ourselves it's fine to unsubscribe from further
community updates be cause we deliberately chose to leave.

In case of being kicked however, this is different.
Say I'm kicked from a community because its token permissions have
changed, in this case we don't want clients to manually re-subscribe to
the community to get informed when there were further changes.
status-go should rather not unsubscribe if we know for sure we've been
kicked by someone else.
This commit is contained in:
Pascal Precht 2023-06-07 15:23:51 +02:00 committed by Follow the white rabbit
parent 87ce6cfbcd
commit 511faad0ec
2 changed files with 14 additions and 8 deletions

View File

@ -4359,9 +4359,13 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
} }
} else if changes.ShouldMemberLeave { } else if changes.ShouldMemberLeave {
response, err := m.leaveCommunity(changes.Community.ID()) // this means we've been kicked by the community owner/admin,
// in this case we don't want to unsubscribe from community updates
// so we still get notified accordingly when something changes,
// hence, we're setting `unsubscribeFromCommunity` to `false` here
response, err := m.leaveCommunity(changes.Community.ID(), false)
if err != nil { if err != nil {
logger.Error("cannot join community", zap.Error(err)) logger.Error("cannot leave community", zap.Error(err))
continue continue
} }

View File

@ -980,7 +980,7 @@ func (m *Messenger) LeaveCommunity(communityID types.HexBytes) (*MessengerRespon
return nil, err return nil, err
} }
mr, err := m.leaveCommunity(communityID) mr, err := m.leaveCommunity(communityID, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1036,7 +1036,7 @@ func (m *Messenger) LeaveCommunity(communityID types.HexBytes) (*MessengerRespon
return mr, nil return mr, nil
} }
func (m *Messenger) leaveCommunity(communityID types.HexBytes) (*MessengerResponse, error) { func (m *Messenger) leaveCommunity(communityID types.HexBytes, unsubsribeFromCommunity bool) (*MessengerResponse, error) {
response := &MessengerResponse{} response := &MessengerResponse{}
community, err := m.communitiesManager.LeaveCommunity(communityID) community, err := m.communitiesManager.LeaveCommunity(communityID)
@ -1059,9 +1059,11 @@ func (m *Messenger) leaveCommunity(communityID types.HexBytes) (*MessengerRespon
} }
} }
_, err = m.transport.RemoveFilterByChatID(communityID.String()) if unsubsribeFromCommunity {
if err != nil { _, err = m.transport.RemoveFilterByChatID(communityID.String())
return nil, err if err != nil {
return nil, err
}
} }
response.AddCommunity(community) response.AddCommunity(community)
@ -2143,7 +2145,7 @@ func (m *Messenger) handleSyncCommunity(messageState *ReceivedMessageState, sync
return err return err
} }
} else { } else {
mr, err = m.leaveCommunity(syncCommunity.Id) mr, err = m.leaveCommunity(syncCommunity.Id, true)
if err != nil { if err != nil {
logger.Debug("m.leaveCommunity error", zap.Error(err)) logger.Debug("m.leaveCommunity error", zap.Error(err))
return err return err