Skip to content

Commit

Permalink
fix: If no text is provided, means user delete the text on the Deskto…
Browse files Browse the repository at this point in the history
…p. But not deleting this tiddler

fixes #18
  • Loading branch information
linonetwo committed Sep 11, 2023
1 parent d7a4e72 commit 7ac5389
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/services/BackgroundSyncService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ export class BackgroundSyncService {
},
body: JSON.stringify(request),
}).then(response => response.json() as Promise<ISyncEndPointResponse>);
// DEBUG: console request
console.log(`request`, request);
// DEBUG: console response
console.log(`response`, response);
if (response === undefined) return false;
const { deletes, updates } = response;
await this.#updateTiddlersFromServer(wiki, deletes, updates);
Expand Down Expand Up @@ -224,21 +228,22 @@ export class BackgroundSyncService {

// Update Tiddlers
for (const tiddlerFields of updates) {
let { text, title, ...fieldsToSave } = tiddlerFields as ITiddlerFieldsParam & { text?: string; title: string };
const { text, title, ...fieldsToSave } = tiddlerFields as ITiddlerFieldsParam & { text?: string; title: string };
const ignore = getSyncIgnoredTiddlers(title).includes(title);
if (ignore) continue;
const saveFullTiddler = getFullSaveTiddlers(title).includes(title);

// If no text is provided, fetch from existing tiddler. This should not happened in tw-mobile-sync, just in case.
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (!text) {
const existingTiddler = await tiddlerRepo.findOne({ where: { title } });
if (existingTiddler === null) {
console.warn(`Cannot find text for tiddler ${title}`);
} else {
text = existingTiddler.text ?? '';
}
}
// If no text is provided, means user delete the text on the Desktop. But not deleting this tiddler. fixes #18
// // If no text is provided, fetch from existing tiddler. This should not happened in tw-mobile-sync, just in case.
// // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
// if (!text) {
// const existingTiddler = await tiddlerRepo.findOne({ where: { title } });
// if (existingTiddler === null) {
// console.warn(`Cannot find text for tiddler ${title}`);
// } else {
// text = existingTiddler.text ?? '';
// }
// }

const tiddler = new TiddlerSQLModel();
tiddler.title = title;
Expand Down

0 comments on commit 7ac5389

Please sign in to comment.