2021-11-11 19:02:25 +02:00
|
|
|
import * as Acct from 'misskey-js/built/acct';
|
|
|
|
import { host as localHost } from '@/config';
|
2019-04-25 01:46:39 +03:00
|
|
|
|
|
|
|
export async function genSearchQuery(v: any, q: string) {
|
|
|
|
let host: string;
|
|
|
|
let userId: string;
|
|
|
|
if (q.split(' ').some(x => x.startsWith('@'))) {
|
|
|
|
for (const at of q.split(' ').filter(x => x.startsWith('@')).map(x => x.substr(1))) {
|
|
|
|
if (at.includes('.')) {
|
|
|
|
if (at === localHost || at === '.') {
|
|
|
|
host = null;
|
|
|
|
} else {
|
|
|
|
host = at;
|
|
|
|
}
|
|
|
|
} else {
|
2021-11-11 19:02:25 +02:00
|
|
|
const user = await v.os.api('users/show', Acct.parse(at)).catch(x => null);
|
2019-04-25 01:46:39 +03:00
|
|
|
if (user) {
|
|
|
|
userId = user.id;
|
|
|
|
} else {
|
|
|
|
// todo: show error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
query: q.split(' ').filter(x => !x.startsWith('/') && !x.startsWith('@')).join(' '),
|
|
|
|
host: host,
|
2022-12-22 09:01:59 +02:00
|
|
|
userId: userId,
|
2019-04-25 01:46:39 +03:00
|
|
|
};
|
|
|
|
}
|