diff options
Diffstat (limited to 'internal/validate/formvalidation.go')
-rw-r--r-- | internal/validate/formvalidation.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/internal/validate/formvalidation.go b/internal/validate/formvalidation.go index 20d4aa782..f9328dc1f 100644 --- a/internal/validate/formvalidation.go +++ b/internal/validate/formvalidation.go @@ -45,6 +45,7 @@ const ( maximumEmojiCategoryLength = 64 maximumProfileFieldLength = 255 maximumProfileFields = 6 + maximumListTitleLength = 200 ) // NewPassword returns an error if the given password is not sufficiently strong, or nil if it's ok. @@ -257,3 +258,28 @@ func ProfileFields(fields []*gtsmodel.Field) error { return nil } + +// ListTitle validates the title of a new or updated List. +func ListTitle(title string) error { + if title == "" { + return fmt.Errorf("list title must be provided, and must be no more than %d chars", maximumListTitleLength) + } + + if length := len([]rune(title)); length > maximumListTitleLength { + return fmt.Errorf("list title length must be no more than %d chars, provided title was %d chars", maximumListTitleLength, length) + } + + return nil +} + +// ListRepliesPolicy validates the replies_policy of a new or updated list. +func ListRepliesPolicy(repliesPolicy gtsmodel.RepliesPolicy) error { + switch repliesPolicy { + case "", gtsmodel.RepliesPolicyFollowed, gtsmodel.RepliesPolicyList, gtsmodel.RepliesPolicyNone: + // No problem. + return nil + default: + // Uh oh. + return fmt.Errorf("list replies_policy must be either empty or one of 'followed', 'list', 'none'") + } +} |