common: get note's locked status from its content

This commit is contained in:
Abdullah Atta
2024-02-24 12:22:29 +05:00
parent b4542a532b
commit 613c1ca30f

View File

@@ -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<string>;
@@ -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)