mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
common: get note's locked status from its content
This commit is contained in:
@@ -66,12 +66,18 @@ export type NoteResolvedData = {
|
|||||||
async function resolveNotes(ids: string[]) {
|
async function resolveNotes(ids: string[]) {
|
||||||
const relations = [
|
const relations = [
|
||||||
...(await db.relations
|
...(await db.relations
|
||||||
.to({ type: "note", ids }, ["notebook", "tag", "color", "vault"])
|
.to({ type: "note", ids }, ["notebook", "tag", "color"])
|
||||||
.get()),
|
.get()),
|
||||||
...(await db.relations
|
...(await db.relations
|
||||||
.from({ type: "note", ids }, ["reminder", "attachment"])
|
.from({ type: "note", ids }, ["reminder", "attachment"])
|
||||||
.get())
|
.get())
|
||||||
];
|
];
|
||||||
|
const lockedReference = await db
|
||||||
|
.sql()
|
||||||
|
.selectFrom("content")
|
||||||
|
.where("noteId", "in", ids)
|
||||||
|
.select(["noteId", "locked"])
|
||||||
|
.execute();
|
||||||
|
|
||||||
const relationIds: {
|
const relationIds: {
|
||||||
notebooks: Set<string>;
|
notebooks: Set<string>;
|
||||||
@@ -91,11 +97,11 @@ async function resolveNotes(ids: string[]) {
|
|||||||
string,
|
string,
|
||||||
{
|
{
|
||||||
notebooks: string[];
|
notebooks: string[];
|
||||||
color: string;
|
color?: string;
|
||||||
tags: string[];
|
tags: string[];
|
||||||
reminders: string[];
|
reminders: string[];
|
||||||
attachments: string[];
|
attachments: string[];
|
||||||
locked: boolean;
|
locked?: boolean;
|
||||||
}
|
}
|
||||||
> = {};
|
> = {};
|
||||||
|
|
||||||
@@ -126,12 +132,21 @@ async function resolveNotes(ids: string[]) {
|
|||||||
} else if (relation.fromType === "color" && !data.color) {
|
} else if (relation.fromType === "color" && !data.color) {
|
||||||
data.color = relation.fromId;
|
data.color = relation.fromId;
|
||||||
relationIds.colors.add(relation.fromId);
|
relationIds.colors.add(relation.fromId);
|
||||||
} else if (relation.fromType === "vault") {
|
|
||||||
data.locked = true;
|
|
||||||
}
|
}
|
||||||
grouped[noteId] = data;
|
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 = {
|
const resolved = {
|
||||||
notebooks: await db.notebooks.all.records(
|
notebooks: await db.notebooks.all.records(
|
||||||
Array.from(relationIds.notebooks)
|
Array.from(relationIds.notebooks)
|
||||||
|
|||||||
Reference in New Issue
Block a user