From f1569e4bde50e993611288a59b7a415a010cbfa8 Mon Sep 17 00:00:00 2001 From: Parvesh Monu Date: Mon, 10 Jan 2022 17:34:52 +0530 Subject: [PATCH] fix membership requests on synced devices (#2477) --- VERSION | 2 +- protocol/messenger_communities.go | 41 +++++++++++++++++-------------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/VERSION b/VERSION index 1375263c2..0ca871819 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.92.6 +0.92.7 diff --git a/protocol/messenger_communities.go b/protocol/messenger_communities.go index 58aa89e12..5479baa04 100644 --- a/protocol/messenger_communities.go +++ b/protocol/messenger_communities.go @@ -174,6 +174,15 @@ func (m *Messenger) joinCommunity(ctx context.Context, communityID types.HexByte return nil, err } + if community.IsAdmin() { + // Init the community filter so we can receive messages on the community + communityFilters, err := m.transport.InitCommunityFilters([]*ecdsa.PrivateKey{community.PrivateKey()}) + if err != nil { + return nil, err + } + filters = append(filters, communityFilters...) + } + willSync, err := m.scheduleSyncFilters(filters) if err != nil { logger.Debug("m.scheduleSyncFilters error", zap.Error(err)) @@ -990,6 +999,20 @@ func (m *Messenger) handleSyncCommunity(messageState *ReceivedMessageState, sync return err } + // associate private key with community if set + if syncCommunity.PrivateKey != nil { + orgPrivKey, err := crypto.ToECDSA(syncCommunity.PrivateKey) + if err != nil { + logger.Debug("crypto.ToECDSA", zap.Error(err)) + return err + } + err = m.communitiesManager.SetPrivateKey(syncCommunity.Id, orgPrivKey) + if err != nil { + logger.Debug("m.communitiesManager.SetPrivateKey", zap.Error(err)) + return err + } + } + // if we are not waiting for approval, join or leave the community if !pending { var mr *MessengerResponse @@ -1020,23 +1043,5 @@ func (m *Messenger) handleSyncCommunity(messageState *ReceivedMessageState, sync return err } - // associate private key with community if set - if syncCommunity.PrivateKey == nil { - logger.Debug("syncCommunity.PrivateKey is nil") - return nil - } - logger.Debug("syncCommunity.PrivateKey is not nil") - - orgPrivKey, err := crypto.ToECDSA(syncCommunity.PrivateKey) - if err != nil { - logger.Debug("crypto.ToECDSA", zap.Error(err)) - return err - } - err = m.communitiesManager.SetPrivateKey(syncCommunity.Id, orgPrivKey) - if err != nil { - logger.Debug("m.communitiesManager.SetPrivateKey", zap.Error(err)) - return err - } - return nil }