From f5c004d67d4ed66b6c6df100afec47174aa14ae0 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Thu, 25 May 2023 10:37:38 +0200 Subject: [feature] Add List functionality (#1802) * start working on lists * further list work * test list db functions nicely * more work on lists * peepoopeepoo * poke * start list timeline func * we're getting there lads * couldn't be me working on stuff... could it? * hook up handlers * fiddling * weeee * woah * screaming, pissing * fix streaming being a whiny baby * lint, small test fix, swagger * tidying up, testing * fucked! by the linter * move timelines to state like a boss * add timeline start to tests using state * invalidate lists --- internal/validate/formvalidation.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'internal/validate/formvalidation.go') 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'") + } +} -- cgit v1.2.3