mirror of
https://github.com/status-im/status-go.git
synced 2025-01-11 15:14:52 +00:00
refactor(communities)_: expand channelEncrypted
usage
This commit is contained in:
parent
2bc2099d55
commit
89e7e7f24b
protocol/communities
@ -1670,7 +1670,7 @@ func (o *Community) marshaledDescription() ([]byte, error) {
|
|||||||
|
|
||||||
// This is only workaround to lower the size of the message that goes over the wire,
|
// This is only workaround to lower the size of the message that goes over the wire,
|
||||||
// see https://github.com/status-im/status-desktop/issues/12188
|
// see https://github.com/status-im/status-desktop/issues/12188
|
||||||
dehydrateChannelsMembers(o.IDString(), clone)
|
dehydrateChannelsMembers(clone)
|
||||||
|
|
||||||
if o.encryptor != nil {
|
if o.encryptor != nil {
|
||||||
err := encryptDescription(o.encryptor, o, clone)
|
err := encryptDescription(o.encryptor, o, clone)
|
||||||
@ -1717,28 +1717,19 @@ func (o *Community) ToProtocolMessageBytes() ([]byte, error) {
|
|||||||
return o.toProtocolMessageBytes()
|
return o.toProtocolMessageBytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
func channelHasTokenPermissions(communityID string, channelID string, permissions map[string]*protobuf.CommunityTokenPermission) bool {
|
func dehydrateChannelsMembers(description *protobuf.CommunityDescription) {
|
||||||
for _, tokenPermission := range permissions {
|
|
||||||
if includes(tokenPermission.ChatIds, communityID+channelID) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func dehydrateChannelsMembers(communityID string, description *protobuf.CommunityDescription) {
|
|
||||||
// To save space, we don't attach members for channels without permissions,
|
// To save space, we don't attach members for channels without permissions,
|
||||||
// otherwise the message will hit waku msg size limit.
|
// otherwise the message will hit waku msg size limit.
|
||||||
for channelID, channel := range description.Chats {
|
for channelID, channel := range description.Chats {
|
||||||
if !channelHasTokenPermissions(communityID, channelID, description.TokenPermissions) {
|
if !channelEncrypted(ChatID(description.ID, channelID), description.TokenPermissions) {
|
||||||
channel.Members = map[string]*protobuf.CommunityMember{} // clean members
|
channel.Members = map[string]*protobuf.CommunityMember{} // clean members
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func hydrateChannelsMembers(communityID string, description *protobuf.CommunityDescription) {
|
func hydrateChannelsMembers(description *protobuf.CommunityDescription) {
|
||||||
for channelID, channel := range description.Chats {
|
for channelID, channel := range description.Chats {
|
||||||
if !channelHasTokenPermissions(communityID, channelID, description.TokenPermissions) {
|
if !channelEncrypted(ChatID(description.ID, channelID), description.TokenPermissions) {
|
||||||
channel.Members = make(map[string]*protobuf.CommunityMember)
|
channel.Members = make(map[string]*protobuf.CommunityMember)
|
||||||
for pubKey, member := range description.Members {
|
for pubKey, member := range description.Members {
|
||||||
channel.Members[pubKey] = member
|
channel.Members[pubKey] = member
|
||||||
@ -1938,13 +1929,11 @@ func (o *Community) HasTokenPermissions() bool {
|
|||||||
return len(o.tokenPermissions()) > 0
|
return len(o.tokenPermissions()) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Community) channelEncrypted(channelID string) bool {
|
func channelEncrypted(chatID string, permissions map[string]*protobuf.CommunityTokenPermission) bool {
|
||||||
chatID := o.ChatID(channelID)
|
|
||||||
|
|
||||||
hasPermission := false
|
hasPermission := false
|
||||||
viewableByEveryone := false
|
viewableByEveryone := false
|
||||||
|
|
||||||
for _, p := range o.tokenPermissions() {
|
for _, p := range permissions {
|
||||||
if !includes(p.ChatIds, chatID) {
|
if !includes(p.ChatIds, chatID) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -1961,6 +1950,10 @@ func (o *Community) channelEncrypted(channelID string) bool {
|
|||||||
return hasPermission && !viewableByEveryone
|
return hasPermission && !viewableByEveryone
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *Community) channelEncrypted(channelID string) bool {
|
||||||
|
return channelEncrypted(o.ChatID(channelID), o.config.CommunityDescription.TokenPermissions)
|
||||||
|
}
|
||||||
|
|
||||||
func (o *Community) ChannelEncrypted(channelID string) bool {
|
func (o *Community) ChannelEncrypted(channelID string) bool {
|
||||||
o.mutex.Lock()
|
o.mutex.Lock()
|
||||||
defer o.mutex.Unlock()
|
defer o.mutex.Unlock()
|
||||||
@ -2432,8 +2425,12 @@ func (o *Community) populateChatWithAllMembers(chatID string) (*CommunityChanges
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ChatID(communityID, channelID string) string {
|
||||||
|
return communityID + channelID
|
||||||
|
}
|
||||||
|
|
||||||
func (o *Community) ChatID(channelID string) string {
|
func (o *Community) ChatID(channelID string) string {
|
||||||
return o.IDString() + channelID
|
return ChatID(o.IDString(), channelID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Community) ChatIDs() (chatIDs []string) {
|
func (o *Community) ChatIDs() (chatIDs []string) {
|
||||||
|
@ -2213,7 +2213,7 @@ func (m *Manager) preprocessDescription(id types.HexBytes, description *protobuf
|
|||||||
upgradeTokenPermissions(description)
|
upgradeTokenPermissions(description)
|
||||||
|
|
||||||
// Workaround for https://github.com/status-im/status-desktop/issues/12188
|
// Workaround for https://github.com/status-im/status-desktop/issues/12188
|
||||||
hydrateChannelsMembers(types.EncodeHex(id), description)
|
hydrateChannelsMembers(description)
|
||||||
|
|
||||||
return response, description, m.persistence.SaveDecryptedCommunityDescription(id, response, description)
|
return response, description, m.persistence.SaveDecryptedCommunityDescription(id, response, description)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user