From 5f93074f91712e14d45ad28eb70756ddbfed9cd0 Mon Sep 17 00:00:00 2001 From: taiyme <53635909+taiyme@users.noreply.github.com> Date: Mon, 29 Apr 2024 21:04:51 +0900 Subject: [PATCH] =?UTF-8?q?fix(tms):=20toMeEntity=20=E3=81=A7=E3=83=88?= =?UTF-8?q?=E3=83=BC=E3=82=AF=E3=83=B3=E3=81=8C=E5=8F=96=E5=BE=97=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=81=AA=E3=81=84=E3=81=93=E3=81=A8=E3=81=8C=E3=81=82?= =?UTF-8?q?=E3=82=8B=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/frontend/src/scripts/tms/to-parameters.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/frontend/src/scripts/tms/to-parameters.ts b/packages/frontend/src/scripts/tms/to-parameters.ts index 301a8c903013..e2f14bf74d1b 100644 --- a/packages/frontend/src/scripts/tms/to-parameters.ts +++ b/packages/frontend/src/scripts/tms/to-parameters.ts @@ -6,10 +6,11 @@ import * as Misskey from 'misskey-js'; import * as mfm from 'mfm-js'; import { toASCII } from 'punycode'; -import { $i, getAccounts } from '@/account.js'; +import { $i } from '@/account.js'; import { defaultStore } from '@/store.js'; import { unique } from '@/scripts/array.js'; import { deepClone } from '@/scripts/clone.js'; +import { getAccountFromId } from '@/scripts/get-account-from-id.js'; import { misskeyApi } from '@/scripts/misskey-api.js'; import { TmsError } from '@/scripts/tms/error.js'; import { getAppearNote } from '@/scripts/tms/get-appear-note.js'; @@ -83,7 +84,7 @@ const toMeEntity = async (fromId?: string | null): Promise => { throw new TmsError(errors.meIdIsRequired); } - const token = (await getAccounts()).find(({ id }) => id === meId)?.token ?? null; + const token = await getAccountToken(meId); if (token == null) { throw new TmsError(errors.tokenIsRequired); } @@ -91,6 +92,13 @@ const toMeEntity = async (fromId?: string | null): Promise => { return { meId, token } as const satisfies MeEntity; }; +const getAccountToken = async (meId: MeEntity['meId']): Promise => { + if ($i?.id === meId && $i.token != null) { + return $i.token; + } + return getAccountFromId(meId).then(x => x?.token ?? null); +}; + const toNoteEntity = async (noteEntityOrId: NoteEntityOrId, { token }: MeEntity): Promise => { if (typeof noteEntityOrId === 'string') { const fetchedNote = await misskeyApi('notes/show', { noteId: noteEntityOrId }, token).catch(() => null);