2021-11-11 18:02:25 +01:00
|
|
|
import * as os from '@/os';
|
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
import { router } from '@/router';
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2021-01-03 15:58:24 +01:00
|
|
|
export async function search() {
|
2021-11-18 10:45:58 +01:00
|
|
|
const { canceled, result: query } = await os.inputText({
|
2022-01-28 03:39:49 +01:00
|
|
|
title: i18n.ts.search,
|
2021-01-03 15:58:24 +01:00
|
|
|
});
|
|
|
|
if (canceled || query == null || query === '') return;
|
2019-04-18 12:40:23 +02:00
|
|
|
|
2021-01-03 15:58:24 +01:00
|
|
|
const q = query.trim();
|
2019-04-18 12:40:23 +02:00
|
|
|
|
2019-04-25 00:46:39 +02:00
|
|
|
if (q.startsWith('@') && !q.includes(' ')) {
|
2020-10-17 13:12:00 +02:00
|
|
|
router.push(`/${q}`);
|
2019-04-18 12:40:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (q.startsWith('#')) {
|
2020-10-17 13:12:00 +02:00
|
|
|
router.push(`/tags/${encodeURIComponent(q.substr(1))}`);
|
2019-04-18 12:40:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// like 2018/03/12
|
|
|
|
if (/^[0-9]{4}\/[0-9]{2}\/[0-9]{2}/.test(q.replace(/-/g, '/'))) {
|
|
|
|
const date = new Date(q.replace(/-/g, '/'));
|
|
|
|
|
|
|
|
// 日付しか指定されてない場合、例えば 2018/03/12 ならユーザーは
|
|
|
|
// 2018/03/12 のコンテンツを「含む」結果になることを期待するはずなので
|
|
|
|
// 23時間59分進める(そのままだと 2018/03/12 00:00:00 「まで」の
|
|
|
|
// 結果になってしまい、2018/03/12 のコンテンツは含まれない)
|
|
|
|
if (q.replace(/-/g, '/').match(/^[0-9]{4}\/[0-9]{2}\/[0-9]{2}$/)) {
|
|
|
|
date.setHours(23, 59, 59, 999);
|
|
|
|
}
|
|
|
|
|
2021-01-03 15:58:24 +01:00
|
|
|
// TODO
|
|
|
|
//v.$root.$emit('warp', date);
|
2021-11-18 10:45:58 +01:00
|
|
|
os.alert({
|
2021-04-20 16:22:59 +02:00
|
|
|
icon: 'fas fa-history',
|
2020-01-29 20:37:25 +01:00
|
|
|
iconOnly: true, autoClose: true
|
2019-04-18 12:40:23 +02:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (q.startsWith('https://')) {
|
2020-10-18 03:11:34 +02:00
|
|
|
const promise = os.api('ap/show', {
|
|
|
|
uri: q
|
2019-04-18 12:40:23 +02:00
|
|
|
});
|
|
|
|
|
2022-01-28 03:39:49 +01:00
|
|
|
os.promiseDialog(promise, null, null, i18n.ts.fetchingAsApObject);
|
2020-10-18 03:11:34 +02:00
|
|
|
|
|
|
|
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}`);
|
2019-04-18 12:40:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
router.push(`/search?q=${encodeURIComponent(q)}`);
|
2019-04-18 12:40:23 +02:00
|
|
|
}
|