diff --git a/app/assets/javascripts/ui_models/app_state/notes_state.ts b/app/assets/javascripts/ui_models/app_state/notes_state.ts index 9b5bd3e37..785dba98b 100644 --- a/app/assets/javascripts/ui_models/app_state/notes_state.ts +++ b/app/assets/javascripts/ui_models/app_state/notes_state.ts @@ -7,6 +7,7 @@ import { NoteMutator, ContentType, SNTag, + ChallengeReason, } from '@standardnotes/snjs'; import { makeObservable, @@ -84,23 +85,6 @@ export class NotesState { return this.application.getTrashedItems().length; } - async runProtectedAction(action: (note: SNNote) => void, notes: SNNote[]): Promise { - let protectedNotesAccessRequest: Promise; - await Promise.all( - notes.map(async (note) => { - if (note.protected) { - if (!protectedNotesAccessRequest) { - protectedNotesAccessRequest = - this.application.authorizeNoteAccess(note); - } - } - if (!note.protected || await protectedNotesAccessRequest) { - action(note); - } - }) - ); - } - async selectNotesRange(selectedNote: SNNote): Promise { const notes = this.application.getDisplayableItems( ContentType.Note @@ -119,10 +103,16 @@ export class NotesState { notesToSelect = notes.slice(selectedNoteIndex, lastSelectedNoteIndex + 1); } - this.runProtectedAction((note) => { + const authorizedNotes = + await this.application.authorizeProtectedActionForNotes( + notesToSelect, + ChallengeReason.SelectProtectedNote + ); + + for (const note of authorizedNotes) { this.selectedNotes[note.uuid] = note; - this.lastSelectedNote = selectedNote; - }, notesToSelect); + this.lastSelectedNote = note; + } } async selectNote(uuid: UuidString): Promise { @@ -308,20 +298,14 @@ export class NotesState { } async setProtectSelectedNotes(protect: boolean): Promise { + const selectedNotes = Object.values(this.selectedNotes); if (protect) { - await this.changeSelectedNotes((mutator) => { - mutator.protected = protect; - }); + await this.application.protectNotes(selectedNotes); if (!this.application.hasProtectionSources()) { this.setShowProtectedWarning(true); } } else { - const selectedNotes = Object.values(this.selectedNotes); - this.runProtectedAction(async (note) => { - await this.application.changeItem(note.uuid, (mutator) => { - mutator.protected = protect; - }); - }, selectedNotes); + await this.application.unprotectNotes(selectedNotes); this.setShowProtectedWarning(false); } } diff --git a/package.json b/package.json index d79e06a27..913df3acd 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,7 @@ "@reach/checkbox": "^0.13.2", "@reach/dialog": "^0.13.0", "@standardnotes/sncrypto-web": "1.2.10", - "@standardnotes/snjs": "2.1.1", + "@standardnotes/snjs": "2.2.0", "mobx": "^6.1.6", "mobx-react-lite": "^3.2.0", "preact": "^10.5.12" diff --git a/yarn.lock b/yarn.lock index 304e348aa..049b05cb9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1936,10 +1936,10 @@ "@standardnotes/sncrypto-common" "^1.2.7" libsodium-wrappers "^0.7.8" -"@standardnotes/snjs@2.1.1": - version "2.1.1" - resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.1.1.tgz#789bb492e76ee4fe5816ed0de01c9b774244034d" - integrity sha512-GeOPZGX5K2YBdzIWVmS/z4wdQJLLz4Yo2lje8rjep2eLlUiQhRO5BVWaOroYq0uaIamtfSr8m+twbYUkCkPSIQ== +"@standardnotes/snjs@2.2.0": + version "2.2.0" + resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.2.0.tgz#40a9b840cb2697ad5b2901f4b36767e058a9a259" + integrity sha512-VWyjDXZQXFOTFIfCIbCr/4wzcNgoUcpiQRV8eux5NOtZrOZ+buh2H1Mob5hi1Hmgg7wtRS3b1HPf2nx3sRap2Q== dependencies: "@standardnotes/auth" "^2.0.0" "@standardnotes/sncrypto-common" "^1.2.9"