2023-07-27 05:31:52 +00:00
|
|
|
/*
|
2024-02-13 15:59:27 +00:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 05:31:52 +00:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-09-19 07:37:43 +00:00
|
|
|
import * as os from '@/os.js';
|
2024-01-04 09:32:46 +00:00
|
|
|
import { misskeyApi } from '@/scripts/misskey-api.js';
|
2023-09-19 07:37:43 +00:00
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import { Router } from '@/nirax.js';
|
2024-01-30 12:07:34 +00:00
|
|
|
import { mainRouter } from '@/router/main.js';
|
2023-03-16 02:56:20 +00:00
|
|
|
|
|
|
|
export async function lookup(router?: Router) {
|
|
|
|
const _router = router ?? mainRouter;
|
|
|
|
|
2023-07-08 08:41:52 +00:00
|
|
|
const { canceled, result: temp } = await os.inputText({
|
2023-03-16 02:56:20 +00:00
|
|
|
title: i18n.ts.lookup,
|
|
|
|
});
|
2023-07-08 08:41:52 +00:00
|
|
|
const query = temp ? temp.trim() : '';
|
2024-07-30 10:18:43 +00:00
|
|
|
if (canceled || query.length <= 1) return;
|
2023-07-07 22:08:16 +00:00
|
|
|
|
2023-03-16 02:56:20 +00:00
|
|
|
if (query.startsWith('@') && !query.includes(' ')) {
|
|
|
|
_router.push(`/${query}`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (query.startsWith('#')) {
|
2023-07-13 22:59:54 +00:00
|
|
|
_router.push(`/tags/${encodeURIComponent(query.substring(1))}`);
|
2023-03-16 02:56:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (query.startsWith('https://')) {
|
2024-01-04 09:32:46 +00:00
|
|
|
const promise = misskeyApi('ap/show', {
|
2023-03-16 02:56:20 +00:00
|
|
|
uri: query,
|
|
|
|
});
|
|
|
|
|
|
|
|
os.promiseDialog(promise, null, null, i18n.ts.fetchingAsApObject);
|
|
|
|
|
|
|
|
const res = await promise;
|
|
|
|
|
|
|
|
if (res.type === 'User') {
|
|
|
|
_router.push(`/@${res.object.username}@${res.object.host}`);
|
|
|
|
} else if (res.type === 'Note') {
|
|
|
|
_router.push(`/notes/${res.object.id}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|