mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
core: publish database updated events on content remove/update
This commit is contained in:
@@ -26,7 +26,9 @@ import {
|
|||||||
Attachment,
|
Attachment,
|
||||||
ContentItem,
|
ContentItem,
|
||||||
ContentType,
|
ContentType,
|
||||||
|
DeleteEvent,
|
||||||
UnencryptedContentItem,
|
UnencryptedContentItem,
|
||||||
|
UpdateEvent,
|
||||||
isDeleted
|
isDeleted
|
||||||
} from "../types";
|
} from "../types";
|
||||||
import Database from "../api";
|
import Database from "../api";
|
||||||
@@ -35,6 +37,7 @@ import { SQLCollection } from "../database/sql-collection";
|
|||||||
import { NoteContent } from "./session-content";
|
import { NoteContent } from "./session-content";
|
||||||
import { InternalLink } from "../utils/internal-link";
|
import { InternalLink } from "../utils/internal-link";
|
||||||
import { tinyToTiptap } from "../migrations";
|
import { tinyToTiptap } from "../migrations";
|
||||||
|
import { EVENTS } from "../common";
|
||||||
|
|
||||||
export const EMPTY_CONTENT = (noteId: string): UnencryptedContentItem => ({
|
export const EMPTY_CONTENT = (noteId: string): UnencryptedContentItem => ({
|
||||||
noteId,
|
noteId,
|
||||||
@@ -178,8 +181,8 @@ export class Content implements ICollection {
|
|||||||
return this.collection.softDelete(ids);
|
return this.collection.softDelete(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
removeByNoteId(...ids: string[]) {
|
async removeByNoteId(...ids: string[]) {
|
||||||
return this.db
|
await this.db
|
||||||
.sql()
|
.sql()
|
||||||
.replaceInto("content")
|
.replaceInto("content")
|
||||||
.columns(["id", "dateModified", "deleted"])
|
.columns(["id", "dateModified", "deleted"])
|
||||||
@@ -194,6 +197,12 @@ export class Content implements ICollection {
|
|||||||
])
|
])
|
||||||
)
|
)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
this.db.eventManager.publish(EVENTS.databaseUpdated, <DeleteEvent>{
|
||||||
|
collection: "content",
|
||||||
|
type: "softDelete",
|
||||||
|
ids
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateByNoteId(partial: Partial<ContentItem>, ...ids: string[]) {
|
async updateByNoteId(partial: Partial<ContentItem>, ...ids: string[]) {
|
||||||
@@ -206,6 +215,13 @@ export class Content implements ICollection {
|
|||||||
dateModified: Date.now()
|
dateModified: Date.now()
|
||||||
})
|
})
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
this.db.eventManager.publish(EVENTS.databaseUpdated, <UpdateEvent>{
|
||||||
|
collection: "content",
|
||||||
|
type: "update",
|
||||||
|
ids,
|
||||||
|
item: partial
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async findByNoteId(noteId: string) {
|
async findByNoteId(noteId: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user