nip29: parent/child tag handling.
This commit is contained in:
@@ -66,6 +66,12 @@ type Group struct {
|
|||||||
// indicates which event kinds this group supports
|
// indicates which event kinds this group supports
|
||||||
SupportedKinds []nostr.Kind
|
SupportedKinds []nostr.Kind
|
||||||
|
|
||||||
|
// arbitrary string indicating the parent group
|
||||||
|
Parent string
|
||||||
|
|
||||||
|
// ordered list of identifiers of child groups
|
||||||
|
Children []string
|
||||||
|
|
||||||
Roles []*Role
|
Roles []*Role
|
||||||
InviteCodes []string
|
InviteCodes []string
|
||||||
|
|
||||||
@@ -206,6 +212,14 @@ func (group Group) ToMetadataEvent() nostr.Event {
|
|||||||
evt.Tags = append(evt.Tags, tag)
|
evt.Tags = append(evt.Tags, tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if group.Parent != "" {
|
||||||
|
evt.Tags = append(evt.Tags, nostr.Tag{"parent", group.Parent})
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, child := range group.Children {
|
||||||
|
evt.Tags = append(evt.Tags, nostr.Tag{"child", child})
|
||||||
|
}
|
||||||
|
|
||||||
return evt
|
return evt
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,6 +341,10 @@ func (group *Group) MergeInMetadataEvent(evt *nostr.Event) error {
|
|||||||
group.About = tag[1]
|
group.About = tag[1]
|
||||||
case "picture":
|
case "picture":
|
||||||
group.Picture = tag[1]
|
group.Picture = tag[1]
|
||||||
|
case "parent":
|
||||||
|
group.Parent = tag[1]
|
||||||
|
case "child":
|
||||||
|
group.Children = append(group.Children, tag[1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+33
-108
@@ -79,40 +79,23 @@ var moderationActionFactories = map[nostr.Kind]func(nostr.Event) (Action, error)
|
|||||||
nostr.KindSimpleGroupEditMetadata: func(evt nostr.Event) (Action, error) {
|
nostr.KindSimpleGroupEditMetadata: func(evt nostr.Event) (Action, error) {
|
||||||
ok := false
|
ok := false
|
||||||
edit := EditMetadata{When: evt.CreatedAt}
|
edit := EditMetadata{When: evt.CreatedAt}
|
||||||
y := true
|
|
||||||
n := false
|
|
||||||
|
|
||||||
hasName := false
|
|
||||||
|
|
||||||
// DEPRECATED: remove all the fields not tagged with Replace = true eventually
|
|
||||||
// edit-metadata to become a PUT rather than a PATCH
|
|
||||||
|
|
||||||
for _, tag := range evt.Tags {
|
for _, tag := range evt.Tags {
|
||||||
if len(tag) >= 1 {
|
if len(tag) >= 1 {
|
||||||
switch tag[0] {
|
switch tag[0] {
|
||||||
case "name":
|
case "name":
|
||||||
if len(tag) >= 2 {
|
if len(tag) >= 2 {
|
||||||
edit.NameValue = &tag[1]
|
edit.Group.Name = tag[1]
|
||||||
if ok {
|
|
||||||
edit.Replace = true
|
|
||||||
}
|
|
||||||
ok = true
|
ok = true
|
||||||
hasName = true
|
|
||||||
}
|
}
|
||||||
case "picture":
|
case "picture":
|
||||||
if len(tag) >= 2 {
|
if len(tag) >= 2 {
|
||||||
edit.PictureValue = &tag[1]
|
edit.Group.Picture = tag[1]
|
||||||
if hasName {
|
|
||||||
edit.Replace = true
|
|
||||||
}
|
|
||||||
ok = true
|
ok = true
|
||||||
}
|
}
|
||||||
case "about":
|
case "about":
|
||||||
if len(tag) >= 2 {
|
if len(tag) >= 2 {
|
||||||
edit.AboutValue = &tag[1]
|
edit.Group.About = tag[1]
|
||||||
if hasName {
|
|
||||||
edit.Replace = true
|
|
||||||
}
|
|
||||||
ok = true
|
ok = true
|
||||||
}
|
}
|
||||||
case "supported_kinds":
|
case "supported_kinds":
|
||||||
@@ -124,54 +107,33 @@ var moderationActionFactories = map[nostr.Kind]func(nostr.Event) (Action, error)
|
|||||||
kinds = append(kinds, nostr.Kind(kind))
|
kinds = append(kinds, nostr.Kind(kind))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
edit.SupportedKindsValue = &kinds
|
edit.Group.SupportedKinds = kinds
|
||||||
edit.Replace = true
|
|
||||||
case "closed":
|
|
||||||
edit.ClosedValue = &y
|
|
||||||
if hasName {
|
|
||||||
edit.Replace = true
|
|
||||||
}
|
|
||||||
ok = true
|
ok = true
|
||||||
case "open":
|
case "closed":
|
||||||
edit.ClosedValue = &n
|
edit.Group.Closed = true
|
||||||
ok = true
|
ok = true
|
||||||
case "restricted":
|
case "restricted":
|
||||||
edit.RestrictedValue = &y
|
edit.Group.Restricted = true
|
||||||
if hasName {
|
|
||||||
edit.Replace = true
|
|
||||||
}
|
|
||||||
ok = true
|
|
||||||
case "unrestricted":
|
|
||||||
edit.RestrictedValue = &n
|
|
||||||
ok = true
|
ok = true
|
||||||
case "hidden":
|
case "hidden":
|
||||||
edit.HiddenValue = &y
|
edit.Group.Hidden = true
|
||||||
if hasName {
|
|
||||||
edit.Replace = true
|
|
||||||
}
|
|
||||||
ok = true
|
|
||||||
case "visible":
|
|
||||||
edit.HiddenValue = &n
|
|
||||||
ok = true
|
ok = true
|
||||||
case "private":
|
case "private":
|
||||||
edit.PrivateValue = &y
|
edit.Group.Private = true
|
||||||
if hasName {
|
ok = true
|
||||||
edit.Replace = true
|
case "parent":
|
||||||
|
if len(tag) >= 2 {
|
||||||
|
edit.Group.Parent = tag[1]
|
||||||
|
ok = true
|
||||||
}
|
}
|
||||||
ok = true
|
|
||||||
case "public":
|
|
||||||
edit.PrivateValue = &n
|
|
||||||
ok = true
|
|
||||||
case "livekit":
|
case "livekit":
|
||||||
edit.LiveKitValue = &y
|
edit.Group.LiveKit = true
|
||||||
edit.Replace = true
|
|
||||||
ok = true
|
|
||||||
case "no-livekit":
|
|
||||||
edit.LiveKitValue = &n
|
|
||||||
ok = true
|
|
||||||
case "no-text":
|
|
||||||
edit.SupportedKindsValue = nil
|
|
||||||
ok = true
|
ok = true
|
||||||
|
case "child":
|
||||||
|
if len(tag) >= 2 {
|
||||||
|
edit.Group.Children = append(edit.Group.Children, tag[1])
|
||||||
|
ok = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -280,63 +242,26 @@ func (a RemoveUser) Apply(group *Group) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type EditMetadata struct {
|
type EditMetadata struct {
|
||||||
NameValue *string
|
Group
|
||||||
PictureValue *string
|
|
||||||
AboutValue *string
|
|
||||||
RestrictedValue *bool
|
|
||||||
ClosedValue *bool
|
|
||||||
HiddenValue *bool
|
|
||||||
PrivateValue *bool
|
|
||||||
LiveKitValue *bool
|
|
||||||
SupportedKindsValue *[]nostr.Kind
|
|
||||||
|
|
||||||
Replace bool
|
When nostr.Timestamp
|
||||||
When nostr.Timestamp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ EditMetadata) Name() string { return "edit-metadata" }
|
func (_ EditMetadata) Name() string { return "edit-metadata" }
|
||||||
func (a EditMetadata) Apply(group *Group) {
|
func (a EditMetadata) Apply(group *Group) {
|
||||||
group.LastMetadataUpdate = a.When
|
group.LastMetadataUpdate = a.When
|
||||||
|
|
||||||
if a.Replace {
|
group.Name = a.Group.Name
|
||||||
group.Name = ""
|
group.Picture = a.Group.Picture
|
||||||
group.Picture = ""
|
group.About = a.Group.About
|
||||||
group.About = ""
|
group.Restricted = a.Group.Restricted
|
||||||
group.Restricted = false
|
group.Closed = a.Group.Closed
|
||||||
group.Closed = false
|
group.Hidden = a.Group.Hidden
|
||||||
group.Hidden = false
|
group.Private = a.Group.Private
|
||||||
group.Private = false
|
group.LiveKit = a.Group.LiveKit
|
||||||
group.LiveKit = false
|
group.SupportedKinds = a.Group.SupportedKinds
|
||||||
group.SupportedKinds = nil
|
group.Parent = a.Group.Parent
|
||||||
}
|
group.Children = a.Group.Children
|
||||||
|
|
||||||
if a.NameValue != nil {
|
|
||||||
group.Name = *a.NameValue
|
|
||||||
}
|
|
||||||
if a.PictureValue != nil {
|
|
||||||
group.Picture = *a.PictureValue
|
|
||||||
}
|
|
||||||
if a.AboutValue != nil {
|
|
||||||
group.About = *a.AboutValue
|
|
||||||
}
|
|
||||||
if a.RestrictedValue != nil {
|
|
||||||
group.Restricted = *a.RestrictedValue
|
|
||||||
}
|
|
||||||
if a.ClosedValue != nil {
|
|
||||||
group.Closed = *a.ClosedValue
|
|
||||||
}
|
|
||||||
if a.HiddenValue != nil {
|
|
||||||
group.Hidden = *a.HiddenValue
|
|
||||||
}
|
|
||||||
if a.PrivateValue != nil {
|
|
||||||
group.Private = *a.PrivateValue
|
|
||||||
}
|
|
||||||
if a.LiveKitValue != nil {
|
|
||||||
group.LiveKit = *a.LiveKitValue
|
|
||||||
}
|
|
||||||
if a.SupportedKindsValue != nil {
|
|
||||||
group.SupportedKinds = *a.SupportedKindsValue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateGroup struct {
|
type CreateGroup struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user