From d942ad1a1f6aeb2f1285d1fb444a344d6a89b4bb Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Tue, 25 Jun 2024 14:46:29 -0400 Subject: [PATCH] fix(manager)_: make sure createCommunityPermission schedules the reeval (#5404) Fixes https://github.com/status-im/status-desktop/issues/15175 The problem was that we used StartMembersReevaluaitonLoop in createCommunityPermission, in case the loop was never started. Indeed it worked if it was the first ever permission, because the loop would then start and members would be re-evaluated. However, if the loop was already started, in the case where there were previous permissions, the call would just early exit, because it was already started. The solution here is to use `ScheduleMembersReevaluaiton` like other permission functions use. To make sure a first permission still works, we call startLoop in schedule if the task doesn't exist. --- protocol/communities/manager.go | 4 +++- protocol/messenger_communities.go | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/protocol/communities/manager.go b/protocol/communities/manager.go index 3cac3ab86..35dd66ecb 100644 --- a/protocol/communities/manager.go +++ b/protocol/communities/manager.go @@ -1449,7 +1449,9 @@ func (m *Manager) ScheduleMembersReevaluation(communityID types.HexBytes) error func (m *Manager) scheduleMembersReevaluation(communityID types.HexBytes, forceImmediateReevaluation bool) error { t, exists := m.membersReevaluationTasks.Load(communityID.String()) if !exists { - return errors.New("reevaluation task doesn't exist") + // No reevaluation task yet. We start the loop which will create it + m.StartMembersReevaluationLoop(communityID, true) + return nil } task, ok := t.(*membersReevaluationTask) diff --git a/protocol/messenger_communities.go b/protocol/messenger_communities.go index 2f77b4f9d..f012fc082 100644 --- a/protocol/messenger_communities.go +++ b/protocol/messenger_communities.go @@ -2739,7 +2739,10 @@ func (m *Messenger) CreateCommunityTokenPermission(request *requests.CreateCommu } if community.IsControlNode() { - m.communitiesManager.StartMembersReevaluationLoop(community.ID(), true) + err = m.communitiesManager.ScheduleMembersReevaluation(community.ID()) + if err != nil { + return nil, err + } } // ensure HRkeys are synced