From e7c180ff8929195fe8dc039ae07e5e833995b150 Mon Sep 17 00:00:00 2001 From: yukineko <27853966+hideki0403@users.noreply.github.com> Date: Thu, 18 Apr 2024 18:29:38 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=E3=83=9E=E3=82=A4=E3=82=B0=E3=83=AC?= =?UTF-8?q?=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E3=81=8C=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E3=81=AB=E8=A1=8C=E3=81=88=E3=81=AA=E3=81=84=E5=95=8F=E9=A1=8C?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/frontend/src/scripts/note-drafts.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/frontend/src/scripts/note-drafts.ts b/packages/frontend/src/scripts/note-drafts.ts index 958b9ae5dc..67abc004a3 100644 --- a/packages/frontend/src/scripts/note-drafts.ts +++ b/packages/frontend/src/scripts/note-drafts.ts @@ -33,10 +33,11 @@ export async function migrate(userId: string) { if (!raw) return; const drafts = JSON.parse(raw) as Record; + const keys = Object.keys(drafts); const newDrafts: Record = {}; - for (let i = 0; i < Object.keys(drafts).length; i++) { - const key = Object.keys(drafts)[i]; + for (let i = 0; i < keys.length; i++) { + const key = keys[i]; const [type, id] = key.split(':'); if (type === 'note' && id !== userId) continue; const keyType = type === 'renote' ? 'quote' : type as keyof NoteKeys; @@ -52,6 +53,7 @@ export async function migrate(userId: string) { delete drafts[key]; } + if (Object.keys(newDrafts).length === 0) return; await idbSet(`drafts::${userId}`, newDrafts); miLocalStorage.setItem('drafts', JSON.stringify(drafts)); } @@ -71,8 +73,8 @@ export async function getAll(userId: string) { export async function get(type: T, userId: string, uniqueId: string, ...args: Parameters) { const key = getKey(type, uniqueId, ...args); - const draft = await getAll(userId)[key]; - return draft ?? null; + const draft = await getAll(userId); + return draft[key] ?? null; } export async function set(type: T, userId: string, uniqueId: string, draft: NoteDraft['data'], ...args: Parameters) {