2023-07-27 07:31:52 +02:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
2022-09-20 22:33:11 +02:00
|
|
|
import type { NotesRepository } from '@/models/index.js';
|
2022-09-17 20:27:08 +02:00
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
|
|
import { QueryService } from '@/core/QueryService.js';
|
|
|
|
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2018-10-25 00:04:15 +02:00
|
|
|
|
|
|
|
export const meta = {
|
2019-02-23 03:20:58 +01:00
|
|
|
tags: ['notes'],
|
|
|
|
|
2022-01-18 14:27:10 +01:00
|
|
|
requireCredential: false,
|
2023-02-17 04:38:30 +01:00
|
|
|
allowGet: true,
|
|
|
|
cacheSec: 3600,
|
2018-10-25 00:04:15 +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;
|
2018-10-25 00:04:15 +02:00
|
|
|
|
2022-02-20 05:15:40 +01:00
|
|
|
export const paramDef = {
|
2022-02-19 06:05:32 +01:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
|
|
|
|
offset: { type: 'integer', default: 0 },
|
2023-02-25 10:26:35 +01:00
|
|
|
channelId: { type: 'string', nullable: true, format: 'misskey:id' },
|
2022-02-19 06:05:32 +01:00
|
|
|
},
|
|
|
|
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,
|
2018-10-25 00:04:15 +02:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
private noteEntityService: NoteEntityService,
|
|
|
|
private queryService: QueryService,
|
|
|
|
) {
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
|
|
|
const day = 1000 * 60 * 60 * 24 * 3; // 3日前まで
|
2019-02-20 14:31:21 +01:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const query = this.notesRepository.createQueryBuilder('note')
|
|
|
|
.addSelect('note.score')
|
|
|
|
.where('note.userHost IS NULL')
|
|
|
|
.andWhere('note.score > 0')
|
|
|
|
.andWhere('note.createdAt > :date', { date: new Date(Date.now() - day) })
|
|
|
|
.andWhere('note.visibility = \'public\'')
|
|
|
|
.innerJoinAndSelect('note.user', 'user')
|
|
|
|
.leftJoinAndSelect('note.reply', 'reply')
|
|
|
|
.leftJoinAndSelect('note.renote', 'renote')
|
|
|
|
.leftJoinAndSelect('reply.user', 'replyUser')
|
2023-04-06 12:48:24 +02:00
|
|
|
.leftJoinAndSelect('renote.user', 'renoteUser');
|
2019-04-07 14:50:36 +02:00
|
|
|
|
2023-02-25 10:26:35 +01:00
|
|
|
if (ps.channelId) query.andWhere('note.channelId = :channelId', { channelId: ps.channelId });
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
if (me) this.queryService.generateMutedUserQuery(query, me);
|
|
|
|
if (me) this.queryService.generateBlockedUserQuery(query, me);
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
let notes = await query
|
|
|
|
.orderBy('note.score', 'DESC')
|
2023-07-08 09:53:07 +02:00
|
|
|
.limit(100)
|
2022-09-17 20:27:08 +02:00
|
|
|
.getMany();
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
notes.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
|
2018-10-25 00:04:15 +02:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
notes = notes.slice(ps.offset, ps.offset + ps.limit);
|
|
|
|
|
|
|
|
return await this.noteEntityService.packMany(notes, me);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|