Fix some group related things
This commit is contained in:
+13
-3
@@ -20,7 +20,7 @@ func MakeGroupMetadataFilter(h string) nostr.Filter {
|
|||||||
return nostr.Filter{
|
return nostr.Filter{
|
||||||
Kinds: []nostr.Kind{nostr.KindSimpleGroupMetadata},
|
Kinds: []nostr.Kind{nostr.KindSimpleGroupMetadata},
|
||||||
Tags: nostr.TagMap{
|
Tags: nostr.TagMap{
|
||||||
"a": []string{h},
|
"d": []string{h},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,7 @@ func MakeGroupEventFilters(h string) []nostr.Filter {
|
|||||||
return []nostr.Filter{
|
return []nostr.Filter{
|
||||||
{
|
{
|
||||||
Tags: nostr.TagMap{
|
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 {
|
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{
|
return nostr.Event{
|
||||||
Kind: nostr.KindSimpleGroupMetadata,
|
Kind: nostr.KindSimpleGroupMetadata,
|
||||||
CreatedAt: event.CreatedAt,
|
CreatedAt: event.CreatedAt,
|
||||||
Tags: event.Tags,
|
Tags: tags,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-3
@@ -73,6 +73,10 @@ func MakeInstance(filename string) (*Instance, error) {
|
|||||||
instance.Relay.Info.PubKey = &pubkey
|
instance.Relay.Info.PubKey = &pubkey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if instance.Config.Groups.Enabled {
|
||||||
|
instance.Relay.Info.SupportedNIPs = append(instance.Relay.Info.SupportedNIPs, 29)
|
||||||
|
}
|
||||||
|
|
||||||
// Handlers
|
// Handlers
|
||||||
|
|
||||||
instance.Relay.OnConnect = instance.OnConnect
|
instance.Relay.OnConnect = instance.OnConnect
|
||||||
@@ -87,7 +91,7 @@ func MakeInstance(filename string) (*Instance, error) {
|
|||||||
instance.Relay.RejectConnection = instance.RejectConnection
|
instance.Relay.RejectConnection = instance.RejectConnection
|
||||||
instance.Relay.PreventBroadcast = instance.PreventBroadcast
|
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()
|
// instance.Relay.StartExpirationManager()
|
||||||
|
|
||||||
// HTTP request handling
|
// HTTP request handling
|
||||||
@@ -311,8 +315,10 @@ func (instance *Instance) OnEvent(ctx context.Context, event nostr.Event) (rejec
|
|||||||
|
|
||||||
meta := instance.GetGroupMetadataEvent(h)
|
meta := instance.GetGroupMetadataEvent(h)
|
||||||
|
|
||||||
if event.Kind == nostr.KindSimpleGroupCreateGroup && !IsEmptyEvent(meta) {
|
if event.Kind == nostr.KindSimpleGroupCreateGroup {
|
||||||
return true, "invalid: that group already exists"
|
if !IsEmptyEvent(meta) {
|
||||||
|
return true, "invalid: that group already exists"
|
||||||
|
}
|
||||||
} else if IsEmptyEvent(meta) {
|
} else if IsEmptyEvent(meta) {
|
||||||
return true, "invalid: no such group exists"
|
return true, "invalid: no such group exists"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user