Fix some group related things

This commit is contained in:
Jon Staab
2025-10-01 16:39:13 -07:00
parent 4fe2981419
commit 03c38fc895
2 changed files with 22 additions and 6 deletions
+13 -3
View File
@@ -20,7 +20,7 @@ func MakeGroupMetadataFilter(h string) nostr.Filter {
return nostr.Filter{
Kinds: []nostr.Kind{nostr.KindSimpleGroupMetadata},
Tags: nostr.TagMap{
"a": []string{h},
"d": []string{h},
},
}
}
@@ -29,7 +29,7 @@ func MakeGroupEventFilters(h string) []nostr.Filter {
return []nostr.Filter{
{
Tags: nostr.TagMap{
"a": []string{h},
"d": []string{h},
},
},
{
@@ -87,9 +87,19 @@ func MakeRemoveUserEvent(h string, pubkey nostr.PubKey) nostr.Event {
}
func MakeMetadataEvent(event nostr.Event) nostr.Event {
tags := nostr.Tags{}
for _, tag := range event.Tags {
if len(tag) >= 2 && tag[0] == "h" {
tags = append(tags, nostr.Tag{"d", tag[1]})
} else {
tags = append(tags, tag)
}
}
return nostr.Event{
Kind: nostr.KindSimpleGroupMetadata,
CreatedAt: event.CreatedAt,
Tags: event.Tags,
Tags: tags,
}
}
+9 -3
View File
@@ -73,6 +73,10 @@ func MakeInstance(filename string) (*Instance, error) {
instance.Relay.Info.PubKey = &pubkey
}
if instance.Config.Groups.Enabled {
instance.Relay.Info.SupportedNIPs = append(instance.Relay.Info.SupportedNIPs, 29)
}
// Handlers
instance.Relay.OnConnect = instance.OnConnect
@@ -87,7 +91,7 @@ func MakeInstance(filename string) (*Instance, error) {
instance.Relay.RejectConnection = instance.RejectConnection
instance.Relay.PreventBroadcast = instance.PreventBroadcast
// Todo: when there's a new version of khatru
// Todo: when there's a new version of khatru
// instance.Relay.StartExpirationManager()
// HTTP request handling
@@ -311,8 +315,10 @@ func (instance *Instance) OnEvent(ctx context.Context, event nostr.Event) (rejec
meta := instance.GetGroupMetadataEvent(h)
if event.Kind == nostr.KindSimpleGroupCreateGroup && !IsEmptyEvent(meta) {
return true, "invalid: that group already exists"
if event.Kind == nostr.KindSimpleGroupCreateGroup {
if !IsEmptyEvent(meta) {
return true, "invalid: that group already exists"
}
} else if IsEmptyEvent(meta) {
return true, "invalid: no such group exists"
}