mirror of
https://github.com/usememos/memos.git
synced 2024-12-24 22:23:01 +08:00
chore: update memo view activity
This commit is contained in:
parent
de5eccf9d6
commit
7549c807ac
4 changed files with 35 additions and 11 deletions
|
@ -25,6 +25,8 @@ const (
|
|||
|
||||
// ActivityMemoCreate is the type for creating memos.
|
||||
ActivityMemoCreate ActivityType = "memo.create"
|
||||
// ActivityMemoView is the type for viewing memos.
|
||||
ActivityMemoView ActivityType = "memo.view"
|
||||
// ActivityMemoUpdate is the type for updating memos.
|
||||
ActivityMemoUpdate ActivityType = "memo.update"
|
||||
// ActivityMemoDelete is the type for deleting memos.
|
||||
|
@ -87,8 +89,11 @@ type ActivityUserAuthSignUpPayload struct {
|
|||
}
|
||||
|
||||
type ActivityMemoCreatePayload struct {
|
||||
Content string `json:"content"`
|
||||
Visibility string `json:"visibility"`
|
||||
MemoID int32 `json:"memoId"`
|
||||
}
|
||||
|
||||
type ActivityMemoViewPayload struct {
|
||||
MemoID int32 `json:"memoId"`
|
||||
}
|
||||
|
||||
type ActivityResourceCreatePayload struct {
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package v1
|
||||
|
||||
// UnknownID is the ID for unknowns.
|
||||
const UnknownID = -1
|
||||
|
||||
// RowStatus is the status for a row.
|
||||
type RowStatus string
|
||||
|
||||
|
|
|
@ -555,6 +555,9 @@ func (s *APIV1Service) GetMemo(c echo.Context) error {
|
|||
return echo.NewHTTPError(http.StatusForbidden, "this memo is protected, missing user in session")
|
||||
}
|
||||
}
|
||||
if err := s.createMemoViewActivity(c, memo, userID); err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create activity").SetInternal(err)
|
||||
}
|
||||
memoResponse, err := s.convertMemoFromStore(ctx, memo)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to compose memo response").SetInternal(err)
|
||||
|
@ -753,8 +756,7 @@ func (s *APIV1Service) UpdateMemo(c echo.Context) error {
|
|||
|
||||
func (s *APIV1Service) createMemoCreateActivity(ctx context.Context, memo *store.Memo) error {
|
||||
payload := ActivityMemoCreatePayload{
|
||||
Content: memo.Content,
|
||||
Visibility: memo.Visibility.String(),
|
||||
MemoID: memo.ID,
|
||||
}
|
||||
payloadBytes, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
|
@ -772,6 +774,27 @@ func (s *APIV1Service) createMemoCreateActivity(ctx context.Context, memo *store
|
|||
return err
|
||||
}
|
||||
|
||||
func (s *APIV1Service) createMemoViewActivity(c echo.Context, memo *store.Memo, userID int32) error {
|
||||
ctx := c.Request().Context()
|
||||
payload := ActivityMemoViewPayload{
|
||||
MemoID: memo.ID,
|
||||
}
|
||||
payloadBytes, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to marshal activity payload")
|
||||
}
|
||||
activity, err := s.Store.CreateActivity(ctx, &store.Activity{
|
||||
CreatorID: userID,
|
||||
Type: string(ActivityMemoView),
|
||||
Level: string(ActivityInfo),
|
||||
Payload: string(payloadBytes),
|
||||
})
|
||||
if err != nil || activity == nil {
|
||||
return errors.Wrap(err, "failed to create activity")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Memo) (*Memo, error) {
|
||||
memoResponse := &Memo{
|
||||
ID: memo.ID,
|
||||
|
|
|
@ -221,10 +221,9 @@ func (s *Server) createServerStartActivity(ctx context.Context) error {
|
|||
return errors.Wrap(err, "failed to marshal activity payload")
|
||||
}
|
||||
activity, err := s.Store.CreateActivity(ctx, &store.Activity{
|
||||
CreatorID: apiv1.UnknownID,
|
||||
Type: apiv1.ActivityServerStart.String(),
|
||||
Level: apiv1.ActivityInfo.String(),
|
||||
Payload: string(payloadBytes),
|
||||
Type: apiv1.ActivityServerStart.String(),
|
||||
Level: apiv1.ActivityInfo.String(),
|
||||
Payload: string(payloadBytes),
|
||||
})
|
||||
if err != nil || activity == nil {
|
||||
return errors.Wrap(err, "failed to create activity")
|
||||
|
|
Loading…
Reference in a new issue