2021-11-12 10:47:04 +00:00
|
|
|
import ms from 'ms';
|
2022-02-27 02:07:39 +00:00
|
|
|
import define from '../../define.js';
|
|
|
|
import { Users, Followings } from '@/models/index.js';
|
|
|
|
import { generateMutedUserQueryForUsers } from '../../common/generate-muted-user-query.js';
|
|
|
|
import { generateBlockedUserQuery, generateBlockQueryForUsers } from '../../common/generate-block-query.js';
|
2018-11-21 14:44:59 +00:00
|
|
|
|
2018-07-16 19:36:44 +00:00
|
|
|
export const meta = {
|
2019-02-23 02:20:58 +00:00
|
|
|
tags: ['users'],
|
|
|
|
|
2022-01-18 13:27:10 +00:00
|
|
|
requireCredential: true,
|
2018-07-16 19:36:44 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
kind: 'read:account',
|
2018-11-02 03:49:08 +00:00
|
|
|
|
2022-06-10 05:25:20 +00:00
|
|
|
description: 'Show users that the authenticated user might be interested to follow.',
|
|
|
|
|
2019-02-24 10:42:26 +00:00
|
|
|
res: {
|
2022-01-18 13:27:10 +00:00
|
|
|
type: 'array',
|
|
|
|
optional: false, nullable: false,
|
2019-02-24 10:42:26 +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-24 10:42:26 +00:00
|
|
|
},
|
2022-01-18 13:27:10 +00:00
|
|
|
} as const;
|
2018-07-16 19:36:44 +00:00
|
|
|
|
2022-02-20 04:15:40 +00:00
|
|
|
export const paramDef = {
|
2022-02-19 05:05:32 +00:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
|
|
|
|
offset: { type: 'integer', default: 0 },
|
|
|
|
},
|
|
|
|
required: [],
|
|
|
|
} as const;
|
|
|
|
|
2022-01-02 17:12:50 +00:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-02-19 05:05:32 +00:00
|
|
|
export default define(meta, paramDef, async (ps, me) => {
|
2019-04-07 12:50:36 +00:00
|
|
|
const query = Users.createQueryBuilder('user')
|
|
|
|
.where('user.isLocked = FALSE')
|
2020-12-11 12:16:20 +00:00
|
|
|
.andWhere('user.isExplorable = TRUE')
|
2019-04-25 15:54:11 +00:00
|
|
|
.andWhere('user.host IS NULL')
|
|
|
|
.andWhere('user.updatedAt >= :date', { date: new Date(Date.now() - ms('7days')) })
|
|
|
|
.andWhere('user.id != :meId', { meId: me.id })
|
2019-04-07 12:50:36 +00:00
|
|
|
.orderBy('user.followersCount', 'DESC');
|
2018-11-21 14:44:59 +00:00
|
|
|
|
2020-07-28 00:38:41 +00:00
|
|
|
generateMutedUserQueryForUsers(query, me);
|
2019-07-21 13:27:36 +00:00
|
|
|
generateBlockQueryForUsers(query, me);
|
2021-08-17 12:48:59 +00:00
|
|
|
generateBlockedUserQuery(query, me);
|
2018-10-09 17:08:26 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
const followingQuery = Followings.createQueryBuilder('following')
|
|
|
|
.select('following.followeeId')
|
|
|
|
.where('following.followerId = :followerId', { followerId: me.id });
|
2019-02-22 02:46:58 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
query
|
|
|
|
.andWhere(`user.id NOT IN (${ followingQuery.getQuery() })`);
|
2018-10-06 07:03:18 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
query.setParameters(followingQuery.getParameters());
|
2019-02-22 02:46:58 +00:00
|
|
|
|
2022-02-19 05:05:32 +00:00
|
|
|
const users = await query.take(ps.limit).skip(ps.offset).getMany();
|
2019-02-22 02:46:58 +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
|
|
|
});
|