mirror of
https://github.com/usememos/memos.git
synced 2025-02-14 10:20:49 +01:00
chore: disable setting memo visibility when creating
This commit is contained in:
parent
05a5c59a7e
commit
3b1bb4a95d
@ -46,8 +46,8 @@ type MemoCreate struct {
|
||||
CreatedTs *int64 `json:"createdTs"`
|
||||
|
||||
// Domain specific fields
|
||||
Content string `json:"content"`
|
||||
Visibility *Visibility `json:"visibility"`
|
||||
Visibility Visibility
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
type MemoPatch struct {
|
||||
|
@ -22,11 +22,17 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
|
||||
}
|
||||
memoCreate := &api.MemoCreate{
|
||||
CreatorID: userID,
|
||||
// Private is the default memo visibility.
|
||||
Visibility: api.Privite,
|
||||
}
|
||||
if err := json.NewDecoder(c.Request().Body).Decode(memoCreate); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted post memo request").SetInternal(err)
|
||||
}
|
||||
|
||||
if memoCreate.Content == "" {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Memo content shouldn't be empty")
|
||||
}
|
||||
|
||||
userSettingMemoVisibilityKey := api.UserSettingMemoVisibilityKey
|
||||
userMemoVisibilitySetting, err := s.Store.FindUserSetting(ctx, &api.UserSettingFind{
|
||||
UserID: userID,
|
||||
@ -38,12 +44,7 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
|
||||
if userMemoVisibilitySetting != nil {
|
||||
memoVisibility := api.Privite
|
||||
json.Unmarshal([]byte(userMemoVisibilitySetting.Value), &memoVisibility)
|
||||
memoCreate.Visibility = &memoVisibility
|
||||
}
|
||||
|
||||
if memoCreate.Visibility == nil || *memoCreate.Visibility == "" {
|
||||
private := api.Privite
|
||||
memoCreate.Visibility = &private
|
||||
memoCreate.Visibility = memoVisibility
|
||||
}
|
||||
|
||||
memo, err := s.Store.CreateMemo(ctx, memoCreate)
|
||||
|
@ -201,13 +201,10 @@ func (s *Store) DeleteMemo(ctx context.Context, delete *api.MemoDelete) error {
|
||||
}
|
||||
|
||||
func createMemoRaw(ctx context.Context, tx *sql.Tx, create *api.MemoCreate) (*memoRaw, error) {
|
||||
set := []string{"creator_id", "content"}
|
||||
placeholder := []string{"?", "?"}
|
||||
args := []interface{}{create.CreatorID, create.Content}
|
||||
set := []string{"creator_id", "content", "visibility"}
|
||||
placeholder := []string{"?", "?", "?"}
|
||||
args := []interface{}{create.CreatorID, create.Content, create.Visibility}
|
||||
|
||||
if v := create.Visibility; v != nil {
|
||||
set, placeholder, args = append(set, "visibility"), append(placeholder, "?"), append(args, *v)
|
||||
}
|
||||
if v := create.CreatedTs; v != nil {
|
||||
set, placeholder, args = append(set, "created_ts"), append(placeholder, "?"), append(args, *v)
|
||||
}
|
||||
|
1
web/src/types/modules/memo.d.ts
vendored
1
web/src/types/modules/memo.d.ts
vendored
@ -17,7 +17,6 @@ interface Memo {
|
||||
|
||||
interface MemoCreate {
|
||||
content: string;
|
||||
visibility?: Visibility;
|
||||
createdTs?: TimeStamp;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user