Merge branch 'bugfix/255-add-thread-edition-validation' of github.com:soulcramer/notify.moe into soulcramer-bugfix/255-add-thread-edition-validation

This commit is contained in:
Eduard Urbach 2021-11-23 14:03:27 +09:00
commit dc9317b654
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0

View File

@ -125,6 +125,28 @@ func (thread *Thread) Create(ctx aero.Context) error {
// Edit creates an edit log entry.
func (thread *Thread) Edit(ctx aero.Context, key string, value reflect.Value, newValue reflect.Value) (consumed bool, err error) {
switch key {
case "Tags":
newTags := newValue.Interface().([]string)
if len(newTags) < 1 {
return true, errors.New("Need to specify at least one tag")
}
case "Title":
newTitle := newValue.String()
if len(newTitle) < 10 {
return true, errors.New("Title too short: Should be at least 10 characters")
}
case "Text":
newText := newValue.String()
if len(newText) < 10 {
return true, errors.New("Text too short: Should be at least 10 characters")
}
}
return edit(thread, ctx, key, value, newValue)
}