From de0c42faaf1a72f1e850f64bc720fd2e824f8cb8 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Sun, 3 Mar 2024 16:45:54 +0100 Subject: [PATCH] Implement "expires" and "not-before" for groups. --- README | 2 ++ group/description.go | 6 ++++++ group/group.go | 16 ++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/README b/README index fbc2418..af1ec64 100644 --- a/README +++ b/README @@ -157,6 +157,8 @@ nobody will be able to join the group. The following fields are allowed: a time; - `max-history-age`: the time, in seconds, during which chat history is kept (default 14400, i.e. 4 hours); + - `not-before` and `expires`: the times (in ISO 8601 or RFC 3339 format) + between which joining the group is allowed; - `allow-recording`: if true, then recording is allowed in this group; - `unrestricted-tokens`: if true, then ordinary users (without the "op" privilege) are allowed to create tokens; diff --git a/group/description.go b/group/description.go index a9b6b48..d2c704e 100644 --- a/group/description.go +++ b/group/description.go @@ -46,6 +46,12 @@ type Description struct { // The time for which history entries are kept. MaxHistoryAge int `json:"max-history-age,omitempty"` + // Time after which joining is no longer allowed + Expires *time.Time `json:"expires"` + + // Time before which joining is not allowed + NotBefore *time.Time `json:"not-before,omitempty"` + // Whether users are allowed to log in with an empty username. AllowAnonymous bool `json:"allow-anonymous,omitempty"` diff --git a/group/group.go b/group/group.go index d1a444c..27e2391 100644 --- a/group/group.go +++ b/group/group.go @@ -607,6 +607,22 @@ func AddClient(group string, c Client, creds ClientCredentials) (*Group, error) } return nil, UserError(m) } + if g.description.NotBefore != nil || + g.description.Expires != nil { + now := time.Now() + if g.description.NotBefore != nil && + g.description.NotBefore.After(now) { + return nil, UserError( + "this group is not open yet", + ) + } + if g.description.Expires != nil && + g.description.Expires.Before(now) { + return nil, UserError( + "this group is closed", + ) + } + } if g.description.Autokick { ops := false for _, c := range clients {