Skip to content

Commit

Permalink
fix: derive community.Encrypted() from permissions (#4142)
Browse files Browse the repository at this point in the history
  • Loading branch information
osmaczko committed Oct 11, 2023
1 parent 5a4cc50 commit eed3212
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 69 deletions.
12 changes: 3 additions & 9 deletions protocol/communities/community.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (o *Community) MarshalPublicAPIJSON() ([]byte, error) {
Position: int(c.Position),
}
communityItem.Categories[id] = category
communityItem.Encrypted = o.config.CommunityDescription.Encrypted
communityItem.Encrypted = o.Encrypted()
}
for id, c := range o.config.CommunityDescription.Chats {
canPost, err := o.CanPost(o.config.MemberIdentity, id, nil)
Expand Down Expand Up @@ -260,7 +260,7 @@ func (o *Community) MarshalJSON() ([]byte, error) {
Name: c.Name,
Position: int(c.Position),
}
communityItem.Encrypted = o.config.CommunityDescription.Encrypted
communityItem.Encrypted = o.Encrypted()
communityItem.Categories[id] = category
}
for id, c := range o.config.CommunityDescription.Chats {
Expand Down Expand Up @@ -905,7 +905,7 @@ func (o *Community) Spectate() {
}

func (o *Community) Encrypted() bool {
return o.config.CommunityDescription.Encrypted
return len(o.TokenPermissionsByType(protobuf.CommunityTokenPermission_BECOME_MEMBER)) > 0
}

func (o *Community) Joined() bool {
Expand Down Expand Up @@ -1474,10 +1474,6 @@ func includes(channelIDs []string, channelID string) bool {
return false
}

func (o *Community) updateEncrypted() {
o.config.CommunityDescription.Encrypted = len(o.TokenPermissionsByType(protobuf.CommunityTokenPermission_BECOME_MEMBER)) > 0
}

func (o *Community) UpsertTokenPermission(tokenPermission *protobuf.CommunityTokenPermission) (*CommunityChanges, error) {
o.mutex.Lock()
defer o.mutex.Unlock()
Expand All @@ -1488,7 +1484,6 @@ func (o *Community) UpsertTokenPermission(tokenPermission *protobuf.CommunityTok
return nil, err
}

o.updateEncrypted()
o.increaseClock()

return changes, nil
Expand Down Expand Up @@ -1534,7 +1529,6 @@ func (o *Community) DeleteTokenPermission(permissionID string) (*CommunityChange
return nil, err
}

o.updateEncrypted()
o.increaseClock()

return changes, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func createTestCommunity(identity *ecdsa.PrivateKey) *Community {
Chats: map[string]*protobuf.CommunityChat{},
BanList: []string{},
Categories: map[string]*protobuf.CommunityCategory{},
Encrypted: false,
TokenPermissions: map[string]*protobuf.CommunityTokenPermission{},
CommunityTokensMetadata: []*protobuf.CommunityTokenMetadata{},
},
Expand Down
116 changes: 59 additions & 57 deletions protocol/protobuf/communities.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion protocol/protobuf/communities.proto
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ message CommunityDescription {
CommunityAdminSettings admin_settings = 10;
string intro_message = 11;
string outro_message = 12;
bool encrypted = 13;
bool encrypted = 13 [deprecated=true];
repeated string tags = 14;
map<string, CommunityTokenPermission> token_permissions = 15;
repeated CommunityTokenMetadata community_tokens_metadata = 16;
Expand Down
1 change: 0 additions & 1 deletion protocol/requests/create_community_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ func (c *CreateCommunity) ToCommunityDescription() (*protobuf.CommunityDescripti
},
IntroMessage: c.IntroMessage,
OutroMessage: c.OutroMessage,
Encrypted: false,
Tags: c.Tags,
}
return description, nil
Expand Down

0 comments on commit eed3212

Please sign in to comment.