2023-07-27 00:31:52 -05:00
|
|
|
/*
|
2024-02-13 09:50:11 -06:00
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
2023-07-27 00:31:52 -05:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-09-03 23:33:38 -05:00
|
|
|
import * as Misskey from 'misskey-js';
|
2023-09-19 02:37:43 -05:00
|
|
|
import { host as localHost } from '@/config.js';
|
2019-04-24 17:46:39 -05:00
|
|
|
|
|
|
|
export async function genSearchQuery(v: any, q: string) {
|
|
|
|
let host: string;
|
|
|
|
let userId: string;
|
|
|
|
if (q.split(' ').some(x => x.startsWith('@'))) {
|
2023-07-13 17:59:54 -05:00
|
|
|
for (const at of q.split(' ').filter(x => x.startsWith('@')).map(x => x.substring(1))) {
|
2019-04-24 17:46:39 -05:00
|
|
|
if (at.includes('.')) {
|
|
|
|
if (at === localHost || at === '.') {
|
|
|
|
host = null;
|
|
|
|
} else {
|
|
|
|
host = at;
|
|
|
|
}
|
|
|
|
} else {
|
2024-01-04 03:32:46 -06:00
|
|
|
const user = await v.api('users/show', Misskey.acct.parse(at)).catch(x => null);
|
2019-04-24 17:46:39 -05: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 01:01:59 -06:00
|
|
|
userId: userId,
|
2019-04-24 17:46:39 -05:00
|
|
|
};
|
|
|
|
}
|