From 45f8796e644e705014a79cccea026f3674933465 Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Fri, 24 Oct 2025 11:59:10 -0700 Subject: [PATCH] Generate group events --- zooid/groups.go | 2 ++ zooid/instance.go | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/zooid/groups.go b/zooid/groups.go index a9a7450..1a40a36 100644 --- a/zooid/groups.go +++ b/zooid/groups.go @@ -97,6 +97,7 @@ func (g *GroupStore) GetAdmins(h string) []nostr.PubKey { func (g *GroupStore) GenerateAdminsEvent(h string) nostr.Event { tags := nostr.Tags{ nostr.Tag{"-"}, + nostr.Tag{"d", h}, } for _, pubkey := range g.GetAdmins(h) { @@ -192,6 +193,7 @@ func (g *GroupStore) GetMembers(h string) []nostr.PubKey { func (g *GroupStore) GenerateMembersEvent(h string) nostr.Event { tags := nostr.Tags{ nostr.Tag{"-"}, + nostr.Tag{"d", h}, } for _, pubkey := range g.GetMembers(h) { diff --git a/zooid/instance.go b/zooid/instance.go index 53c7eaf..1db9742 100644 --- a/zooid/instance.go +++ b/zooid/instance.go @@ -275,9 +275,42 @@ func (instance *Instance) QueryStored(ctx context.Context, filter nostr.Filter) } } else { pubkey, _ := khatru.GetAuthed(ctx) + generated := make([]nostr.Event, 0) if slices.Contains(filter.Kinds, RELAY_INVITE) && instance.Config.CanInvite(pubkey) { - if !yield(instance.StripSignature(ctx, instance.GenerateInviteEvent(pubkey))) { + generated = append(generated, instance.GenerateInviteEvent(pubkey)) + } + + if slices.Contains(filter.Kinds, nostr.KindSimpleGroupAdmins) { + filter = nostr.Filter{ + Kinds: []nostr.Kind{nostr.KindSimpleGroupMetadata}, + } + + for event := range instance.Events.QueryEvents(filter, 0) { + if tag := event.Tags.Find("d"); tag != nil { + generated = append(generated, instance.Groups.GenerateAdminsEvent(tag[1])) + } + } + } + + if slices.Contains(filter.Kinds, nostr.KindSimpleGroupMembers) { + filter = nostr.Filter{ + Kinds: []nostr.Kind{nostr.KindSimpleGroupMetadata}, + } + + for event := range instance.Events.QueryEvents(filter, 0) { + if tag := event.Tags.Find("d"); tag != nil { + generated = append(generated, instance.Groups.GenerateMembersEvent(tag[1])) + } + } + } + + for _, event := range generated { + if !filter.Matches(event) { + continue + } + + if !yield(instance.StripSignature(ctx, event)) { return } }