Fix various group related bugs

This commit is contained in:
Jon Staab
2025-10-30 14:52:20 -07:00
parent f375e70a42
commit e11dfee898
2 changed files with 41 additions and 16 deletions
+21 -6
View File
@@ -3,12 +3,21 @@ package zooid
import (
"fiatjaf.com/nostr"
"fiatjaf.com/nostr/nip29"
"slices"
)
// Utils
func GetGroupIDFromEvent(event nostr.Event) string {
tag := event.Tags.Find("h")
var tagName string
if slices.Contains(nip29.MetadataEventKinds, event.Kind) {
tagName = "d"
} else {
tagName = "h"
}
tag := event.Tags.Find(tagName)
if tag != nil {
return tag[1]
@@ -27,7 +36,7 @@ type GroupStore struct {
// Metadata
func (g *GroupStore) GetMetadata(h string) nostr.Event {
func (g *GroupStore) GetMetadata(h string) (nostr.Event, bool) {
filter := nostr.Filter{
Kinds: []nostr.Kind{nostr.KindSimpleGroupMetadata},
Tags: nostr.TagMap{
@@ -36,13 +45,13 @@ func (g *GroupStore) GetMetadata(h string) nostr.Event {
}
for event := range g.Events.QueryEvents(filter, 1) {
return event
return event, true
}
return nostr.Event{}
return nostr.Event{}, false
}
func (g *GroupStore) SetMetadataFromEvent(event nostr.Event) error {
func (g *GroupStore) UpdateMetadata(event nostr.Event) error {
tags := nostr.Tags{}
for _, tag := range event.Tags {
@@ -214,7 +223,13 @@ func (g *GroupStore) UpdateMembersList(h string) error {
// Other stuff
func (g *GroupStore) HasAccess(h string, pubkey nostr.PubKey) bool {
if !HasTag(g.GetMetadata(h).Tags, "closed") {
meta, found := g.GetMetadata(h)
if !found {
return false
}
if !HasTag(meta.Tags, "closed") {
return true
}