replace "no-text" with "supported_kinds".

This commit is contained in:
fiatjaf
2026-03-11 10:49:41 -03:00
parent 4e490879b5
commit 681bd55e55
2 changed files with 23 additions and 25 deletions
+23 -14
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"net/url"
"slices"
"strconv"
"strings"
"fiatjaf.com/nostr"
@@ -55,12 +56,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
// indicates which event kinds this group supports
SupportedKinds []nostr.Kind
Roles []*Role
InviteCodes []string
@@ -75,7 +76,6 @@ func (group Group) String() string {
maybeRestricted := ""
maybeHidden := ""
maybeClosed := ""
maybeNoText := ""
if group.Private {
maybePrivate = " private"
@@ -89,9 +89,6 @@ func (group Group) String() string {
if group.Closed {
maybeClosed = " closed"
}
if group.NoText {
maybeNoText = " no-text"
}
maybeLivekit := ""
if group.Livekit {
@@ -123,7 +120,6 @@ func (group Group) String() string {
maybeRestricted,
maybeHidden,
maybeClosed,
maybeNoText,
maybeLivekit,
group.Picture,
group.About,
@@ -190,14 +186,19 @@ 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"})
}
if group.SupportedKinds != nil {
tag := make(nostr.Tag, 1, 1+len(group.SupportedKinds))
tag[0] = "supported_kinds"
for _, kind := range group.SupportedKinds {
tag = append(tag, strconv.Itoa(int(kind)))
}
evt.Tags = append(evt.Tags, tag)
}
return evt
}
@@ -282,10 +283,18 @@ func (group *Group) MergeInMetadataEvent(evt *nostr.Event) error {
group.Closed = true
case "hidden":
group.Hidden = true
case "no-text":
group.NoText = true
case "livekit":
group.Livekit = true
case "supported_kinds":
kinds := make([]nostr.Kind, 0, len(tag)-1)
for _, raw := range tag[1:] {
kind, err := strconv.Atoi(raw)
if err != nil {
continue
}
kinds = append(kinds, nostr.Kind(kind))
}
group.SupportedKinds = kinds
default:
if len(tag) >= 2 {
switch tag[0] {
-11
View File
@@ -123,12 +123,6 @@ var moderationActionFactories = map[nostr.Kind]func(nostr.Event) (Action, error)
case "public":
edit.PrivateValue = &n
ok = true
case "no-text":
edit.NoTextValue = &y
ok = true
case "text":
edit.NoTextValue = &n
ok = true
case "livekit":
edit.LivekitValue = &y
ok = true
@@ -250,7 +244,6 @@ type EditMetadata struct {
ClosedValue *bool
HiddenValue *bool
PrivateValue *bool
NoTextValue *bool
LivekitValue *bool
When nostr.Timestamp
}
@@ -279,9 +272,6 @@ 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
}
@@ -310,7 +300,6 @@ 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 = ""