|
6 | 6 | import * as Misskey from 'misskey-js';
|
7 | 7 | import * as mfm from 'mfm-js';
|
8 | 8 | import { toASCII } from 'punycode';
|
9 |
| -import { $i, getAccounts } from '@/account.js'; |
| 9 | +import { $i } from '@/account.js'; |
10 | 10 | import { defaultStore } from '@/store.js';
|
11 | 11 | import { unique } from '@/scripts/array.js';
|
12 | 12 | import { deepClone } from '@/scripts/clone.js';
|
| 13 | +import { getAccountFromId } from '@/scripts/get-account-from-id.js'; |
13 | 14 | import { misskeyApi } from '@/scripts/misskey-api.js';
|
14 | 15 | import { TmsError } from '@/scripts/tms/error.js';
|
15 | 16 | import { getAppearNote } from '@/scripts/tms/get-appear-note.js';
|
@@ -83,14 +84,21 @@ const toMeEntity = async (fromId?: string | null): Promise<MeEntity> => {
|
83 | 84 | throw new TmsError(errors.meIdIsRequired);
|
84 | 85 | }
|
85 | 86 |
|
86 |
| - const token = (await getAccounts()).find(({ id }) => id === meId)?.token ?? null; |
| 87 | + const token = await getAccountToken(meId); |
87 | 88 | if (token == null) {
|
88 | 89 | throw new TmsError(errors.tokenIsRequired);
|
89 | 90 | }
|
90 | 91 |
|
91 | 92 | return { meId, token } as const satisfies MeEntity;
|
92 | 93 | };
|
93 | 94 |
|
| 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 | + |
94 | 102 | const toNoteEntity = async (noteEntityOrId: NoteEntityOrId, { token }: MeEntity): Promise<NoteEntity> => {
|
95 | 103 | if (typeof noteEntityOrId === 'string') {
|
96 | 104 | const fetchedNote = await misskeyApi('notes/show', { noteId: noteEntityOrId }, token).catch(() => null);
|
|
0 commit comments