From 00ffe16cb76934aa7fb4e97babed06b890d869aa Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Thu, 26 Feb 2026 07:17:58 -0300 Subject: [PATCH] nip29: add "no-text" and "livekit" tags. --- nip29/group.go | 75 ++++++++++++++++++++++--------- nip29/moderation_actions.go | 90 ++++++++++++++++++++----------------- 2 files changed, 102 insertions(+), 63 deletions(-) diff --git a/nip29/group.go b/nip29/group.go index 5a323f4..8902ca4 100644 --- a/nip29/group.go +++ b/nip29/group.go @@ -55,6 +55,12 @@ type Group struct { // indicates that relays should hide group metadata from non-members Hidden bool + // indicates that text messages are not allowed in the group + NoText bool + + // indicates that the group supports audio/video live chat + Livekit bool + Roles []*Role InviteCodes []string @@ -69,6 +75,7 @@ func (group Group) String() string { maybeRestricted := "" maybeHidden := "" maybeClosed := "" + maybeNoText := "" if group.Private { maybePrivate = " private" @@ -82,6 +89,14 @@ func (group Group) String() string { if group.Closed { maybeClosed = " closed" } + if group.NoText { + maybeNoText = " no-text" + } + + maybeLivekit := "" + if group.Livekit { + maybeLivekit = " livekit" + } members := make([]string, len(group.Members)) i := 0 @@ -101,13 +116,15 @@ func (group Group) String() string { i++ } - return fmt.Sprintf(``, + return fmt.Sprintf(``, group.Address, group.Name, maybePrivate, maybeRestricted, maybeHidden, maybeClosed, + maybeNoText, + maybeLivekit, group.Picture, group.About, strings.Join(members, " "), @@ -173,6 +190,13 @@ func (group Group) ToMetadataEvent() nostr.Event { if group.Closed { evt.Tags = append(evt.Tags, nostr.Tag{"closed"}) } + if group.NoText { + evt.Tags = append(evt.Tags, nostr.Tag{"no-text"}) + } + + if group.Livekit { + evt.Tags = append(evt.Tags, nostr.Tag{"livekit"}) + } return evt } @@ -247,27 +271,34 @@ func (group *Group) MergeInMetadataEvent(evt *nostr.Event) error { group.LastMetadataUpdate = evt.CreatedAt group.Name = group.Address.ID - if tag := evt.Tags.Find("name"); tag != nil { - group.Name = tag[1] - } - if tag := evt.Tags.Find("about"); tag != nil { - group.About = tag[1] - } - if tag := evt.Tags.Find("picture"); tag != nil { - group.Picture = tag[1] - } - - if tag := evt.Tags.Find("private"); tag != nil { - group.Private = true - } - if tag := evt.Tags.Find("restricted"); tag != nil { - group.Restricted = true - } - if tag := evt.Tags.Find("hidden"); tag != nil { - group.Hidden = true - } - if tag := evt.Tags.Find("closed"); tag != nil { - group.Closed = true + for _, tag := range evt.Tags { + if len(tag) >= 1 { + switch tag[0] { + case "private": + group.Private = true + case "restricted": + group.Restricted = true + case "closed": + group.Closed = true + case "hidden": + group.Hidden = true + case "no-text": + group.NoText = true + default: + if len(tag) >= 2 { + switch tag[0] { + case "name": + group.Name = tag[1] + case "about": + group.About = tag[1] + case "picture": + group.Picture = tag[1] + case "livekit": + group.Livekit = true + } + } + } + } } return nil diff --git a/nip29/moderation_actions.go b/nip29/moderation_actions.go index 0a819c0..8aa4ccb 100644 --- a/nip29/moderation_actions.go +++ b/nip29/moderation_actions.go @@ -78,48 +78,46 @@ var moderationActionFactories = map[nostr.Kind]func(nostr.Event) (Action, error) nostr.KindSimpleGroupEditMetadata: func(evt nostr.Event) (Action, error) { ok := false edit := EditMetadata{When: evt.CreatedAt} - if t := evt.Tags.Find("name"); t != nil { - edit.NameValue = &t[1] - ok = true - } - if t := evt.Tags.Find("picture"); t != nil { - edit.PictureValue = &t[1] - ok = true - } - if t := evt.Tags.Find("about"); t != nil { - edit.AboutValue = &t[1] - ok = true - } - y := true - n := false - if evt.Tags.Has("closed") { - edit.ClosedValue = &y - ok = true - } else if evt.Tags.Has("open") { - edit.ClosedValue = &n - ok = true - } - if evt.Tags.Has("restricted") { - edit.RestrictedValue = &y - ok = true - } else if evt.Tags.Has("unrestricted") { - edit.RestrictedValue = &n - ok = true - } - if evt.Tags.Has("hidden") { - edit.HiddenValue = &y - ok = true - } else if evt.Tags.Has("visible") { - edit.HiddenValue = &n - ok = true - } - if evt.Tags.Has("private") { - edit.PrivateValue = &y - ok = true - } else if evt.Tags.Has("public") { - edit.PrivateValue = &n - ok = true + + for _, tag := range evt.Tags { + if len(tag) >= 1 { + switch tag[0] { + case "name": + if len(tag) >= 2 { + edit.NameValue = &tag[1] + ok = true + } + case "picture": + if len(tag) >= 2 { + edit.PictureValue = &tag[1] + ok = true + } + case "about": + if len(tag) >= 2 { + edit.AboutValue = &tag[1] + ok = true + } + case "closed": + edit.ClosedValue = &y + ok = true + case "restricted": + edit.RestrictedValue = &y + ok = true + case "hidden": + edit.HiddenValue = &y + ok = true + case "private": + edit.PrivateValue = &y + ok = true + case "no-text": + edit.NoTextValue = &y + ok = true + case "livekit": + edit.LivekitValue = &y + ok = true + } + } } if ok { @@ -233,6 +231,8 @@ type EditMetadata struct { ClosedValue *bool HiddenValue *bool PrivateValue *bool + NoTextValue *bool + LivekitValue *bool When nostr.Timestamp } @@ -260,6 +260,12 @@ func (a EditMetadata) Apply(group *Group) { if a.PrivateValue != nil { group.Private = *a.PrivateValue } + if a.NoTextValue != nil { + group.NoText = *a.NoTextValue + } + if a.LivekitValue != nil { + group.Livekit = *a.LivekitValue + } } type CreateGroup struct { @@ -285,9 +291,11 @@ func (a DeleteGroup) Apply(group *Group) { group.Private = true group.Restricted = true group.Hidden = true + group.NoText = true group.Name = "[deleted]" group.About = "" group.Picture = "" + group.Livekit = false group.LastMetadataUpdate = a.When group.LastAdminsUpdate = a.When group.LastMembersUpdate = a.When