From 613c1ca30f5cc4bd30121ccdc9b33b636bc164eb Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Sat, 24 Feb 2024 12:22:29 +0500 Subject: [PATCH] common: get note's locked status from its content --- packages/common/src/utils/resolve-items.ts | 25 +++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/common/src/utils/resolve-items.ts b/packages/common/src/utils/resolve-items.ts index b293f2187..3ef124bbd 100644 --- a/packages/common/src/utils/resolve-items.ts +++ b/packages/common/src/utils/resolve-items.ts @@ -66,12 +66,18 @@ export type NoteResolvedData = { async function resolveNotes(ids: string[]) { const relations = [ ...(await db.relations - .to({ type: "note", ids }, ["notebook", "tag", "color", "vault"]) + .to({ type: "note", ids }, ["notebook", "tag", "color"]) .get()), ...(await db.relations .from({ type: "note", ids }, ["reminder", "attachment"]) .get()) ]; + const lockedReference = await db + .sql() + .selectFrom("content") + .where("noteId", "in", ids) + .select(["noteId", "locked"]) + .execute(); const relationIds: { notebooks: Set; @@ -91,11 +97,11 @@ async function resolveNotes(ids: string[]) { string, { notebooks: string[]; - color: string; + color?: string; tags: string[]; reminders: string[]; attachments: string[]; - locked: boolean; + locked?: boolean; } > = {}; @@ -126,12 +132,21 @@ async function resolveNotes(ids: string[]) { } else if (relation.fromType === "color" && !data.color) { data.color = relation.fromId; relationIds.colors.add(relation.fromId); - } else if (relation.fromType === "vault") { - data.locked = true; } grouped[noteId] = data; } + for (const ref of lockedReference) { + if (!ref.noteId) continue; + grouped[ref.noteId] = grouped[ref.noteId] || { + attachments: [], + notebooks: [], + reminders: [], + tags: [] + }; + grouped[ref.noteId].locked = !!ref.locked; + } + const resolved = { notebooks: await db.notebooks.all.records( Array.from(relationIds.notebooks)