core: set conflicted property on notes after fetch is done

This commit is contained in:
Abdullah Atta
2024-05-14 15:20:09 +05:00
parent fe1ea6dc27
commit 5eea179a58
2 changed files with 17 additions and 9 deletions

View File

@@ -242,6 +242,19 @@ class Sync {
this.connection?.off("SendItems");
this.connection?.off("SendVaultKey");
await this.db
.sql()
.updateTable("notes")
.where("id", "in", (eb) =>
eb
.selectFrom("content")
.select("noteId as id")
.where("conflicted", "is not", null)
.$castTo<string | null>()
)
.set({ conflicted: true })
.execute();
}
async send(deviceId: string, isForceSync?: boolean) {
@@ -334,10 +347,8 @@ class Sync {
const localItems = await collection.records(chunk.items.map((i) => i.id));
let items: (MaybeDeletedItem<Item> | undefined)[] = [];
if (itemType === "content") {
items = await Promise.all(
deserialized.map((item) =>
this.merger.mergeContent(item, localItems[item.id])
)
items = deserialized.map((item) =>
this.merger.mergeContent(item, localItems[item.id])
);
} else {
items =

View File

@@ -46,7 +46,7 @@ class Merger {
}
}
async mergeContent(
mergeContent(
remoteItem: MaybeDeletedItem<Item>,
localItem: MaybeDeletedItem<Item> | undefined
) {
@@ -75,10 +75,7 @@ class Merger {
else if (!conflicted) return;
// otherwise we trigger the conflicts
await this.db.notes.add({
id: localItem.noteId,
conflicted: true
});
this.logger.info("conflict marked", { id: localItem.noteId });
localItem.conflicted = remoteItem;
return localItem;
}