Skip to content

Commit 5f93074

Browse files
committed
fix(tms): toMeEntity でトークンが取得できないことがある問題
1 parent 2d23e45 commit 5f93074

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/frontend/src/scripts/tms/to-parameters.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
import * as Misskey from 'misskey-js';
77
import * as mfm from 'mfm-js';
88
import { toASCII } from 'punycode';
9-
import { $i, getAccounts } from '@/account.js';
9+
import { $i } from '@/account.js';
1010
import { defaultStore } from '@/store.js';
1111
import { unique } from '@/scripts/array.js';
1212
import { deepClone } from '@/scripts/clone.js';
13+
import { getAccountFromId } from '@/scripts/get-account-from-id.js';
1314
import { misskeyApi } from '@/scripts/misskey-api.js';
1415
import { TmsError } from '@/scripts/tms/error.js';
1516
import { getAppearNote } from '@/scripts/tms/get-appear-note.js';
@@ -83,14 +84,21 @@ const toMeEntity = async (fromId?: string | null): Promise<MeEntity> => {
8384
throw new TmsError(errors.meIdIsRequired);
8485
}
8586

86-
const token = (await getAccounts()).find(({ id }) => id === meId)?.token ?? null;
87+
const token = await getAccountToken(meId);
8788
if (token == null) {
8889
throw new TmsError(errors.tokenIsRequired);
8990
}
9091

9192
return { meId, token } as const satisfies MeEntity;
9293
};
9394

95+
const getAccountToken = async (meId: MeEntity['meId']): Promise<MeEntity['token'] | null> => {
96+
if ($i?.id === meId && $i.token != null) {
97+
return $i.token;
98+
}
99+
return getAccountFromId(meId).then(x => x?.token ?? null);
100+
};
101+
94102
const toNoteEntity = async (noteEntityOrId: NoteEntityOrId, { token }: MeEntity): Promise<NoteEntity> => {
95103
if (typeof noteEntityOrId === 'string') {
96104
const fetchedNote = await misskeyApi('notes/show', { noteId: noteEntityOrId }, token).catch(() => null);

0 commit comments

Comments
 (0)