diff options
| author | Marie <marie@kaifa.ch> | 2023-12-31 19:29:09 +0100 |
|---|---|---|
| committer | Marie <marie@kaifa.ch> | 2023-12-31 19:29:26 +0100 |
| commit | 7b04c6ade4dc11c604ccbf39b834988a16621e85 (patch) | |
| tree | 4ca7ed4fe092f7f8b6ded4ef10f5eedec2b3ab0c /packages/frontend/src/scripts/use-note-capture.ts | |
| parent | merge: bugfix auth-fetch ask to never cache responses (#284) (diff) | |
| download | sharkey-7b04c6ade4dc11c604ccbf39b834988a16621e85.tar.gz sharkey-7b04c6ade4dc11c604ccbf39b834988a16621e85.tar.bz2 sharkey-7b04c6ade4dc11c604ccbf39b834988a16621e85.zip | |
fix: make real-time update work with new notes/show changes
Diffstat (limited to 'packages/frontend/src/scripts/use-note-capture.ts')
| -rw-r--r-- | packages/frontend/src/scripts/use-note-capture.ts | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/packages/frontend/src/scripts/use-note-capture.ts b/packages/frontend/src/scripts/use-note-capture.ts index 427bc6ff36..bcdba5455a 100644 --- a/packages/frontend/src/scripts/use-note-capture.ts +++ b/packages/frontend/src/scripts/use-note-capture.ts @@ -30,11 +30,15 @@ export function useNoteCapture(props: { case 'replied': { if (!props.onReplyCallback) break; - const replyNote = await os.api("notes/show", { - noteId: body.id, - }); + // notes/show may throw if the current user can't see the note + try { + const replyNote = await os.api('notes/show', { + noteId: body.id, + }); - await props.onReplyCallback(replyNote); + await props.onReplyCallback(replyNote); + } catch { /* empty */ } + break; } @@ -95,17 +99,20 @@ export function useNoteCapture(props: { } case 'updated': { - const editedNote = await os.api("notes/show", { - noteId: id, - }); + try { + const editedNote = await os.api('notes/show', { + noteId: id, + }); + + const keys = new Set<string>(); + Object.keys(editedNote) + .concat(Object.keys(note.value)) + .forEach((key) => keys.add(key)); + keys.forEach((key) => { + note.value[key] = editedNote[key]; + }); + } catch { /* empty */ } - const keys = new Set<string>(); - Object.keys(editedNote) - .concat(Object.keys(note.value)) - .forEach((key) => keys.add(key)); - keys.forEach((key) => { - note.value[key] = editedNote[key]; - }); break; } } |