2023-01-13 13:40:33 +09:00
|
|
|
import * as os from "@/os";
|
|
|
|
import { i18n } from "@/i18n";
|
|
|
|
import { mainRouter } from "@/router";
|
2020-10-17 20:12:00 +09:00
|
|
|
|
2021-01-03 23:58:24 +09:00
|
|
|
export async function search() {
|
2021-11-18 18:45:58 +09:00
|
|
|
const { canceled, result: query } = await os.inputText({
|
2022-01-28 11:39:49 +09:00
|
|
|
title: i18n.ts.search,
|
2023-05-29 12:34:18 +09:00
|
|
|
placeholder: i18n.ts.searchPlaceholder,
|
2023-05-26 10:06:41 +09:00
|
|
|
text:
|
|
|
|
"Advanced search operators\n" +
|
2023-05-26 06:25:52 +09:00
|
|
|
"from:user => filter by user\n" +
|
|
|
|
"has:image/video/audio/text/file => filter by attachment types\n" +
|
|
|
|
"domain:domain.com => filter by domain\n" +
|
|
|
|
"before:Date => show posts made before Date\n" +
|
2023-05-28 09:19:57 +09:00
|
|
|
"after:Date => show posts made after Date\n" +
|
|
|
|
'"text" => get posts with exact text between quotes\n' +
|
|
|
|
"filter:following => show results only from users you follow\n" +
|
|
|
|
"filter:followers => show results only from followers\n",
|
2021-01-03 23:58:24 +09:00
|
|
|
});
|
2023-01-13 13:40:33 +09:00
|
|
|
if (canceled || query == null || query === "") return;
|
2019-04-18 19:40:23 +09:00
|
|
|
|
2021-01-03 23:58:24 +09:00
|
|
|
const q = query.trim();
|
2019-04-18 19:40:23 +09:00
|
|
|
|
2023-01-13 13:40:33 +09:00
|
|
|
if (q.startsWith("@") && !q.includes(" ")) {
|
2022-06-20 17:38:49 +09:00
|
|
|
mainRouter.push(`/${q}`);
|
2019-04-18 19:40:23 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-13 13:40:33 +09:00
|
|
|
if (q.startsWith("#")) {
|
2022-06-20 17:38:49 +09:00
|
|
|
mainRouter.push(`/tags/${encodeURIComponent(q.substr(1))}`);
|
2019-04-18 19:40:23 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// like 2018/03/12
|
2023-01-13 13:40:33 +09:00
|
|
|
if (/^[0-9]{4}\/[0-9]{2}\/[0-9]{2}/.test(q.replace(/-/g, "/"))) {
|
|
|
|
const date = new Date(q.replace(/-/g, "/"));
|
2019-04-18 19:40:23 +09:00
|
|
|
|
|
|
|
// 日付しか指定されてない場合、例えば 2018/03/12 ならユーザーは
|
|
|
|
// 2018/03/12 のコンテンツを「含む」結果になることを期待するはずなので
|
|
|
|
// 23時間59分進める(そのままだと 2018/03/12 00:00:00 「まで」の
|
|
|
|
// 結果になってしまい、2018/03/12 のコンテンツは含まれない)
|
2023-01-13 13:40:33 +09:00
|
|
|
if (q.replace(/-/g, "/").match(/^[0-9]{4}\/[0-9]{2}\/[0-9]{2}$/)) {
|
2019-04-18 19:40:23 +09:00
|
|
|
date.setHours(23, 59, 59, 999);
|
|
|
|
}
|
|
|
|
|
2021-01-03 23:58:24 +09:00
|
|
|
// TODO
|
|
|
|
//v.$root.$emit('warp', date);
|
2021-11-18 18:45:58 +09:00
|
|
|
os.alert({
|
2023-03-12 06:01:04 +09:00
|
|
|
icon: "ph-clock-counter-clockwise ph-bold ph-lg",
|
2023-01-13 13:40:33 +09:00
|
|
|
iconOnly: true,
|
|
|
|
autoClose: true,
|
2019-04-18 19:40:23 +09:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-13 13:40:33 +09:00
|
|
|
if (q.startsWith("https://")) {
|
|
|
|
const promise = os.api("ap/show", {
|
2022-06-20 17:38:49 +09:00
|
|
|
uri: q,
|
2019-04-18 19:40:23 +09:00
|
|
|
});
|
|
|
|
|
2022-01-28 11:39:49 +09:00
|
|
|
os.promiseDialog(promise, null, null, i18n.ts.fetchingAsApObject);
|
2020-10-18 10:11:34 +09:00
|
|
|
|
|
|
|
const res = await promise;
|
|
|
|
|
2023-01-13 13:40:33 +09:00
|
|
|
if (res.type === "User") {
|
2022-06-20 17:38:49 +09:00
|
|
|
mainRouter.push(`/@${res.object.username}@${res.object.host}`);
|
2023-01-13 13:40:33 +09:00
|
|
|
} else if (res.type === "Note") {
|
2022-06-20 17:38:49 +09:00
|
|
|
mainRouter.push(`/notes/${res.object.id}`);
|
2019-04-18 19:40:23 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-20 17:38:49 +09:00
|
|
|
mainRouter.push(`/search?q=${encodeURIComponent(q)}`);
|
2019-04-18 19:40:23 +09:00
|
|
|
}
|