47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
import type Logger from '@/logger.js';
|
|
import { bindThis } from '@/decorators.js';
|
|
import { NoteCreateService } from '@/core/NoteCreateService.js';
|
|
import type { NoteScheduleRepository, UsersRepository } from '@/models/_.js';
|
|
import { DI } from '@/di-symbols.js';
|
|
import { QueueLoggerService } from '../QueueLoggerService.js';
|
|
import type * as Bull from 'bullmq';
|
|
import type { ScheduleNotePostJobData } from '../types.js';
|
|
|
|
@Injectable()
|
|
export class ScheduleNotePostProcessorService {
|
|
private logger: Logger;
|
|
|
|
constructor(
|
|
@Inject(DI.noteScheduleRepository)
|
|
private noteScheduleRepository: NoteScheduleRepository,
|
|
|
|
@Inject(DI.usersRepository)
|
|
private usersRepository: UsersRepository,
|
|
|
|
private noteCreateService: NoteCreateService,
|
|
private queueLoggerService: QueueLoggerService,
|
|
) {
|
|
this.logger = this.queueLoggerService.logger.createSubLogger('ended-poll-notification');
|
|
}
|
|
|
|
@bindThis
|
|
public async process(job: Bull.Job<ScheduleNotePostJobData>): Promise<void> {
|
|
this.noteScheduleRepository.findOneBy({ id: job.data.scheduleNoteId }).then(async (data) => {
|
|
if (!data) {
|
|
this.logger.warn(`Schedule note ${job.data.scheduleNoteId} not found`);
|
|
} else {
|
|
data.note.createdAt = new Date();
|
|
const me = await this.usersRepository.findOneByOrFail({ id: data.userId });
|
|
await this.noteCreateService.create(me, data.note);
|
|
await this.noteScheduleRepository.remove(data);
|
|
}
|
|
});
|
|
}
|
|
}
|