nip29: fix updating LastAdminsUpdate and LastMembersUpdate.
This commit is contained in:
@@ -49,12 +49,12 @@ type Group struct {
|
|||||||
// indicates that only members can write messages to the group
|
// indicates that only members can write messages to the group
|
||||||
Restricted bool
|
Restricted bool
|
||||||
|
|
||||||
// indicates that relays should hide group metadata from non-members
|
|
||||||
Hidden bool
|
|
||||||
|
|
||||||
// indicates that join requests are ignored unless they include an invite code
|
// indicates that join requests are ignored unless they include an invite code
|
||||||
Closed bool
|
Closed bool
|
||||||
|
|
||||||
|
// indicates that relays should hide group metadata from non-members
|
||||||
|
Hidden bool
|
||||||
|
|
||||||
Roles []*Role
|
Roles []*Role
|
||||||
InviteCodes []string
|
InviteCodes []string
|
||||||
|
|
||||||
|
|||||||
@@ -92,21 +92,34 @@ var moderationActionFactories = map[nostr.Kind]func(nostr.Event) (Action, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
y := true
|
y := true
|
||||||
if evt.Tags.Has("private") {
|
n := false
|
||||||
edit.PrivateValue = &y
|
|
||||||
ok = true
|
|
||||||
}
|
|
||||||
if evt.Tags.Has("closed") {
|
if evt.Tags.Has("closed") {
|
||||||
edit.ClosedValue = &y
|
edit.ClosedValue = &y
|
||||||
ok = true
|
ok = true
|
||||||
|
} else if evt.Tags.Has("open") {
|
||||||
|
edit.ClosedValue = &n
|
||||||
|
ok = true
|
||||||
}
|
}
|
||||||
if evt.Tags.Has("restricted") {
|
if evt.Tags.Has("restricted") {
|
||||||
edit.RestrictedValue = &y
|
edit.RestrictedValue = &y
|
||||||
ok = true
|
ok = true
|
||||||
|
} else if evt.Tags.Has("unrestricted") {
|
||||||
|
edit.RestrictedValue = &n
|
||||||
|
ok = true
|
||||||
}
|
}
|
||||||
if evt.Tags.Has("hidden") {
|
if evt.Tags.Has("hidden") {
|
||||||
edit.HiddenValue = &y
|
edit.HiddenValue = &y
|
||||||
ok = true
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
@@ -178,6 +191,7 @@ func (a PutUser) Apply(group *Group) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
roles = append(roles, group.GetRoleByName(roleName))
|
roles = append(roles, group.GetRoleByName(roleName))
|
||||||
|
group.LastAdminsUpdate = a.When
|
||||||
}
|
}
|
||||||
group.Members[target.PubKey] = roles
|
group.Members[target.PubKey] = roles
|
||||||
|
|
||||||
@@ -187,6 +201,8 @@ func (a PutUser) Apply(group *Group) {
|
|||||||
group.InviteCodes = group.InviteCodes[0 : len(group.InviteCodes)-1]
|
group.InviteCodes = group.InviteCodes[0 : len(group.InviteCodes)-1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
group.LastMembersUpdate = a.When
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,6 +214,13 @@ type RemoveUser struct {
|
|||||||
func (_ RemoveUser) Name() string { return "remove-user" }
|
func (_ RemoveUser) Name() string { return "remove-user" }
|
||||||
func (a RemoveUser) Apply(group *Group) {
|
func (a RemoveUser) Apply(group *Group) {
|
||||||
for _, tpk := range a.Targets {
|
for _, tpk := range a.Targets {
|
||||||
|
if roles, exists := group.Members[tpk]; exists {
|
||||||
|
group.LastMembersUpdate = a.When
|
||||||
|
if len(roles) > 0 {
|
||||||
|
group.LastAdminsUpdate = a.When
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
delete(group.Members, tpk)
|
delete(group.Members, tpk)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -206,10 +229,10 @@ type EditMetadata struct {
|
|||||||
NameValue *string
|
NameValue *string
|
||||||
PictureValue *string
|
PictureValue *string
|
||||||
AboutValue *string
|
AboutValue *string
|
||||||
PrivateValue *bool
|
|
||||||
RestrictedValue *bool
|
RestrictedValue *bool
|
||||||
HiddenValue *bool
|
|
||||||
ClosedValue *bool
|
ClosedValue *bool
|
||||||
|
HiddenValue *bool
|
||||||
|
PrivateValue *bool
|
||||||
When nostr.Timestamp
|
When nostr.Timestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,17 +248,17 @@ func (a EditMetadata) Apply(group *Group) {
|
|||||||
if a.AboutValue != nil {
|
if a.AboutValue != nil {
|
||||||
group.About = *a.AboutValue
|
group.About = *a.AboutValue
|
||||||
}
|
}
|
||||||
if a.PrivateValue != nil {
|
|
||||||
group.Private = *a.PrivateValue
|
|
||||||
}
|
|
||||||
if a.RestrictedValue != nil {
|
if a.RestrictedValue != nil {
|
||||||
group.Restricted = *a.RestrictedValue
|
group.Restricted = *a.RestrictedValue
|
||||||
}
|
}
|
||||||
|
if a.ClosedValue != nil {
|
||||||
|
group.Closed = *a.ClosedValue
|
||||||
|
}
|
||||||
if a.HiddenValue != nil {
|
if a.HiddenValue != nil {
|
||||||
group.Hidden = *a.HiddenValue
|
group.Hidden = *a.HiddenValue
|
||||||
}
|
}
|
||||||
if a.ClosedValue != nil {
|
if a.PrivateValue != nil {
|
||||||
group.Closed = *a.ClosedValue
|
group.Private = *a.PrivateValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user