2022-02-27 02:07:39 +00:00
|
|
|
import define from '../../define.js';
|
|
|
|
import { ApiError } from '../../error.js';
|
|
|
|
import { DriveFiles, Followings, NoteFavorites, NoteReactions, Notes, PageLikes, PollVotes, Users } from '@/models/index.js';
|
2020-11-25 12:31:34 +00:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['users'],
|
|
|
|
|
2022-01-18 13:27:10 +00:00
|
|
|
requireCredential: false,
|
2020-11-25 12:31:34 +00:00
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchUser: {
|
|
|
|
message: 'No such user.',
|
|
|
|
code: 'NO_SUCH_USER',
|
2021-12-09 14:58:30 +00:00
|
|
|
id: '9e638e45-3b25-4ef7-8f95-07e8498f1819',
|
2020-11-25 12:31:34 +00:00
|
|
|
},
|
2021-12-09 14:58:30 +00:00
|
|
|
},
|
2022-01-18 13:27:10 +00:00
|
|
|
} as const;
|
2020-11-25 12:31:34 +00:00
|
|
|
|
2022-02-20 04:15:40 +00:00
|
|
|
export const paramDef = {
|
2022-02-19 05:05:32 +00:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
userId: { type: 'string', format: 'misskey:id' },
|
|
|
|
},
|
|
|
|
required: ['userId'],
|
|
|
|
} 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) => {
|
2022-03-26 06:34:00 +00:00
|
|
|
const user = await Users.findOneBy({ id: ps.userId });
|
2020-11-25 12:31:34 +00:00
|
|
|
if (user == null) {
|
|
|
|
throw new ApiError(meta.errors.noSuchUser);
|
|
|
|
}
|
|
|
|
|
|
|
|
const [
|
|
|
|
notesCount,
|
|
|
|
repliesCount,
|
|
|
|
renotesCount,
|
|
|
|
repliedCount,
|
|
|
|
renotedCount,
|
|
|
|
pollVotesCount,
|
|
|
|
pollVotedCount,
|
|
|
|
localFollowingCount,
|
|
|
|
remoteFollowingCount,
|
|
|
|
localFollowersCount,
|
|
|
|
remoteFollowersCount,
|
|
|
|
sentReactionsCount,
|
|
|
|
receivedReactionsCount,
|
|
|
|
noteFavoritesCount,
|
|
|
|
pageLikesCount,
|
|
|
|
pageLikedCount,
|
|
|
|
driveFilesCount,
|
|
|
|
driveUsage,
|
|
|
|
] = await Promise.all([
|
|
|
|
Notes.createQueryBuilder('note')
|
|
|
|
.where('note.userId = :userId', { userId: user.id })
|
|
|
|
.getCount(),
|
|
|
|
Notes.createQueryBuilder('note')
|
|
|
|
.where('note.userId = :userId', { userId: user.id })
|
|
|
|
.andWhere('note.replyId IS NOT NULL')
|
|
|
|
.getCount(),
|
|
|
|
Notes.createQueryBuilder('note')
|
|
|
|
.where('note.userId = :userId', { userId: user.id })
|
|
|
|
.andWhere('note.renoteId IS NOT NULL')
|
|
|
|
.getCount(),
|
|
|
|
Notes.createQueryBuilder('note')
|
|
|
|
.where('note.replyUserId = :userId', { userId: user.id })
|
|
|
|
.getCount(),
|
|
|
|
Notes.createQueryBuilder('note')
|
|
|
|
.where('note.renoteUserId = :userId', { userId: user.id })
|
|
|
|
.getCount(),
|
|
|
|
PollVotes.createQueryBuilder('vote')
|
|
|
|
.where('vote.userId = :userId', { userId: user.id })
|
|
|
|
.getCount(),
|
|
|
|
PollVotes.createQueryBuilder('vote')
|
|
|
|
.innerJoin('vote.note', 'note')
|
|
|
|
.where('note.userId = :userId', { userId: user.id })
|
|
|
|
.getCount(),
|
|
|
|
Followings.createQueryBuilder('following')
|
|
|
|
.where('following.followerId = :userId', { userId: user.id })
|
|
|
|
.andWhere('following.followeeHost IS NULL')
|
|
|
|
.getCount(),
|
|
|
|
Followings.createQueryBuilder('following')
|
|
|
|
.where('following.followerId = :userId', { userId: user.id })
|
|
|
|
.andWhere('following.followeeHost IS NOT NULL')
|
|
|
|
.getCount(),
|
|
|
|
Followings.createQueryBuilder('following')
|
|
|
|
.where('following.followeeId = :userId', { userId: user.id })
|
|
|
|
.andWhere('following.followerHost IS NULL')
|
|
|
|
.getCount(),
|
|
|
|
Followings.createQueryBuilder('following')
|
|
|
|
.where('following.followeeId = :userId', { userId: user.id })
|
|
|
|
.andWhere('following.followerHost IS NOT NULL')
|
|
|
|
.getCount(),
|
|
|
|
NoteReactions.createQueryBuilder('reaction')
|
|
|
|
.where('reaction.userId = :userId', { userId: user.id })
|
|
|
|
.getCount(),
|
|
|
|
NoteReactions.createQueryBuilder('reaction')
|
|
|
|
.innerJoin('reaction.note', 'note')
|
|
|
|
.where('note.userId = :userId', { userId: user.id })
|
|
|
|
.getCount(),
|
|
|
|
NoteFavorites.createQueryBuilder('favorite')
|
|
|
|
.where('favorite.userId = :userId', { userId: user.id })
|
|
|
|
.getCount(),
|
|
|
|
PageLikes.createQueryBuilder('like')
|
|
|
|
.where('like.userId = :userId', { userId: user.id })
|
|
|
|
.getCount(),
|
|
|
|
PageLikes.createQueryBuilder('like')
|
|
|
|
.innerJoin('like.page', 'page')
|
|
|
|
.where('page.userId = :userId', { userId: user.id })
|
|
|
|
.getCount(),
|
|
|
|
DriveFiles.createQueryBuilder('file')
|
|
|
|
.where('file.userId = :userId', { userId: user.id })
|
|
|
|
.getCount(),
|
|
|
|
DriveFiles.calcDriveUsageOf(user),
|
|
|
|
]);
|
|
|
|
|
|
|
|
return {
|
|
|
|
notesCount,
|
|
|
|
repliesCount,
|
|
|
|
renotesCount,
|
|
|
|
repliedCount,
|
|
|
|
renotedCount,
|
|
|
|
pollVotesCount,
|
|
|
|
pollVotedCount,
|
|
|
|
localFollowingCount,
|
|
|
|
remoteFollowingCount,
|
|
|
|
localFollowersCount,
|
|
|
|
remoteFollowersCount,
|
|
|
|
followingCount: localFollowingCount + remoteFollowingCount,
|
|
|
|
followersCount: localFollowersCount + remoteFollowersCount,
|
|
|
|
sentReactionsCount,
|
|
|
|
receivedReactionsCount,
|
|
|
|
noteFavoritesCount,
|
|
|
|
pageLikesCount,
|
|
|
|
pageLikedCount,
|
|
|
|
driveFilesCount,
|
|
|
|
driveUsage,
|
|
|
|
};
|
|
|
|
});
|