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