2022-09-17 20:27:08 +02:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
2023-04-03 05:11:16 +02:00
|
|
|
import Redis from 'ioredis';
|
2022-09-17 20:27:08 +02:00
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
2023-04-03 05:11:16 +02:00
|
|
|
import type { NotesRepository, AntennasRepository } from '@/models/index.js';
|
2022-09-17 20:27:08 +02:00
|
|
|
import { QueryService } from '@/core/QueryService.js';
|
|
|
|
import { NoteReadService } from '@/core/NoteReadService.js';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
|
|
|
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
2023-04-03 05:11:16 +02:00
|
|
|
import { IdService } from '@/core/IdService.js';
|
2022-02-27 03:07:39 +01:00
|
|
|
import { ApiError } from '../../error.js';
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
export const meta = {
|
2020-04-03 15:42:29 +02:00
|
|
|
tags: ['antennas', 'account', 'notes'],
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-01-18 14:27:10 +01:00
|
|
|
requireCredential: true,
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
kind: 'read:account',
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchAntenna: {
|
|
|
|
message: 'No such antenna.',
|
|
|
|
code: 'NO_SUCH_ANTENNA',
|
2021-12-09 15:58:30 +01:00
|
|
|
id: '850926e0-fd3b-49b6-b69a-b28a5dbd82fe',
|
|
|
|
},
|
2021-03-06 14:34:11 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'array',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 14:34:11 +01:00
|
|
|
items: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 15:58:30 +01:00
|
|
|
ref: 'Note',
|
|
|
|
},
|
|
|
|
},
|
2022-01-18 14:27:10 +01:00
|
|
|
} as const;
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-02-20 05:15:40 +01:00
|
|
|
export const paramDef = {
|
2022-02-19 06:05:32 +01:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
antennaId: { type: 'string', format: 'misskey:id' },
|
|
|
|
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
|
|
|
|
sinceId: { type: 'string', format: 'misskey:id' },
|
|
|
|
untilId: { type: 'string', format: 'misskey:id' },
|
|
|
|
sinceDate: { type: 'integer' },
|
|
|
|
untilDate: { type: 'integer' },
|
|
|
|
},
|
|
|
|
required: ['antennaId'],
|
|
|
|
} 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(
|
2023-04-03 05:11:16 +02:00
|
|
|
@Inject(DI.redis)
|
|
|
|
private redisClient: Redis.Redis,
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
@Inject(DI.notesRepository)
|
|
|
|
private notesRepository: NotesRepository,
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
@Inject(DI.antennasRepository)
|
|
|
|
private antennasRepository: AntennasRepository,
|
|
|
|
|
2023-04-03 05:11:16 +02:00
|
|
|
private idService: IdService,
|
2022-09-17 20:27:08 +02:00
|
|
|
private noteEntityService: NoteEntityService,
|
|
|
|
private queryService: QueryService,
|
|
|
|
private noteReadService: NoteReadService,
|
|
|
|
) {
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
|
|
|
const antenna = await this.antennasRepository.findOneBy({
|
|
|
|
id: ps.antennaId,
|
|
|
|
userId: me.id,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (antenna == null) {
|
|
|
|
throw new ApiError(meta.errors.noSuchAntenna);
|
|
|
|
}
|
2021-09-18 06:30:28 +02:00
|
|
|
|
2023-04-13 01:33:36 +02:00
|
|
|
const limit = ps.limit + (ps.untilId ? 1 : 0) + (ps.sinceId ? 1 : 0); // untilIdに指定したものも含まれるため+1
|
2023-04-03 05:11:16 +02:00
|
|
|
const noteIdsRes = await this.redisClient.xrevrange(
|
|
|
|
`antennaTimeline:${antenna.id}`,
|
2023-04-13 01:33:36 +02:00
|
|
|
ps.untilId ? this.idService.parse(ps.untilId).date.getTime() : ps.untilDate ?? '+',
|
|
|
|
ps.sinceId ? this.idService.parse(ps.sinceId).date.getTime() : ps.sinceDate ?? '-',
|
2023-04-12 04:40:08 +02:00
|
|
|
'COUNT', limit);
|
2023-04-03 05:11:16 +02:00
|
|
|
|
|
|
|
if (noteIdsRes.length === 0) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2023-04-13 01:33:36 +02:00
|
|
|
const noteIds = noteIdsRes.map(x => x[1][1]).filter(x => x !== ps.untilId && x !== ps.sinceId);
|
2023-04-03 05:11:16 +02:00
|
|
|
|
|
|
|
if (noteIds.length === 0) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
const query = this.notesRepository.createQueryBuilder('note')
|
|
|
|
.where('note.id IN (:...noteIds)', { noteIds: noteIds })
|
2022-09-17 20:27:08 +02:00
|
|
|
.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');
|
2022-09-17 20:27:08 +02:00
|
|
|
|
|
|
|
this.queryService.generateVisibilityQuery(query, me);
|
|
|
|
this.queryService.generateMutedUserQuery(query, me);
|
|
|
|
this.queryService.generateBlockedUserQuery(query, me);
|
|
|
|
|
2023-04-03 05:11:16 +02:00
|
|
|
const notes = await query.getMany();
|
|
|
|
notes.sort((a, b) => a.id > b.id ? -1 : 1);
|
2022-09-17 20:27:08 +02:00
|
|
|
|
|
|
|
if (notes.length > 0) {
|
|
|
|
this.noteReadService.read(me.id, notes);
|
|
|
|
}
|
|
|
|
|
2023-03-20 12:12:38 +01:00
|
|
|
this.antennasRepository.update(antenna.id, {
|
|
|
|
lastUsedAt: new Date(),
|
|
|
|
});
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
return await this.noteEntityService.packMany(notes, me);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|