chore: add `CommunityID` to `ProtectedTopic`

This commit is contained in:
Patryk Osmaczko 2023-10-30 19:34:21 +01:00 committed by osmaczko
parent 627ac9449b
commit e3a8f5630a
2 changed files with 12 additions and 13 deletions

View File

@ -2081,7 +2081,11 @@ func (m *Messenger) SetCommunityShard(request *requests.SetCommunityShard) (*Mes
} }
response := &MessengerResponse{} response := &MessengerResponse{}
response.AddProtectedTopic(community.PubsubTopic(), topicPrivKey) response.AddProtectedTopic(&ProtectedTopic{
CommunityID: community.IDString(),
PubsubTopic: community.PubsubTopic(),
PublicKey: hexutil.Encode(crypto.FromECDSAPub(&topicPrivKey.PublicKey)),
})
return response, nil return response, nil
} }

View File

@ -1,11 +1,8 @@
package protocol package protocol
import ( import (
"crypto/ecdsa"
"encoding/json" "encoding/json"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/status-im/status-go/eth-node/crypto"
ensservice "github.com/status-im/status-go/services/ens" ensservice "github.com/status-im/status-go/services/ens"
"github.com/status-im/status-go/services/browsers" "github.com/status-im/status-go/services/browsers"
@ -38,6 +35,7 @@ type ClearedHistory struct {
} }
type ProtectedTopic struct { type ProtectedTopic struct {
CommunityID string `json:"communityID"`
PubsubTopic string `json:"pubsubTopic"` PubsubTopic string `json:"pubsubTopic"`
PublicKey string `json:"publicKey"` PublicKey string `json:"publicKey"`
} }
@ -70,7 +68,7 @@ type MessengerResponse struct {
removedMessages map[string]*RemovedMessage removedMessages map[string]*RemovedMessage
communities map[string]*communities.Community communities map[string]*communities.Community
communitiesSettings map[string]*communities.CommunitySettings communitiesSettings map[string]*communities.CommunitySettings
protectedTopics map[string]*ecdsa.PrivateKey protectedTopics map[string]*ProtectedTopic
activityCenterNotifications map[string]*ActivityCenterNotification activityCenterNotifications map[string]*ActivityCenterNotification
activityCenterState *ActivityCenterState activityCenterState *ActivityCenterState
messages map[string]*common.Message messages map[string]*common.Message
@ -224,11 +222,8 @@ func (r *MessengerResponse) CommunitiesSettings() []*communities.CommunitySettin
func (r *MessengerResponse) ProtectedTopics() []ProtectedTopic { func (r *MessengerResponse) ProtectedTopics() []ProtectedTopic {
protectedTopics := make([]ProtectedTopic, 0, len(r.protectedTopics)) protectedTopics := make([]ProtectedTopic, 0, len(r.protectedTopics))
for pubsubTopic, privKey := range r.protectedTopics { for _, pt := range r.protectedTopics {
protectedTopics = append(protectedTopics, ProtectedTopic{ protectedTopics = append(protectedTopics, *pt)
PubsubTopic: pubsubTopic,
PublicKey: hexutil.Encode(crypto.FromECDSAPub(&privKey.PublicKey)),
})
} }
return protectedTopics return protectedTopics
} }
@ -377,12 +372,12 @@ func (r *MessengerResponse) AddRequestsToJoinCommunity(requestsToJoin []*communi
r.RequestsToJoinCommunity = append(r.RequestsToJoinCommunity, requestsToJoin...) r.RequestsToJoinCommunity = append(r.RequestsToJoinCommunity, requestsToJoin...)
} }
func (r *MessengerResponse) AddProtectedTopic(pubsubTopic string, privKey *ecdsa.PrivateKey) { func (r *MessengerResponse) AddProtectedTopic(pt *ProtectedTopic) {
if r.protectedTopics == nil { if r.protectedTopics == nil {
r.protectedTopics = make(map[string]*ecdsa.PrivateKey) r.protectedTopics = make(map[string]*ProtectedTopic)
} }
r.protectedTopics[pubsubTopic] = privKey r.protectedTopics[pt.CommunityID] = pt
} }
func (r *MessengerResponse) AddRequestToJoinCommunity(requestToJoin *communities.RequestToJoin) { func (r *MessengerResponse) AddRequestToJoinCommunity(requestToJoin *communities.RequestToJoin) {