diff --git a/protocol/communities/manager.go b/protocol/communities/manager.go index 0643d5d74..8260eca72 100644 --- a/protocol/communities/manager.go +++ b/protocol/communities/manager.go @@ -4879,12 +4879,7 @@ func (m *Manager) createCommunityTokenPermission(request *requests.CreateCommuni } -func (m *Manager) PromoteSelfToControlNode(communityID types.HexBytes, clock uint64) (*CommunityChanges, error) { - community, err := m.GetByID(communityID) - if err != nil { - return nil, err - } - +func (m *Manager) PromoteSelfToControlNode(community *Community, clock uint64) (*CommunityChanges, error) { if community == nil { return nil, ErrOrgNotFound } @@ -4921,7 +4916,23 @@ func (m *Manager) promoteSelfToControlNode(community *Community, clock uint64) ( } community.config.ControlDevice = true - _, err = community.AddRoleToMember(&m.identity.PublicKey, protobuf.CommunityMember_ROLE_OWNER) + if exists := community.HasMember(&m.identity.PublicKey); !exists { + ownerRole := []protobuf.CommunityMember_Roles{protobuf.CommunityMember_ROLE_OWNER} + _, err = community.AddMember(&m.identity.PublicKey, ownerRole) + if err != nil { + return false, err + } + + for channelID := range community.Chats() { + _, err = community.AddMemberToChat(channelID, &m.identity.PublicKey, ownerRole) + if err != nil { + return false, err + } + } + } else { + _, err = community.AddRoleToMember(&m.identity.PublicKey, protobuf.CommunityMember_ROLE_OWNER) + } + if err != nil { return false, err } diff --git a/protocol/messenger_communities.go b/protocol/messenger_communities.go index f9cf8928f..c09d5cc1c 100644 --- a/protocol/messenger_communities.go +++ b/protocol/messenger_communities.go @@ -44,7 +44,6 @@ import ( localnotifications "github.com/status-im/status-go/services/local-notifications" "github.com/status-im/status-go/services/wallet/bigint" "github.com/status-im/status-go/signal" - "github.com/status-im/status-go/transactions" ) // 7 days interval @@ -6053,17 +6052,21 @@ func (m *Messenger) processCommunityChanges(messageState *ReceivedMessageState) messageState.Response.CommunityChanges = nil } -func (m *Messenger) SetCommunitySignerPubKey(ctx context.Context, communityID []byte, chainID uint64, contractAddress string, txArgs transactions.SendTxArgs, password string, newSignerPubKey string) (string, error) { - if m.communityTokensService == nil { - return "", errors.New("tokens service not initialized") - } - - return m.communityTokensService.SetSignerPubKey(ctx, chainID, contractAddress, txArgs, password, newSignerPubKey) -} - func (m *Messenger) PromoteSelfToControlNode(communityID types.HexBytes) (*MessengerResponse, error) { clock, _ := m.getLastClockWithRelatedChat() - changes, err := m.communitiesManager.PromoteSelfToControlNode(communityID, clock) + + community, err := m.FetchCommunity(&FetchCommunityRequest{ + CommunityKey: types.EncodeHex(communityID), + Shard: nil, + TryDatabase: true, + WaitForResponse: true, + }) + + if err != nil { + return nil, err + } + + changes, err := m.communitiesManager.PromoteSelfToControlNode(community, clock) if err != nil { return nil, err }