Skip to content

Commit

Permalink
feat_: use content-topic override for all community filters
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyaprem committed Nov 1, 2024
1 parent d61d200 commit 54b1cd7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion protocol/communities_messenger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3630,7 +3630,7 @@ func (s *MessengerCommunitiesSuite) TestHandleImport() {
message.Sig = crypto.FromECDSAPub(&s.owner.identity.PublicKey)
message.Payload = wrappedPayload

filter := s.alice.transport.FilterByChatID(chat.ID)
filter := s.alice.transport.FilterByChatID(community.MemberUpdateChannelID())
importedMessages := make(map[transport.Filter][]*types.Message, 0)

importedMessages[*filter] = append(importedMessages[*filter], message)
Expand Down
17 changes: 9 additions & 8 deletions protocol/messenger_communities.go
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ func (m *Messenger) initCommunityChats(community *communities.Community) ([]*Cha
chats := CreateCommunityChats(community, m.getTimesource())

for _, chat := range chats {
publicFiltersToInit = append(publicFiltersToInit, transport.FiltersToInitialize{ChatID: chat.ID, PubsubTopic: community.PubsubTopic()})
publicFiltersToInit = append(publicFiltersToInit, transport.FiltersToInitialize{ChatID: chat.ID, PubsubTopic: community.PubsubTopic(), ContentTopicOverrideID: community.MemberUpdateChannelID()})

}

Expand Down Expand Up @@ -2402,7 +2402,7 @@ func (m *Messenger) CreateCommunityChat(communityID types.HexBytes, c *protobuf.
for chatID, chat := range changes.ChatsAdded {
c := CreateCommunityChat(changes.Community.IDString(), chatID, chat, m.getTimesource())
chats = append(chats, c)
publicFiltersToInit = append(publicFiltersToInit, transport.FiltersToInitialize{ChatID: c.ID, PubsubTopic: changes.Community.PubsubTopic()})
publicFiltersToInit = append(publicFiltersToInit, transport.FiltersToInitialize{ChatID: c.ID, PubsubTopic: changes.Community.PubsubTopic(), ContentTopicOverrideID: changes.Community.MemberUpdateChannelID()})

response.AddChat(c)
}
Expand Down Expand Up @@ -2444,7 +2444,7 @@ func (m *Messenger) EditCommunityChat(communityID types.HexBytes, chatID string,
for chatID, change := range changes.ChatsModified {
c := CreateCommunityChat(community.IDString(), chatID, change.ChatModified, m.getTimesource())
chats = append(chats, c)
publicFiltersToInit = append(publicFiltersToInit, transport.FiltersToInitialize{ChatID: c.ID, PubsubTopic: community.PubsubTopic()})
publicFiltersToInit = append(publicFiltersToInit, transport.FiltersToInitialize{ChatID: c.ID, PubsubTopic: community.PubsubTopic(), ContentTopicOverrideID: community.MemberUpdateChannelID()})
response.AddChat(c)
}

Expand Down Expand Up @@ -2498,8 +2498,8 @@ func (m *Messenger) DefaultFilters(o *communities.Community) []transport.Filters

filters := []transport.FiltersToInitialize{
{ChatID: cID, PubsubTopic: communityPubsubTopic},
{ChatID: updatesChannelID, PubsubTopic: communityPubsubTopic},
{ChatID: mlChannelID, PubsubTopic: communityPubsubTopic},
{ChatID: updatesChannelID, PubsubTopic: communityPubsubTopic, ContentTopicOverrideID: memberUpdateChannelID},
{ChatID: mlChannelID, PubsubTopic: communityPubsubTopic, ContentTopicOverrideID: memberUpdateChannelID},
{ChatID: memberUpdateChannelID, PubsubTopic: communityPubsubTopic},
{ChatID: uncompressedPubKey, PubsubTopic: shard.DefaultNonProtectedPubsubTopic()},
}
Expand Down Expand Up @@ -2725,7 +2725,7 @@ func (m *Messenger) UpdateCommunityFilters(community *communities.Community) err
if err != nil {
return err
}
publicFiltersToInit = append(publicFiltersToInit, transport.FiltersToInitialize{ChatID: communityChatID, PubsubTopic: community.PubsubTopic()})
publicFiltersToInit = append(publicFiltersToInit, transport.FiltersToInitialize{ChatID: communityChatID, PubsubTopic: community.PubsubTopic(), ContentTopicOverrideID: community.MemberUpdateChannelID()})
}

_, err := m.transport.InitPublicFilters(publicFiltersToInit)
Expand Down Expand Up @@ -3419,8 +3419,9 @@ func (m *Messenger) handleCommunityResponse(state *ReceivedMessageState, communi

state.Response.AddChat(chat)
publicFiltersToInit = append(publicFiltersToInit, transport.FiltersToInitialize{
ChatID: chat.ID,
PubsubTopic: community.PubsubTopic(),
ChatID: chat.ID,
PubsubTopic: community.PubsubTopic(),
ContentTopicOverrideID: community.MemberUpdateChannelID(),
})
// Update name, currently is the only field is mutable
} else if oldChat.Name != chat.Name ||
Expand Down
15 changes: 7 additions & 8 deletions protocol/transport/filters_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,13 @@ func (f *FiltersManager) LoadContactCode(pubKey *ecdsa.PublicKey) (*Filter, erro
func (f *FiltersManager) addSymmetric(chatID string, pubsubTopic string, contentTopicID string) (*RawFilter, error) {
var symKeyID string
var err error

topic := ToTopic(chatID)
var topic []byte
if contentTopicID != "" {
//use override contentTopicID to generate contentTopic
topic = ToTopic(contentTopicID)
} else {
topic = ToTopic(chatID)
}
topics := [][]byte{topic}

symKey, ok := f.keys[chatID]
Expand All @@ -650,12 +655,6 @@ func (f *FiltersManager) addSymmetric(chatID string, pubsubTopic string, content
}
}

if contentTopicID != "" {
//add receive filter for the single default contentTopic for all community chats
topic = ToTopic(contentTopicID)
topics = append(topics, topic)
}

id, err := f.service.Subscribe(&types.SubscriptionOptions{
SymKeyID: symKeyID,
PoW: minPow,
Expand Down

0 comments on commit 54b1cd7

Please sign in to comment.