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: only show comments in memo detail page

Stevenb938c8d7b65d
diff --git a/api/v1/memo.go b/api/v1/memo.go
index 73d56ea89..ddd434111 100644
--- a/api/v1/memo.go
+++ b/api/v1/memo.go
@@ -144,7 +144,10 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
// @Router /api/v1/memo [GET]
func (s *APIV1Service) GetMemoList(c echo.Context) error {
ctx := c.Request().Context()
- findMemoMessage := &store.FindMemo{}
+ hasParentFlag := false
+ findMemoMessage := &store.FindMemo{
+ HasParent: &hasParentFlag,
+ }
if userID, err := util.ConvertStringToInt32(c.QueryParam("creatorId")); err == nil {
findMemoMessage.CreatorID = &userID
}
@@ -404,7 +407,10 @@ func (s *APIV1Service) CreateMemo(c echo.Context) error {
// - creatorUsername is listed at ./web/src/helpers/api.ts:82, but it's not present here
func (s *APIV1Service) GetAllMemos(c echo.Context) error {
ctx := c.Request().Context()
- findMemoMessage := &store.FindMemo{}
+ hasParentFlag := false
+ findMemoMessage := &store.FindMemo{
+ HasParent: &hasParentFlag,
+ }
_, ok := c.Get(userIDContextKey).(int32)
if !ok {
findMemoMessage.VisibilityList = []store.Visibility{store.Public}
@@ -461,8 +467,10 @@ func (s *APIV1Service) GetAllMemos(c echo.Context) error {
func (s *APIV1Service) GetMemoStats(c echo.Context) error {
ctx := c.Request().Context()
normalStatus := store.Normal
+ hasParentFlag := false
findMemoMessage := &store.FindMemo{
RowStatus: &normalStatus,
+ HasParent: &hasParentFlag,
}
if creatorID, err := util.ConvertStringToInt32(c.QueryParam("creatorId")); err == nil {
findMemoMessage.CreatorID = &creatorID
diff --git a/store/db/sqlite/memo.go b/store/db/sqlite/memo.go
index a864a22cf..d02153916 100644
--- a/store/db/sqlite/memo.go
+++ b/store/db/sqlite/memo.go
@@ -65,9 +65,6 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
if v := find.CreatedTsAfter; v != nil {
where, args = append(where, "memo.created_ts > ?"), append(args, *v)
}
- if v := find.Pinned; v != nil {
- where = append(where, "memo_organizer.pinned = 1")
- }
if v := find.ContentSearch; len(v) != 0 {
for _, s := range v {
where, args = append(where, "memo.content LIKE ?"), append(args, "%"+s+"%")
@@ -81,6 +78,17 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
}
where = append(where, fmt.Sprintf("memo.visibility in (%s)", strings.Join(list, ",")))
}
+ if v := find.Pinned; v != nil {
+ where = append(where, "memo_organizer.pinned = 1")
+ }
+ if v := find.HasParent; v != nil {
+ if *v {
+ where = append(where, "parent_id IS NOT NULL")
+ } else {
+ where = append(where, "parent_id IS NULL")
+ }
+ }
+
orders := []string{"pinned DESC"}
if find.OrderByUpdatedTs {
orders = append(orders, "updated_ts DESC")
@@ -99,6 +107,15 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
memo.content AS content,
memo.visibility AS visibility,
CASE WHEN memo_organizer.pinned = 1 THEN 1 ELSE 0 END AS pinned,
+ (
+ SELECT
+ related_memo_id
+ FROM
+ memo_relation
+ WHERE
+ memo_relation.memo_id = memo.id AND memo_relation.type = 'COMMENT'
+ LIMIT 1
+ ) AS parent_id,
GROUP_CONCAT(resource.id) AS resource_id_list,
(
SELECT
@@ -145,6 +162,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
&memo.Content,
&memo.Visibility,
&memo.Pinned,
+ &memo.ParentID,
&memoResourceIDList,
&memoRelationList,
); err != nil {
@@ -184,10 +202,6 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
RelatedMemoID: relatedMemoID,
Type: relationType,
})
- // Set the first parent ID if relation type is comment.
- if memo.ParentID == nil && memoID == memo.ID && relationType == store.MemoRelationComment {
- memo.ParentID = &relatedMemoID
- }
}
}
list = append(list, &memo)
diff --git a/store/memo.go b/store/memo.go
index 338d6c4e6..e5afa05bb 100644
--- a/store/memo.go
+++ b/store/memo.go
@@ -60,9 +60,10 @@ type FindMemo struct {
CreatedTsBefore *int64
// Domain specific fields
- Pinned *bool
ContentSearch []string
VisibilityList []Visibility
+ Pinned *bool
+ HasParent *bool
// Pagination
Limit *int
diff --git a/web/src/components/Memo.tsx b/web/src/components/Memo.tsx
index d251dcd83..bad0ef10d 100644
--- a/web/src/components/Memo.tsx
+++ b/web/src/components/Memo.tsx
@@ -245,18 +245,26 @@ const Memo: React.FC<Props> = (props: Props) => {
</span>
<div className="more-action-btns-wrapper">
<div className="more-action-btns-container min-w-[6em]">
- <span className="btn" onClick={handleTogglePinMemoBtnClick}>
- {memo.pinned ? <Icon.BookmarkMinus className="w-4 h-auto mr-2" /> : <Icon.BookmarkPlus className="w-4 h-auto mr-2" />}
- {memo.pinned ? t("common.unpin") : t("common.pin")}
- </span>
+ {!memo.parent && (
+ <span className="btn" onClick={handleTogglePinMemoBtnClick}>
+ {memo.pinned ? (
+ <Icon.BookmarkMinus className="w-4 h-auto mr-2" />
+ ) : (
+ <Icon.BookmarkPlus className="w-4 h-auto mr-2" />
+ )}
+ {memo.pinned ? t("common.unpin") : t("common.pin")}
+ </span>
+ )}
<span className="btn" onClick={handleEditMemoClick}>
<Icon.Edit3 className="w-4 h-auto mr-2" />
{t("common.edit")}
</span>
- <span className="btn" onClick={handleMarkMemoClick}>
- <Icon.Link className="w-4 h-auto mr-2" />
- {t("common.mark")}
- </span>
+ {!memo.parent && (
+ <span className="btn" onClick={handleMarkMemoClick}>
+ <Icon.Link className="w-4 h-auto mr-2" />
+ {t("common.mark")}
+ </span>
+ )}
<Divider className="!my-1" />
<span className="btn text-orange-500" onClick={handleArchiveMemoClick}>
<Icon.Archive className="w-4 h-auto mr-2" />
@@ -290,12 +298,6 @@ const Memo: React.FC<Props> = (props: Props) => {
<div className="flex flex-row justify-start items-center">
{creator && (
<>
- <Link className="flex flex-row justify-start items-center" to={`/m/${memo.id}`}>
- <Tooltip title={"Identifier"} placement="top">
- <span className="text-sm text-gray-500 dark:text-gray-400">#{memo.id}</span>
- </Tooltip>
- </Link>
- <Icon.Dot className="w-4 h-auto text-gray-400 dark:text-zinc-400" />
<Link to={`/u/${encodeURIComponent(memo.creatorUsername)}`}>
<Tooltip title={"Creator"} placement="top">
<span className="flex flex-row justify-start items-center">
diff --git a/web/src/components/MemoList.tsx b/web/src/components/MemoList.tsx
index e48ab522b..345a55119 100644
--- a/web/src/components/MemoList.tsx
+++ b/web/src/components/MemoList.tsx
@@ -63,7 +63,7 @@ const MemoList: React.FC = () => {
return shouldShow;
})
: memos
- ).filter((memo) => memo.creatorUsername === username && memo.rowStatus === "NORMAL");
+ ).filter((memo) => memo.creatorUsername === username && memo.rowStatus === "NORMAL" && !memo.parent);
const pinnedMemos = shownMemos.filter((m) => m.pinned);
const unpinnedMemos = shownMemos.filter((m) => !m.pinned);
diff --git a/web/src/components/MemoResource.tsx b/web/src/components/MemoResource.tsx
index 52e8c918f..c5ef9299b 100644
--- a/web/src/components/MemoResource.tsx
+++ b/web/src/components/MemoResource.tsx
@@ -16,22 +16,18 @@ const MemoResource: React.FC<Props> = (props: Props) => {
};
return (
- <>
- <div className={`w-auto flex flex-row justify-start items-center text-gray-500 dark:text-gray-400 hover:opacity-80 ${className}`}>
- {resource.type.startsWith("audio") ? (
- <>
- <audio src={resourceUrl} controls></audio>
- </>
- ) : (
- <>
- <ResourceIcon className="!w-4 !h-4 mr-1" resource={resource} />
- <span className="text-sm max-w-[256px] truncate cursor-pointer" onClick={handlePreviewBtnClick}>
- {resource.filename}
- </span>
- </>
- )}
- </div>
- </>
+ <div className={`w-auto flex flex-row justify-start items-center text-gray-500 dark:text-gray-400 hover:opacity-80 ${className}`}>
+ {resource.type.startsWith("audio") ? (
+ <audio src={resourceUrl} controls></audio>
+ ) : (
+ <>
+ <ResourceIcon className="!w-4 !h-4 mr-1" resource={resource} />
+ <span className="text-sm max-w-[256px] truncate cursor-pointer" onClick={handlePreviewBtnClick}>
+ {resource.filename}
+ </span>
+ </>
+ )}
+ </div>
);
};
diff --git a/web/src/pages/Explore.tsx b/web/src/pages/Explore.tsx
index 706fec61f..a2cfe66d8 100644
--- a/web/src/pages/Explore.tsx
+++ b/web/src/pages/Explore.tsx
@@ -54,7 +54,7 @@ const Explore = () => {
: memos;
const sortedMemos = fetchedMemos
- .filter((m) => m.rowStatus === "NORMAL" && m.visibility !== "PRIVATE")
+ .filter((m) => m.rowStatus === "NORMAL" && m.visibility !== "PRIVATE" && !m.parent)
.sort((mi, mj) => mj.displayTs - mi.displayTs);
useEffect(() => {
diff --git a/web/src/pages/MemoDetail.tsx b/web/src/pages/MemoDetail.tsx
index f580624b2..19671ca92 100644
--- a/web/src/pages/MemoDetail.tsx
+++ b/web/src/pages/MemoDetail.tsx
@@ -114,6 +114,10 @@ const MemoDetail = () => {
<div className="relative flex-grow max-w-2xl w-full min-h-full flex flex-col justify-start items-start px-4 pb-6">
<div className="w-full mb-4 flex flex-row justify-start items-center mr-1">
<span className="text-gray-400 select-none">{getDateTimeString(memo.displayTs)}</span>
+ <Icon.Dot className="w-4 h-auto text-gray-400 dark:text-zinc-400" />
+ <Tooltip title={"Identifier"} placement="top">
+ <span className="text-gray-400 dark:text-gray-400">#{memo.id}</span>
+ </Tooltip>
</div>
{memo.parent && (
<div className="mb-2">
@@ -127,10 +131,6 @@ const MemoDetail = () => {
<MemoRelationListView relationList={referenceRelations} />
<div className="w-full mt-4 flex flex-col sm:flex-row justify-start sm:justify-between sm:items-center gap-2">
<div className="flex flex-row justify-start items-center">
- <Tooltip title={"Identifier"} placement="top">
- <span className="text-sm text-gray-500 dark:text-gray-400">#{memo.id}</span>
- </Tooltip>
- <Icon.Dot className="w-4 h-auto text-gray-400 dark:text-zinc-400" />
<Link to={`/u/${encodeURIComponent(memo.creatorUsername)}`}>
<Tooltip title={"Creator"} placement="top">
<span className="flex flex-row justify-start items-center">