mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-13 11:13:08 +02:00
f6154dc0af
Co-authored-by: MeiMei <30769358+mei23@users.noreply.github.com> Co-authored-by: Satsuki Yanagi <17376330+u1-liquid@users.noreply.github.com>
31 lines
777 B
TypeScript
31 lines
777 B
TypeScript
import parseAcct from '../../misc/acct/parse';
|
|
import { host as localHost } from '../config';
|
|
|
|
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 {
|
|
const user = await v.$root.api('users/show', parseAcct(at)).catch(x => null);
|
|
if (user) {
|
|
userId = user.id;
|
|
} else {
|
|
// todo: show error
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
return {
|
|
query: q.split(' ').filter(x => !x.startsWith('/') && !x.startsWith('@')).join(' '),
|
|
host: host,
|
|
userId: userId
|
|
};
|
|
}
|