nip29: add "no-text" and "livekit" tags.
This commit is contained in:
+53
-22
@@ -55,6 +55,12 @@ type Group struct {
|
|||||||
// indicates that relays should hide group metadata from non-members
|
// indicates that relays should hide group metadata from non-members
|
||||||
Hidden bool
|
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
|
Roles []*Role
|
||||||
InviteCodes []string
|
InviteCodes []string
|
||||||
|
|
||||||
@@ -69,6 +75,7 @@ func (group Group) String() string {
|
|||||||
maybeRestricted := ""
|
maybeRestricted := ""
|
||||||
maybeHidden := ""
|
maybeHidden := ""
|
||||||
maybeClosed := ""
|
maybeClosed := ""
|
||||||
|
maybeNoText := ""
|
||||||
|
|
||||||
if group.Private {
|
if group.Private {
|
||||||
maybePrivate = " private"
|
maybePrivate = " private"
|
||||||
@@ -82,6 +89,14 @@ func (group Group) String() string {
|
|||||||
if group.Closed {
|
if group.Closed {
|
||||||
maybeClosed = " closed"
|
maybeClosed = " closed"
|
||||||
}
|
}
|
||||||
|
if group.NoText {
|
||||||
|
maybeNoText = " no-text"
|
||||||
|
}
|
||||||
|
|
||||||
|
maybeLivekit := ""
|
||||||
|
if group.Livekit {
|
||||||
|
maybeLivekit = " livekit"
|
||||||
|
}
|
||||||
|
|
||||||
members := make([]string, len(group.Members))
|
members := make([]string, len(group.Members))
|
||||||
i := 0
|
i := 0
|
||||||
@@ -101,13 +116,15 @@ func (group Group) String() string {
|
|||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf(`<Group %s name="%s"%s%s%s%s picture="%s" about="%s" members=[%v]>`,
|
return fmt.Sprintf(`<Group %s name="%s"%s%s%s%s%s%s picture="%s" about="%s" members=[%v]>`,
|
||||||
group.Address,
|
group.Address,
|
||||||
group.Name,
|
group.Name,
|
||||||
maybePrivate,
|
maybePrivate,
|
||||||
maybeRestricted,
|
maybeRestricted,
|
||||||
maybeHidden,
|
maybeHidden,
|
||||||
maybeClosed,
|
maybeClosed,
|
||||||
|
maybeNoText,
|
||||||
|
maybeLivekit,
|
||||||
group.Picture,
|
group.Picture,
|
||||||
group.About,
|
group.About,
|
||||||
strings.Join(members, " "),
|
strings.Join(members, " "),
|
||||||
@@ -173,6 +190,13 @@ func (group Group) ToMetadataEvent() nostr.Event {
|
|||||||
if group.Closed {
|
if group.Closed {
|
||||||
evt.Tags = append(evt.Tags, nostr.Tag{"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
|
return evt
|
||||||
}
|
}
|
||||||
@@ -247,27 +271,34 @@ func (group *Group) MergeInMetadataEvent(evt *nostr.Event) error {
|
|||||||
group.LastMetadataUpdate = evt.CreatedAt
|
group.LastMetadataUpdate = evt.CreatedAt
|
||||||
group.Name = group.Address.ID
|
group.Name = group.Address.ID
|
||||||
|
|
||||||
if tag := evt.Tags.Find("name"); tag != nil {
|
for _, tag := range evt.Tags {
|
||||||
group.Name = tag[1]
|
if len(tag) >= 1 {
|
||||||
}
|
switch tag[0] {
|
||||||
if tag := evt.Tags.Find("about"); tag != nil {
|
case "private":
|
||||||
group.About = tag[1]
|
group.Private = true
|
||||||
}
|
case "restricted":
|
||||||
if tag := evt.Tags.Find("picture"); tag != nil {
|
group.Restricted = true
|
||||||
group.Picture = tag[1]
|
case "closed":
|
||||||
}
|
group.Closed = true
|
||||||
|
case "hidden":
|
||||||
if tag := evt.Tags.Find("private"); tag != nil {
|
group.Hidden = true
|
||||||
group.Private = true
|
case "no-text":
|
||||||
}
|
group.NoText = true
|
||||||
if tag := evt.Tags.Find("restricted"); tag != nil {
|
default:
|
||||||
group.Restricted = true
|
if len(tag) >= 2 {
|
||||||
}
|
switch tag[0] {
|
||||||
if tag := evt.Tags.Find("hidden"); tag != nil {
|
case "name":
|
||||||
group.Hidden = true
|
group.Name = tag[1]
|
||||||
}
|
case "about":
|
||||||
if tag := evt.Tags.Find("closed"); tag != nil {
|
group.About = tag[1]
|
||||||
group.Closed = true
|
case "picture":
|
||||||
|
group.Picture = tag[1]
|
||||||
|
case "livekit":
|
||||||
|
group.Livekit = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
+49
-41
@@ -78,48 +78,46 @@ 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}
|
||||||
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
|
y := true
|
||||||
n := false
|
|
||||||
if evt.Tags.Has("closed") {
|
for _, tag := range evt.Tags {
|
||||||
edit.ClosedValue = &y
|
if len(tag) >= 1 {
|
||||||
ok = true
|
switch tag[0] {
|
||||||
} else if evt.Tags.Has("open") {
|
case "name":
|
||||||
edit.ClosedValue = &n
|
if len(tag) >= 2 {
|
||||||
ok = true
|
edit.NameValue = &tag[1]
|
||||||
}
|
ok = true
|
||||||
if evt.Tags.Has("restricted") {
|
}
|
||||||
edit.RestrictedValue = &y
|
case "picture":
|
||||||
ok = true
|
if len(tag) >= 2 {
|
||||||
} else if evt.Tags.Has("unrestricted") {
|
edit.PictureValue = &tag[1]
|
||||||
edit.RestrictedValue = &n
|
ok = true
|
||||||
ok = true
|
}
|
||||||
}
|
case "about":
|
||||||
if evt.Tags.Has("hidden") {
|
if len(tag) >= 2 {
|
||||||
edit.HiddenValue = &y
|
edit.AboutValue = &tag[1]
|
||||||
ok = true
|
ok = true
|
||||||
} else if evt.Tags.Has("visible") {
|
}
|
||||||
edit.HiddenValue = &n
|
case "closed":
|
||||||
ok = true
|
edit.ClosedValue = &y
|
||||||
}
|
ok = true
|
||||||
if evt.Tags.Has("private") {
|
case "restricted":
|
||||||
edit.PrivateValue = &y
|
edit.RestrictedValue = &y
|
||||||
ok = true
|
ok = true
|
||||||
} else if evt.Tags.Has("public") {
|
case "hidden":
|
||||||
edit.PrivateValue = &n
|
edit.HiddenValue = &y
|
||||||
ok = true
|
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 {
|
if ok {
|
||||||
@@ -233,6 +231,8 @@ type EditMetadata struct {
|
|||||||
ClosedValue *bool
|
ClosedValue *bool
|
||||||
HiddenValue *bool
|
HiddenValue *bool
|
||||||
PrivateValue *bool
|
PrivateValue *bool
|
||||||
|
NoTextValue *bool
|
||||||
|
LivekitValue *bool
|
||||||
When nostr.Timestamp
|
When nostr.Timestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,6 +260,12 @@ func (a EditMetadata) Apply(group *Group) {
|
|||||||
if a.PrivateValue != nil {
|
if a.PrivateValue != nil {
|
||||||
group.Private = *a.PrivateValue
|
group.Private = *a.PrivateValue
|
||||||
}
|
}
|
||||||
|
if a.NoTextValue != nil {
|
||||||
|
group.NoText = *a.NoTextValue
|
||||||
|
}
|
||||||
|
if a.LivekitValue != nil {
|
||||||
|
group.Livekit = *a.LivekitValue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateGroup struct {
|
type CreateGroup struct {
|
||||||
@@ -285,9 +291,11 @@ func (a DeleteGroup) Apply(group *Group) {
|
|||||||
group.Private = true
|
group.Private = true
|
||||||
group.Restricted = true
|
group.Restricted = true
|
||||||
group.Hidden = true
|
group.Hidden = true
|
||||||
|
group.NoText = true
|
||||||
group.Name = "[deleted]"
|
group.Name = "[deleted]"
|
||||||
group.About = ""
|
group.About = ""
|
||||||
group.Picture = ""
|
group.Picture = ""
|
||||||
|
group.Livekit = false
|
||||||
group.LastMetadataUpdate = a.When
|
group.LastMetadataUpdate = a.When
|
||||||
group.LastAdminsUpdate = a.When
|
group.LastAdminsUpdate = a.When
|
||||||
group.LastMembersUpdate = a.When
|
group.LastMembersUpdate = a.When
|
||||||
|
|||||||
Reference in New Issue
Block a user