diff --git a/packages/lib/models/Note.ts b/packages/lib/models/Note.ts index 46717db9d..4f3fd3a38 100644 --- a/packages/lib/models/Note.ts +++ b/packages/lib/models/Note.ts @@ -502,7 +502,7 @@ export default class Note extends BaseItem { note.longitude = geoData.coords.longitude; note.latitude = geoData.coords.latitude; note.altitude = geoData.coords.altitude; - return Note.save(note); + return Note.save(note, { ignoreProvisionalFlag: true }); } static filter(note: NoteEntity) { @@ -626,7 +626,16 @@ export default class Note extends BaseItem { static async save(o: NoteEntity, options: any = null) { const isNew = this.isNew(o, options); + + // If true, this is a provisional note - it will be saved permanently + // only if the user makes changes to it. const isProvisional = options && !!options.provisional; + + // If true, saving the note will not change the provisional flag of the + // note. This is used for background processing that it not initiated by + // the user. For example when setting the geolocation of a note. + const ignoreProvisionalFlag = options && !!options.ignoreProvisionalFlag; + const dispatchUpdateAction = options ? options.dispatchUpdateAction !== false : true; if (isNew && !o.source) o.source = Setting.value('appName'); if (isNew && !o.source_application) o.source_application = Setting.value('appId'); @@ -672,6 +681,7 @@ export default class Note extends BaseItem { type: 'NOTE_UPDATE_ONE', note: note, provisional: isProvisional, + ignoreProvisionalFlag: ignoreProvisionalFlag, changedFields: changedFields, }); } diff --git a/packages/lib/reducer.ts b/packages/lib/reducer.ts index f943174ab..8f12ee131 100644 --- a/packages/lib/reducer.ts +++ b/packages/lib/reducer.ts @@ -833,21 +833,22 @@ const reducer = produce((draft: Draft = defaultState, action: any) => { draft.selectedNoteIds = newIndex >= 0 ? [newNotes[newIndex].id] : []; } - let newProvisionalNoteIds = draft.provisionalNoteIds; + if (!action.ignoreProvisionalFlag) { + let newProvisionalNoteIds = draft.provisionalNoteIds; - if (action.provisional) { - newProvisionalNoteIds = newProvisionalNoteIds.slice(); - newProvisionalNoteIds.push(modNote.id); - } else { - const idx = newProvisionalNoteIds.indexOf(modNote.id); - if (idx >= 0) { + if (action.provisional) { newProvisionalNoteIds = newProvisionalNoteIds.slice(); - newProvisionalNoteIds.splice(idx, 1); - + newProvisionalNoteIds.push(modNote.id); + } else { + const idx = newProvisionalNoteIds.indexOf(modNote.id); + if (idx >= 0) { + newProvisionalNoteIds = newProvisionalNoteIds.slice(); + newProvisionalNoteIds.splice(idx, 1); + } } - } - draft.provisionalNoteIds = newProvisionalNoteIds; + draft.provisionalNoteIds = newProvisionalNoteIds; + } } break;