Support remote objects in search (#9479)

* Support remote objects in search

Closes #9428

* Use account instead of localStorage

* Use useRouter instead of mainRouter

Co-authored-by: Chaos <chaoticryptidz@owo.monster>
This commit is contained in:
Soni L 2023-01-07 23:15:54 -03:00 committed by GitHub
parent 91356b1805
commit ecbefce2aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 0 deletions

View File

@ -12,12 +12,37 @@ import { computed } from 'vue';
import XNotes from '@/components/MkNotes.vue'; import XNotes from '@/components/MkNotes.vue';
import { i18n } from '@/i18n'; import { i18n } from '@/i18n';
import { definePageMetadata } from '@/scripts/page-metadata'; import { definePageMetadata } from '@/scripts/page-metadata';
import * as os from '@/os';
import { useRouter } from '@/router';
import { $i } from '@/account';
const router = useRouter();
const props = defineProps<{ const props = defineProps<{
query: string; query: string;
channel?: string; channel?: string;
}>(); }>();
const query = props.query;
if ($i != null) {
if (query.startsWith('https://') || (query.startsWith('@') && !query.includes(' '))) {
const promise = os.api('ap/show', {
uri: props.query,
});
os.promiseDialog(promise, null, null, i18n.ts.fetchingAsApObject);
const res = await promise;
if (res.type === 'User') {
router.replace(`/@${res.object.username}@${res.object.host}`);
} else if (res.type === 'Note') {
router.replace(`/notes/${res.object.id}`);
}
}
}
const pagination = { const pagination = {
endpoint: 'notes/search' as const, endpoint: 'notes/search' as const,
limit: 10, limit: 10,