2022-06-14 11:01:23 +02:00
|
|
|
import { Brackets } from 'typeorm';
|
2022-09-17 20:27:08 +02:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import { NotesRepository, FollowingsRepository } from '@/models/index.js';
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
|
|
import { QueryService } from '@/core/QueryService.js';
|
|
|
|
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
|
|
|
import { MetaService } from '@/core/MetaService.js';
|
|
|
|
import { NoteReadService } from '@/core/NoteReadService.js';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
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-09-17 20:27:08 +02:00
|
|
|
@Injectable()
|
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.notesRepository)
|
|
|
|
private notesRepository: NotesRepository,
|
2019-04-07 14:50:36 +02:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
@Inject(DI.followingsRepository)
|
|
|
|
private followingsRepository: FollowingsRepository,
|
2018-12-29 17:40:24 +01:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
private noteEntityService: NoteEntityService,
|
|
|
|
private queryService: QueryService,
|
|
|
|
private noteReadService: NoteReadService,
|
|
|
|
) {
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
|
|
|
const followingQuery = this.followingsRepository.createQueryBuilder('following')
|
|
|
|
.select('following.followeeId')
|
|
|
|
.where('following.followerId = :followerId', { followerId: me.id });
|
2016-12-28 23:49:51 +01:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId)
|
|
|
|
.andWhere(new Brackets(qb => { qb
|
|
|
|
.where(`'{"${me.id}"}' <@ note.mentions`)
|
|
|
|
.orWhere(`'{"${me.id}"}' <@ note.visibleUserIds`);
|
|
|
|
}))
|
|
|
|
.innerJoinAndSelect('note.user', 'user')
|
|
|
|
.leftJoinAndSelect('user.avatar', 'avatar')
|
|
|
|
.leftJoinAndSelect('user.banner', 'banner')
|
|
|
|
.leftJoinAndSelect('note.reply', 'reply')
|
|
|
|
.leftJoinAndSelect('note.renote', 'renote')
|
|
|
|
.leftJoinAndSelect('reply.user', 'replyUser')
|
|
|
|
.leftJoinAndSelect('replyUser.avatar', 'replyUserAvatar')
|
|
|
|
.leftJoinAndSelect('replyUser.banner', 'replyUserBanner')
|
|
|
|
.leftJoinAndSelect('renote.user', 'renoteUser')
|
|
|
|
.leftJoinAndSelect('renoteUser.avatar', 'renoteUserAvatar')
|
|
|
|
.leftJoinAndSelect('renoteUser.banner', 'renoteUserBanner');
|
2018-09-17 19:14:12 +02:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
this.queryService.generateVisibilityQuery(query, me);
|
|
|
|
this.queryService.generateMutedUserQuery(query, me);
|
|
|
|
this.queryService.generateMutedNoteThreadQuery(query, me);
|
|
|
|
this.queryService.generateBlockedUserQuery(query, me);
|
|
|
|
|
|
|
|
if (ps.visibility) {
|
|
|
|
query.andWhere('note.visibility = :visibility', { visibility: ps.visibility });
|
|
|
|
}
|
2016-12-28 23:49:51 +01:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
if (ps.following) {
|
|
|
|
query.andWhere(`((note.userId IN (${ followingQuery.getQuery() })) OR (note.userId = :meId))`, { meId: me.id });
|
|
|
|
query.setParameters(followingQuery.getParameters());
|
|
|
|
}
|
2018-10-29 07:09:03 +01:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const mentions = await query.take(ps.limit).getMany();
|
2019-02-22 03:46:58 +01:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
this.noteReadService.read(me.id, mentions);
|
|
|
|
|
|
|
|
return await this.noteEntityService.packMany(mentions, me);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|