2019-02-02 00:16:27 +09:00
|
|
|
import * as ms from 'ms';
|
2017-03-09 03:50:09 +09:00
|
|
|
import $ from 'cafy';
|
2018-11-02 13:47:44 +09:00
|
|
|
import define from '../../define';
|
2019-04-07 21:50:36 +09:00
|
|
|
import { Users, Followings } from '../../../../models';
|
2020-07-28 09:38:41 +09:00
|
|
|
import { generateMutedUserQueryForUsers } from '../../common/generate-muted-user-query';
|
2019-07-21 22:27:36 +09:00
|
|
|
import { generateBlockQueryForUsers } from '../../common/generate-block-query';
|
2018-11-21 23:44:59 +09:00
|
|
|
|
2018-07-17 04:36:44 +09:00
|
|
|
export const meta = {
|
|
|
|
desc: {
|
2018-08-29 06:59:43 +09:00
|
|
|
'ja-JP': 'おすすめのユーザー一覧を取得します。'
|
2018-07-17 04:36:44 +09:00
|
|
|
},
|
|
|
|
|
2019-02-23 11:20:58 +09:00
|
|
|
tags: ['users'],
|
|
|
|
|
2020-02-15 21:33:32 +09:00
|
|
|
requireCredential: true as const,
|
2018-07-17 04:36:44 +09:00
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
kind: 'read:account',
|
2018-11-02 12:49:08 +09:00
|
|
|
|
|
|
|
params: {
|
|
|
|
limit: {
|
2019-02-13 16:33:07 +09:00
|
|
|
validator: $.optional.num.range(1, 100),
|
2018-11-02 12:49:08 +09:00
|
|
|
default: 10
|
|
|
|
},
|
|
|
|
|
|
|
|
offset: {
|
2019-02-13 16:33:07 +09:00
|
|
|
validator: $.optional.num.min(0),
|
2018-11-02 12:49:08 +09:00
|
|
|
default: 0
|
|
|
|
}
|
2019-02-24 19:42:26 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
2019-06-27 18:04:09 +09:00
|
|
|
type: 'array' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
2019-02-24 19:42:26 +09:00
|
|
|
items: {
|
2019-06-27 18:04:09 +09:00
|
|
|
type: 'object' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
2019-04-23 22:35:26 +09:00
|
|
|
ref: 'User',
|
2019-02-24 19:42:26 +09:00
|
|
|
}
|
|
|
|
},
|
2018-07-17 04:36:44 +09:00
|
|
|
};
|
|
|
|
|
2019-02-22 11:46:58 +09:00
|
|
|
export default define(meta, async (ps, me) => {
|
2019-04-07 21:50:36 +09:00
|
|
|
const query = Users.createQueryBuilder('user')
|
|
|
|
.where('user.isLocked = FALSE')
|
2019-04-26 00:54:11 +09: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 21:50:36 +09:00
|
|
|
.orderBy('user.followersCount', 'DESC');
|
2018-11-21 23:44:59 +09:00
|
|
|
|
2020-07-28 09:38:41 +09:00
|
|
|
generateMutedUserQueryForUsers(query, me);
|
2019-07-21 22:27:36 +09:00
|
|
|
generateBlockQueryForUsers(query, me);
|
2018-10-10 02:08:26 +09:00
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
const followingQuery = Followings.createQueryBuilder('following')
|
|
|
|
.select('following.followeeId')
|
|
|
|
.where('following.followerId = :followerId', { followerId: me.id });
|
2019-02-22 11:46:58 +09:00
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
query
|
|
|
|
.andWhere(`user.id NOT IN (${ followingQuery.getQuery() })`);
|
2018-10-06 16:03:18 +09:00
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
query.setParameters(followingQuery.getParameters());
|
2019-02-22 11:46:58 +09:00
|
|
|
|
2019-04-13 01:43:22 +09:00
|
|
|
const users = await query.take(ps.limit!).skip(ps.offset).getMany();
|
2019-02-22 11:46:58 +09:00
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
return await Users.packMany(users, me, { detail: true });
|
2019-02-22 11:46:58 +09:00
|
|
|
});
|