2019-02-17 14:41:47 +00:00
|
|
|
import $ from 'cafy';
|
2021-08-19 12:55:45 +00:00
|
|
|
import define from '../../define';
|
|
|
|
import { Users } from '@/models/index';
|
|
|
|
import { normalizeForSearch } from '@/misc/normalize-for-search';
|
2019-02-17 14:41:47 +00:00
|
|
|
|
|
|
|
export const meta = {
|
2022-01-18 13:27:10 +00:00
|
|
|
requireCredential: false,
|
2019-02-17 14:41:47 +00:00
|
|
|
|
2019-02-23 02:20:58 +00:00
|
|
|
tags: ['hashtags', 'users'],
|
|
|
|
|
2019-02-17 14:41:47 +00:00
|
|
|
params: {
|
|
|
|
tag: {
|
|
|
|
validator: $.str,
|
|
|
|
},
|
|
|
|
|
|
|
|
limit: {
|
|
|
|
validator: $.optional.num.range(1, 100),
|
2021-12-09 14:58:30 +00:00
|
|
|
default: 10,
|
2019-02-17 14:41:47 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
sort: {
|
|
|
|
validator: $.str.or([
|
|
|
|
'+follower',
|
|
|
|
'-follower',
|
|
|
|
'+createdAt',
|
|
|
|
'-createdAt',
|
|
|
|
'+updatedAt',
|
|
|
|
'-updatedAt',
|
|
|
|
]),
|
|
|
|
},
|
|
|
|
|
|
|
|
state: {
|
|
|
|
validator: $.optional.str.or([
|
|
|
|
'all',
|
2021-12-09 14:58:30 +00:00
|
|
|
'alive',
|
2019-02-17 14:41:47 +00:00
|
|
|
]),
|
2021-12-09 14:58:30 +00:00
|
|
|
default: 'all',
|
2019-02-17 14:41:47 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
origin: {
|
|
|
|
validator: $.optional.str.or([
|
|
|
|
'combined',
|
|
|
|
'local',
|
|
|
|
'remote',
|
|
|
|
]),
|
2021-12-09 14:58:30 +00:00
|
|
|
default: 'local',
|
|
|
|
},
|
2019-02-26 20:02:36 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
2022-01-18 13:27:10 +00:00
|
|
|
type: 'array',
|
|
|
|
optional: false, nullable: false,
|
2019-02-26 20:02:36 +00:00
|
|
|
items: {
|
2022-01-18 13:27:10 +00:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
|
|
|
ref: 'UserDetailed',
|
2021-12-09 14:58:30 +00:00
|
|
|
},
|
2019-02-26 20:02:36 +00:00
|
|
|
},
|
2022-01-18 13:27:10 +00:00
|
|
|
} as const;
|
2019-02-17 14:41:47 +00:00
|
|
|
|
2022-01-02 17:12:50 +00:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2019-02-22 02:46:58 +00:00
|
|
|
export default define(meta, async (ps, me) => {
|
2019-04-07 12:50:36 +00:00
|
|
|
const query = Users.createQueryBuilder('user')
|
2021-02-07 01:43:34 +00:00
|
|
|
.where(':tag = ANY(user.tags)', { tag: normalizeForSearch(ps.tag) });
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
const recent = new Date(Date.now() - (1000 * 60 * 60 * 24 * 5));
|
|
|
|
|
|
|
|
if (ps.state === 'alive') {
|
|
|
|
query.andWhere('user.updatedAt > :date', { date: recent });
|
|
|
|
}
|
2019-02-17 14:41:47 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
if (ps.origin === 'local') {
|
|
|
|
query.andWhere('user.host IS NULL');
|
|
|
|
} else if (ps.origin === 'remote') {
|
|
|
|
query.andWhere('user.host IS NOT NULL');
|
|
|
|
}
|
2019-02-17 14:41:47 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
switch (ps.sort) {
|
|
|
|
case '+follower': query.orderBy('user.followersCount', 'DESC'); break;
|
|
|
|
case '-follower': query.orderBy('user.followersCount', 'ASC'); break;
|
|
|
|
case '+createdAt': query.orderBy('user.createdAt', 'DESC'); break;
|
|
|
|
case '-createdAt': query.orderBy('user.createdAt', 'ASC'); break;
|
|
|
|
case '+updatedAt': query.orderBy('user.updatedAt', 'DESC'); break;
|
|
|
|
case '-updatedAt': query.orderBy('user.updatedAt', 'ASC'); break;
|
|
|
|
}
|
2019-02-17 14:41:47 +00:00
|
|
|
|
2019-04-12 16:43:22 +00:00
|
|
|
const users = await query.take(ps.limit!).getMany();
|
2019-02-17 14:41:47 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
return await Users.packMany(users, me, { detail: true });
|
2019-02-22 02:46:58 +00:00
|
|
|
});
|