2023-07-27 08:31:52 +03:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-09-19 10:37:43 +03:00
|
|
|
import * as os from '@/os.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import { mainRouter } from '@/router.js';
|
|
|
|
import { Router } from '@/nirax.js';
|
2023-03-16 04:56:20 +02:00
|
|
|
|
|
|
|
export async function lookup(router?: Router) {
|
|
|
|
const _router = router ?? mainRouter;
|
|
|
|
|
2023-07-08 11:41:52 +03:00
|
|
|
const { canceled, result: temp } = await os.inputText({
|
2023-03-16 04:56:20 +02:00
|
|
|
title: i18n.ts.lookup,
|
|
|
|
});
|
2023-07-08 11:41:52 +03:00
|
|
|
const query = temp ? temp.trim() : '';
|
2023-03-16 04:56:20 +02:00
|
|
|
if (canceled) return;
|
2023-07-08 01:08:16 +03:00
|
|
|
|
2023-03-16 04:56:20 +02:00
|
|
|
if (query.startsWith('@') && !query.includes(' ')) {
|
|
|
|
_router.push(`/${query}`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (query.startsWith('#')) {
|
2023-07-14 01:59:54 +03:00
|
|
|
_router.push(`/tags/${encodeURIComponent(query.substring(1))}`);
|
2023-03-16 04:56:20 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (query.startsWith('https://')) {
|
|
|
|
const promise = os.api('ap/show', {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|