mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-24 07:29:30 +01:00
feat: add full support for localOnly items
This commit is contained in:
@@ -261,6 +261,21 @@ test("deleting a colored note should remove it from that color", () =>
|
||||
// TODO expect(color.noteIds.indexOf(id)).toBe(-1);
|
||||
}));
|
||||
|
||||
test("note's content should follow note's localOnly property", () =>
|
||||
noteTest().then(async ({ db, id }) => {
|
||||
await db.notes.note(id).localOnly();
|
||||
let note = db.notes.note(id);
|
||||
expect(note._note.localOnly).toBe(true);
|
||||
let content = await db.content.raw(note._note.contentId);
|
||||
expect(content.localOnly).toBe(true);
|
||||
|
||||
await db.notes.note(id).localOnly();
|
||||
note = db.notes.note(id);
|
||||
expect(note._note.localOnly).toBe(false);
|
||||
content = await db.content.raw(note._note.contentId);
|
||||
expect(content.localOnly).toBe(false);
|
||||
}));
|
||||
|
||||
test("grouping items where item.title is empty or undefined shouldn't throw", () => {
|
||||
expect(
|
||||
groupArray([{ title: "" }], {
|
||||
|
||||
@@ -43,11 +43,12 @@ test("note edited before last synced time should not get included in collector",
|
||||
expect(data.notes.length).toBe(0);
|
||||
}));
|
||||
|
||||
test("localOnly note should not get included in collector", () =>
|
||||
test("localOnly note should get included as a deleted item in collector", () =>
|
||||
databaseTest().then(async (db) => {
|
||||
await db.notes.add({ ...TEST_NOTE, localOnly: true });
|
||||
|
||||
const data = await db.syncer._collector.collect(0);
|
||||
|
||||
expect(data.notes.length).toBe(0);
|
||||
expect(data.notes.length).toBe(1);
|
||||
expect(data.notes[0].cipher.includes(`"deleted":true`)).toBe(true);
|
||||
}));
|
||||
|
||||
@@ -45,9 +45,15 @@ class Collector {
|
||||
_collect(array) {
|
||||
if (!array.length) return [];
|
||||
return array.reduce((prev, item) => {
|
||||
if (!item || item.localOnly) return prev;
|
||||
if (item.dateModified > this._lastSyncedTimestamp || item.migrated)
|
||||
if (!item) return prev;
|
||||
if (item.localOnly) {
|
||||
prev.push({ id: item.id, deleted: true });
|
||||
} else if (
|
||||
item.dateModified > this._lastSyncedTimestamp ||
|
||||
item.migrated
|
||||
) {
|
||||
prev.push(item);
|
||||
}
|
||||
return prev;
|
||||
}, []);
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ class Merger {
|
||||
async _mergeItem(remoteItem, get, add) {
|
||||
remoteItem = await this._deserialize(remoteItem);
|
||||
let localItem = await get(remoteItem.id);
|
||||
if (localItem.localOnly) return;
|
||||
|
||||
if (!localItem || remoteItem.dateModified > localItem.dateModified) {
|
||||
await add(remoteItem);
|
||||
@@ -64,6 +65,7 @@ class Merger {
|
||||
async _mergeItemWithConflicts(remoteItem, get, add, markAsConflicted) {
|
||||
remoteItem = await this._deserialize(remoteItem);
|
||||
let localItem = await get(remoteItem.id);
|
||||
if (localItem.localOnly) return;
|
||||
|
||||
if (!localItem) {
|
||||
await add(remoteItem);
|
||||
|
||||
@@ -21,7 +21,7 @@ export default class Content extends Collection {
|
||||
await this.extractAttachments(content)
|
||||
);
|
||||
|
||||
const oldContent = await this.raw(content.id, false);
|
||||
const oldContent = await this.raw(content.id);
|
||||
if (content.id && oldContent) {
|
||||
content = {
|
||||
...oldContent,
|
||||
|
||||
@@ -63,6 +63,13 @@ export default class Notes extends Collection {
|
||||
if (oldNote) note.dateEdited = Date.now();
|
||||
}
|
||||
|
||||
if (noteArg.localOnly !== undefined) {
|
||||
await this._db.content.add({
|
||||
id: note.contentId,
|
||||
localOnly: !!noteArg.localOnly,
|
||||
});
|
||||
}
|
||||
|
||||
const noteTitle = getNoteTitle(note, oldNote);
|
||||
if (oldNote && oldNote.title !== noteTitle) note.dateEdited = Date.now();
|
||||
|
||||
|
||||
@@ -163,6 +163,10 @@ export default class Note {
|
||||
return this._db.notes.add({ id: this._note.id, [prop]: !this._note[prop] });
|
||||
}
|
||||
|
||||
localOnly() {
|
||||
return this._toggle("localOnly");
|
||||
}
|
||||
|
||||
favorite() {
|
||||
return this._toggle("favorite");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user