2022-06-14 12:01:23 +03:00
|
|
|
import { Brackets } from 'typeorm';
|
2022-09-17 21:27:08 +03: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-29 00:49:51 +02:00
|
|
|
|
2018-07-16 22:36:44 +03:00
|
|
|
export const meta = {
|
2019-02-23 04:20:58 +02:00
|
|
|
tags: ['notes'],
|
|
|
|
|
2022-01-18 15:27:10 +02:00
|
|
|
requireCredential: true,
|
2018-07-16 22:36:44 +03:00
|
|
|
|
2019-02-23 04:20:58 +02:00
|
|
|
res: {
|
2022-01-18 15:27:10 +02:00
|
|
|
type: 'array',
|
|
|
|
optional: false, nullable: false,
|
2019-02-23 04:20:58 +02:00
|
|
|
items: {
|
2022-01-18 15:27:10 +02:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2019-04-23 16:35:26 +03:00
|
|
|
ref: 'Note',
|
2021-12-09 16:58:30 +02:00
|
|
|
},
|
2019-02-23 04:20:58 +02:00
|
|
|
},
|
2022-01-18 15:27:10 +02:00
|
|
|
} as const;
|
2016-12-29 00:49:51 +02:00
|
|
|
|
2022-02-20 06:15:40 +02:00
|
|
|
export const paramDef = {
|
2022-02-19 07:05:32 +02: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 19:12:50 +02:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-09-17 21:27:08 +03:00
|
|
|
@Injectable()
|
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.notesRepository)
|
|
|
|
private notesRepository: NotesRepository,
|
2019-04-07 15:50:36 +03:00
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
@Inject(DI.followingsRepository)
|
|
|
|
private followingsRepository: FollowingsRepository,
|
2018-12-29 18:40:24 +02:00
|
|
|
|
2022-09-17 21:27:08 +03: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-29 00:49:51 +02:00
|
|
|
|
2022-09-17 21:27:08 +03: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 20:14:12 +03:00
|
|
|
|
2022-09-17 21:27:08 +03: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-29 00:49:51 +02:00
|
|
|
|
2022-09-17 21:27:08 +03: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 08:09:03 +02:00
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
const mentions = await query.take(ps.limit).getMany();
|
2019-02-22 04:46:58 +02:00
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
this.noteReadService.read(me.id, mentions);
|
|
|
|
|
|
|
|
return await this.noteEntityService.packMany(mentions, me);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|