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 Dec 4, 2024
1 parent e8877b1 commit 5c3e122
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 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.UniversalChatID())
importedMessages := make(map[transport.Filter][]*types.Message, 0)

importedMessages[*filter] = append(importedMessages[*filter], message)
Expand Down
19 changes: 10 additions & 9 deletions protocol/messenger_communities.go
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,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.UniversalChatID()})

}

Expand Down Expand Up @@ -2404,7 +2404,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.UniversalChatID()})

response.AddChat(c)
}
Expand Down Expand Up @@ -2446,7 +2446,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.UniversalChatID()})
response.AddChat(c)
}

Expand Down Expand Up @@ -2500,8 +2500,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: o.UniversalChatID()},
{ChatID: mlChannelID, PubsubTopic: communityPubsubTopic, ContentTopicOverrideID: o.UniversalChatID()},
{ChatID: memberUpdateChannelID, PubsubTopic: communityPubsubTopic},
{ChatID: uncompressedPubKey, PubsubTopic: shard.DefaultNonProtectedPubsubTopic()},
}
Expand Down Expand Up @@ -2727,7 +2727,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.UniversalChatID()})
}

_, err := m.transport.InitPublicFilters(publicFiltersToInit)
Expand Down Expand Up @@ -3421,8 +3421,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.UniversalChatID(),
})
// Update name, currently is the only field is mutable
} else if oldChat.Name != chat.Name ||
Expand Down Expand Up @@ -3959,7 +3960,7 @@ func (m *Messenger) InitHistoryArchiveTasks(communities []*communities.Community
// adding the content-topic used for member updates.
// since member updates would not be too frequent i.e only addition/deletion would add a new message,
// this shouldn't cause too much increase in size of archive generated.
filters = append(filters, m.transport.FilterByChatID(c.MemberUpdateChannelID()))
filters = append(filters, m.transport.FilterByChatID(c.UniversalChatID()))

// First we need to know the timestamp of the latest waku message
// we've received for this community, so we can request messages we've
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 5c3e122

Please sign in to comment.