chore: update memo display time (#327)

* chore: update memo display time

* chore: update
This commit is contained in:
boojack
2022-10-21 20:26:00 +08:00
committed by GitHub
parent b68d6e2693
commit 2a4fc7dcc3
17 changed files with 59 additions and 73 deletions

View File

@@ -16,8 +16,8 @@ const (
UserSettingEditorFontStyleKey UserSettingKey = "editorFontStyle"
// UserSettingEditorFontStyleKey is the key type for mobile editor style.
UserSettingMobileEditorStyleKey UserSettingKey = "mobileEditorStyle"
// UserSettingMemoSortOptionKey is the key type for memo sort option.
UserSettingMemoSortOptionKey UserSettingKey = "memoSortOption"
// UserSettingMemoDisplayTsOptionKey is the key type for memo display ts option.
UserSettingMemoDisplayTsOptionKey UserSettingKey = "memoSortOption"
)
// String returns the string format of UserSettingKey type.
@@ -31,18 +31,18 @@ func (key UserSettingKey) String() string {
return "editorFontFamily"
case UserSettingMobileEditorStyleKey:
return "mobileEditorStyle"
case UserSettingMemoSortOptionKey:
return "memoSortOption"
case UserSettingMemoDisplayTsOptionKey:
return "memoDisplayTsOption"
}
return ""
}
var (
UserSettingLocaleValue = []string{"en", "zh", "vi"}
UserSettingMemoVisibilityValue = []Visibility{Privite, Protected, Public}
UserSettingEditorFontStyleValue = []string{"normal", "mono"}
UserSettingMobileEditorStyleValue = []string{"normal", "float"}
UserSettingMemoSortOptionKeyValue = []string{"created_ts", "updated_ts"}
UserSettingLocaleValue = []string{"en", "zh", "vi"}
UserSettingMemoVisibilityValue = []Visibility{Privite, Protected, Public}
UserSettingEditorFontStyleValue = []string{"normal", "mono"}
UserSettingMobileEditorStyleValue = []string{"normal", "float"}
UserSettingMemoDisplayTsOptionKeyValue = []string{"created_ts", "updated_ts"}
)
type UserSetting struct {
@@ -127,22 +127,22 @@ func (upsert UserSettingUpsert) Validate() error {
if invalid {
return fmt.Errorf("invalid user setting mobile editor style value")
}
} else if upsert.Key == UserSettingMemoSortOptionKey {
memoSortOption := "created_ts"
err := json.Unmarshal([]byte(upsert.Value), &memoSortOption)
} else if upsert.Key == UserSettingMemoDisplayTsOptionKey {
memoDisplayTsOption := "created_ts"
err := json.Unmarshal([]byte(upsert.Value), &memoDisplayTsOption)
if err != nil {
return fmt.Errorf("failed to unmarshal user setting memo sort option")
return fmt.Errorf("failed to unmarshal user setting memo display ts option")
}
invalid := true
for _, value := range UserSettingMemoSortOptionKeyValue {
if memoSortOption == value {
for _, value := range UserSettingMemoDisplayTsOptionKeyValue {
if memoDisplayTsOption == value {
invalid = false
break
}
}
if invalid {
return fmt.Errorf("invalid user setting memo sort option value")
return fmt.Errorf("invalid user setting memo display ts option value")
}
} else {
return fmt.Errorf("invalid user setting key")