core: removeFromAllNotebooks should unlink notebook relations too

This commit is contained in:
Abdullah Atta
2023-03-17 14:40:13 +05:00
committed by Abdullah Atta
parent d7a126ab85
commit efc678d3cd
2 changed files with 15 additions and 1 deletions

View File

@@ -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();
}

View File

@@ -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