From 3ee231e45903efa2dce3a5c5e3efaebcaed9f44a Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Thu, 14 Mar 2024 09:59:02 +0500 Subject: [PATCH] core: publish database updated events on content remove/update --- packages/core/src/collections/content.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/core/src/collections/content.ts b/packages/core/src/collections/content.ts index 986002f8f..9e579a7fa 100644 --- a/packages/core/src/collections/content.ts +++ b/packages/core/src/collections/content.ts @@ -26,7 +26,9 @@ import { Attachment, ContentItem, ContentType, + DeleteEvent, UnencryptedContentItem, + UpdateEvent, isDeleted } from "../types"; import Database from "../api"; @@ -35,6 +37,7 @@ import { SQLCollection } from "../database/sql-collection"; import { NoteContent } from "./session-content"; import { InternalLink } from "../utils/internal-link"; import { tinyToTiptap } from "../migrations"; +import { EVENTS } from "../common"; export const EMPTY_CONTENT = (noteId: string): UnencryptedContentItem => ({ noteId, @@ -178,8 +181,8 @@ export class Content implements ICollection { return this.collection.softDelete(ids); } - removeByNoteId(...ids: string[]) { - return this.db + async removeByNoteId(...ids: string[]) { + await this.db .sql() .replaceInto("content") .columns(["id", "dateModified", "deleted"]) @@ -194,6 +197,12 @@ export class Content implements ICollection { ]) ) .execute(); + + this.db.eventManager.publish(EVENTS.databaseUpdated, { + collection: "content", + type: "softDelete", + ids + }); } async updateByNoteId(partial: Partial, ...ids: string[]) { @@ -206,6 +215,13 @@ export class Content implements ICollection { dateModified: Date.now() }) .execute(); + + this.db.eventManager.publish(EVENTS.databaseUpdated, { + collection: "content", + type: "update", + ids, + item: partial + }); } async findByNoteId(noteId: string) {