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