2023-07-27 14:31:52 +09:00
|
|
|
/*
|
2024-02-13 15:59:27 +00:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 14:31:52 +09:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
*/
|
|
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
2023-04-14 13:50:05 +09:00
|
|
|
import * as Redis from 'ioredis';
|
2022-09-18 03:27:08 +09:00
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
2023-09-15 14:28:29 +09:00
|
|
|
import type { NotesRepository, AntennasRepository } from '@/models/_.js';
|
2022-09-18 03:27:08 +09: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 12:11:16 +09:00
|
|
|
import { IdService } from '@/core/IdService.js';
|
2023-11-26 10:02:22 +09:00
|
|
|
import { FanoutTimelineService } from '@/core/FanoutTimelineService.js';
|
2023-11-21 15:32:34 +09:00
|
|
|
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
2024-01-08 04:28:13 +01:00
|
|
|
import { trackPromise } from '@/misc/promise-tracker.js';
|
2022-02-27 11:07:39 +09:00
|
|
|
import { ApiError } from '../../error.js';
|
2020-01-30 04:37:25 +09:00
|
|
|
|
|
|
|
|
export const meta = {
|
2020-04-03 22:42:29 +09:00
|
|
|
tags: ['antennas', 'account', 'notes'],
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-01-18 22:27:10 +09:00
|
|
|
requireCredential: true,
|
2020-01-30 04:37:25 +09:00
|
|
|
|
|
|
|
|
kind: 'read:account',
|
|
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
|
noSuchAntenna: {
|
|
|
|
|
message: 'No such antenna.',
|
|
|
|
|
code: 'NO_SUCH_ANTENNA',
|
2021-12-09 23:58:30 +09:00
|
|
|
id: '850926e0-fd3b-49b6-b69a-b28a5dbd82fe',
|
|
|
|
|
},
|
2021-03-06 22:34:11 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
res: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'array',
|
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 22:34:11 +09:00
|
|
|
items: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'object',
|
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 23:58:30 +09:00
|
|
|
ref: 'Note',
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-01-18 22:27:10 +09:00
|
|
|
} as const;
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-02-20 13:15:40 +09:00
|
|
|
export const paramDef = {
|
2022-02-19 14:05:32 +09: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-09-18 03:27:08 +09:00
|
|
|
@Injectable()
|
2023-08-17 21:20:58 +09:00
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
2022-09-18 03:27:08 +09:00
|
|
|
constructor(
|
2023-10-03 20:26:11 +09:00
|
|
|
@Inject(DI.redisForTimelines)
|
|
|
|
|
private redisForTimelines: Redis.Redis,
|
2023-04-03 12:11:16 +09:00
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
@Inject(DI.notesRepository)
|
|
|
|
|
private notesRepository: NotesRepository,
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
@Inject(DI.antennasRepository)
|
|
|
|
|
private antennasRepository: AntennasRepository,
|
|
|
|
|
|
2023-04-03 12:11:16 +09:00
|
|
|
private idService: IdService,
|
2022-09-18 03:27:08 +09:00
|
|
|
private noteEntityService: NoteEntityService,
|
|
|
|
|
private queryService: QueryService,
|
|
|
|
|
private noteReadService: NoteReadService,
|
2023-11-26 10:02:22 +09:00
|
|
|
private fanoutTimelineService: FanoutTimelineService,
|
2023-11-21 15:32:34 +09:00
|
|
|
private globalEventService: GlobalEventService,
|
2022-09-18 03:27:08 +09:00
|
|
|
) {
|
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
2023-10-16 10:45:22 +09:00
|
|
|
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.gen(ps.untilDate!) : null);
|
|
|
|
|
const sinceId = ps.sinceId ?? (ps.sinceDate ? this.idService.gen(ps.sinceDate!) : null);
|
2023-10-09 20:31:39 +09:00
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
const antenna = await this.antennasRepository.findOneBy({
|
|
|
|
|
id: ps.antennaId,
|
|
|
|
|
userId: me.id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (antenna == null) {
|
|
|
|
|
throw new ApiError(meta.errors.noSuchAntenna);
|
|
|
|
|
}
|
2021-09-18 13:30:28 +09:00
|
|
|
|
2023-11-21 15:32:34 +09:00
|
|
|
// falseだった場合はアンテナの配信先が増えたことを通知したい
|
|
|
|
|
const needPublishEvent = !antenna.isActive;
|
|
|
|
|
|
|
|
|
|
antenna.isActive = true;
|
|
|
|
|
antenna.lastUsedAt = new Date();
|
2024-01-08 04:28:13 +01:00
|
|
|
trackPromise(this.antennasRepository.update(antenna.id, antenna));
|
2023-11-21 15:32:34 +09:00
|
|
|
|
|
|
|
|
if (needPublishEvent) {
|
|
|
|
|
this.globalEventService.publishInternalEvent('antennaUpdated', antenna);
|
|
|
|
|
}
|
2023-07-21 10:09:03 +09:00
|
|
|
|
2023-11-26 10:02:22 +09:00
|
|
|
let noteIds = await this.fanoutTimelineService.get(`antennaTimeline:${antenna.id}`, untilId, sinceId);
|
2023-10-09 20:31:39 +09:00
|
|
|
noteIds = noteIds.slice(0, ps.limit);
|
2023-04-03 12:11:16 +09:00
|
|
|
if (noteIds.length === 0) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const query = this.notesRepository.createQueryBuilder('note')
|
|
|
|
|
.where('note.id IN (:...noteIds)', { noteIds: noteIds })
|
2022-09-18 03:27:08 +09:00
|
|
|
.innerJoinAndSelect('note.user', 'user')
|
|
|
|
|
.leftJoinAndSelect('note.reply', 'reply')
|
|
|
|
|
.leftJoinAndSelect('note.renote', 'renote')
|
|
|
|
|
.leftJoinAndSelect('reply.user', 'replyUser')
|
2023-04-06 19:48:24 +09:00
|
|
|
.leftJoinAndSelect('renote.user', 'renoteUser');
|
2022-09-18 03:27:08 +09:00
|
|
|
|
|
|
|
|
this.queryService.generateVisibilityQuery(query, me);
|
|
|
|
|
this.queryService.generateMutedUserQuery(query, me);
|
|
|
|
|
this.queryService.generateBlockedUserQuery(query, me);
|
|
|
|
|
|
2023-04-03 12:11:16 +09:00
|
|
|
const notes = await query.getMany();
|
2023-10-10 09:45:40 +09:00
|
|
|
if (sinceId != null && untilId == null) {
|
|
|
|
|
notes.sort((a, b) => a.id < b.id ? -1 : 1);
|
|
|
|
|
} else {
|
|
|
|
|
notes.sort((a, b) => a.id > b.id ? -1 : 1);
|
|
|
|
|
}
|
2022-09-18 03:27:08 +09:00
|
|
|
|
2024-02-22 21:10:28 +09:00
|
|
|
this.noteReadService.read(me.id, notes);
|
2022-09-18 03:27:08 +09:00
|
|
|
|
|
|
|
|
return await this.noteEntityService.packMany(notes, me);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|