2021-08-19 14:55:45 +02:00
|
|
|
import define from '../../define';
|
|
|
|
import read from '@/services/note/read';
|
|
|
|
import { Notes, Followings } from '@/models/index';
|
|
|
|
import { generateVisibilityQuery } from '../../common/generate-visibility-query';
|
|
|
|
import { generateMutedUserQuery } from '../../common/generate-muted-user-query';
|
|
|
|
import { makePaginationQuery } from '../../common/make-pagination-query';
|
2019-04-07 14:50:36 +02:00
|
|
|
import { Brackets } from 'typeorm';
|
2021-08-19 14:55:45 +02:00
|
|
|
import { generateBlockedUserQuery } from '../../common/generate-block-query';
|
2021-10-31 07:30:22 +01:00
|
|
|
import { generateMutedNoteThreadQuery } from '../../common/generate-muted-note-thread-query';
|
2016-12-28 23:49:51 +01:00
|
|
|
|
2018-07-16 21:36:44 +02:00
|
|
|
export const meta = {
|
2019-02-23 03:20:58 +01:00
|
|
|
tags: ['notes'],
|
|
|
|
|
2022-01-18 14:27:10 +01:00
|
|
|
requireCredential: true,
|
2018-07-16 21:36:44 +02:00
|
|
|
|
2019-02-23 03:20:58 +01:00
|
|
|
res: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'array',
|
|
|
|
optional: false, nullable: false,
|
2019-02-23 03:20:58 +01:00
|
|
|
items: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2019-04-23 15:35:26 +02:00
|
|
|
ref: 'Note',
|
2021-12-09 15:58:30 +01:00
|
|
|
},
|
2019-02-23 03:20:58 +01:00
|
|
|
},
|
2022-01-18 14:27:10 +01:00
|
|
|
} as const;
|
2016-12-28 23:49:51 +01:00
|
|
|
|
2022-02-20 05:15:40 +01:00
|
|
|
export const paramDef = {
|
2022-02-19 06:05:32 +01:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
following: { type: 'boolean', default: false },
|
|
|
|
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
|
|
|
|
sinceId: { type: 'string', format: 'misskey:id' },
|
|
|
|
untilId: { type: 'string', format: 'misskey:id' },
|
|
|
|
visibility: { type: 'string' },
|
|
|
|
},
|
|
|
|
required: [],
|
|
|
|
} as const;
|
|
|
|
|
2022-01-02 18:12:50 +01:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-02-19 06:05:32 +01:00
|
|
|
export default define(meta, paramDef, async (ps, user) => {
|
2019-04-07 14:50:36 +02:00
|
|
|
const followingQuery = Followings.createQueryBuilder('following')
|
|
|
|
.select('following.followeeId')
|
|
|
|
.where('following.followerId = :followerId', { followerId: user.id });
|
|
|
|
|
|
|
|
const query = makePaginationQuery(Notes.createQueryBuilder('note'), ps.sinceId, ps.untilId)
|
|
|
|
.andWhere(new Brackets(qb => { qb
|
2021-05-21 07:13:03 +02:00
|
|
|
.where(`'{"${user.id}"}' <@ note.mentions`)
|
|
|
|
.orWhere(`'{"${user.id}"}' <@ note.visibleUserIds`);
|
2019-04-07 14:50:36 +02:00
|
|
|
}))
|
2021-03-21 04:33:37 +01:00
|
|
|
.innerJoinAndSelect('note.user', 'user')
|
2021-03-21 04:31:56 +01:00
|
|
|
.leftJoinAndSelect('note.reply', 'reply')
|
|
|
|
.leftJoinAndSelect('note.renote', 'renote')
|
|
|
|
.leftJoinAndSelect('reply.user', 'replyUser')
|
|
|
|
.leftJoinAndSelect('renote.user', 'renoteUser');
|
2018-12-29 17:40:24 +01:00
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
generateVisibilityQuery(query, user);
|
2020-07-28 02:38:41 +02:00
|
|
|
generateMutedUserQuery(query, user);
|
2021-10-31 07:30:22 +01:00
|
|
|
generateMutedNoteThreadQuery(query, user);
|
2021-08-17 14:48:59 +02:00
|
|
|
generateBlockedUserQuery(query, user);
|
2016-12-28 23:49:51 +01:00
|
|
|
|
2018-09-17 19:14:12 +02:00
|
|
|
if (ps.visibility) {
|
2019-04-07 14:50:36 +02:00
|
|
|
query.andWhere('note.visibility = :visibility', { visibility: ps.visibility });
|
2018-09-17 19:14:12 +02:00
|
|
|
}
|
|
|
|
|
2018-09-16 15:48:57 +02:00
|
|
|
if (ps.following) {
|
2019-04-07 14:50:36 +02:00
|
|
|
query.andWhere(`((note.userId IN (${ followingQuery.getQuery() })) OR (note.userId = :meId))`, { meId: user.id });
|
|
|
|
query.setParameters(followingQuery.getParameters());
|
2016-12-28 23:49:51 +01:00
|
|
|
}
|
|
|
|
|
2022-02-19 06:05:32 +01:00
|
|
|
const mentions = await query.take(ps.limit).getMany();
|
2018-10-29 07:09:03 +01:00
|
|
|
|
2021-03-23 07:12:47 +01:00
|
|
|
read(user.id, mentions);
|
2019-02-22 03:46:58 +01:00
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
return await Notes.packMany(mentions, user);
|
2019-02-22 03:46:58 +01:00
|
|
|
});
|