[feature] Enable federation in/out of profile PropertyValue fields (#1722)

Co-authored-by: kim <grufwub@gmail.com>
Co-authored-by: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>
This commit is contained in:
tobi
2023-05-09 12:16:10 +02:00
committed by GitHub
parent cbb9e2d3f0
commit 0e29f1f5bb
180 changed files with 9278 additions and 1550 deletions

View File

@@ -25,6 +25,7 @@ import (
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/regexes"
pwv "github.com/wagslane/go-password-validator"
"golang.org/x/text/language"
@@ -43,7 +44,7 @@ const (
maximumCustomCSSLength = 5000
maximumEmojiCategoryLength = 64
maximumProfileFieldLength = 255
maximumProfileFields = 4
maximumProfileFields = 6
)
// NewPassword returns an error if the given password is not sufficiently strong, or nil if it's ok.
@@ -233,19 +234,26 @@ func ULID(i string) bool {
return regexes.ULID.MatchString(i)
}
func ProfileFieldsCount(fields []apimodel.UpdateField) error {
if length := len(fields); length > maximumProfileFields {
// ProfileFields validates the length of provided fields slice,
// and also iterates through the fields and trims each name + value
// to maximumProfileFieldLength, if they were above.
func ProfileFields(fields []*gtsmodel.Field) error {
if len(fields) > maximumProfileFields {
return fmt.Errorf("cannot have more than %d profile fields", maximumProfileFields)
}
// Trim each field name + value to maximum allowed length.
for _, field := range fields {
n := []rune(field.Name)
if len(n) > maximumProfileFieldLength {
field.Name = string(n[:maximumProfileFieldLength])
}
v := []rune(field.Value)
if len(v) > maximumProfileFieldLength {
field.Value = string(v[:maximumProfileFieldLength])
}
}
return nil
}
func ProfileField(f *string) string {
s := []rune(*f)
if len(s) > maximumProfileFieldLength {
return string(s[:maximumProfileFieldLength]) // trim profile field to maximum allowed length
}
return string(*f)
}