Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

chore: update memo view activity

Steven7549c807acde
diff --git a/api/v1/activity.go b/api/v1/activity.go
index ff90bbf06..e667d8024 100644
--- a/api/v1/activity.go
+++ b/api/v1/activity.go
@@ -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 {
diff --git a/api/v1/common.go b/api/v1/common.go
index b8a18ebbb..a0b49bbcf 100644
--- a/api/v1/common.go
+++ b/api/v1/common.go
@@ -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
diff --git a/api/v1/memo.go b/api/v1/memo.go
index 7534dbb36..399721555 100644
--- a/api/v1/memo.go
+++ b/api/v1/memo.go
@@ -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,
diff --git a/server/server.go b/server/server.go
index 616860b4d..3781b6140 100644
--- a/server/server.go
+++ b/server/server.go
@@ -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")