Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

core: `removeFromAllNotebooks` should unlink notebook relations too

Abdullah Attaefc678d3cdba
diff --git a/packages/core/collections/notes.js b/packages/core/collections/notes.js
index 66f649db9..b067456d2 100644
--- a/packages/core/collections/notes.js
+++ b/packages/core/collections/notes.js
@@ -374,7 +374,7 @@ export default class Notes extends Collection {
async removeFromAllNotebooks(...noteIds) {
for (const noteId of noteIds) {
const note = this.note(noteId);
- if (!note || note.deleted || !note.notebooks) {
+ if (!note || note.deleted) {
continue;
}
@@ -382,6 +382,7 @@ export default class Notes extends Collection {
id: noteId,
notebooks: []
});
+ await this._db.relations.unlinkAll(note.data, "notebook");
}
this.topicReferences.rebuild();
}
diff --git a/packages/core/collections/relations.js b/packages/core/collections/relations.js
index e12f91c21..9dec64252 100644
--- a/packages/core/collections/relations.js
+++ b/packages/core/collections/relations.js
@@ -142,6 +142,19 @@ export default class Relations extends Collection {
await this.remove(relation.id);
}
+ /**
+ *
+ * @param {ItemReference} from
+ * @param {string} type
+ */
+ async unlinkAll(to, type) {
+ for (const relation of this.all.filter(
+ (a) => compareItemReference(a.to, to) && a.from.type === type
+ )) {
+ await this.remove(relation.id);
+ }
+ }
+
/**
* @param {Relation[]} relations
* @param {"from" | "to"} resolveType