mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-14 11:53:08 +02:00
8a6791da3f
* Remove unused injections * Remove unused imports
55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
import { DI } from '@/di-symbols.js';
|
|
import type { PollVotesRepository, NotesRepository } from '@/models/index.js';
|
|
import type Logger from '@/logger.js';
|
|
import { NotificationService } from '@/core/NotificationService.js';
|
|
import { bindThis } from '@/decorators.js';
|
|
import { QueueLoggerService } from '../QueueLoggerService.js';
|
|
import type * as Bull from 'bullmq';
|
|
import type { EndedPollNotificationJobData } from '../types.js';
|
|
|
|
@Injectable()
|
|
export class EndedPollNotificationProcessorService {
|
|
private logger: Logger;
|
|
|
|
constructor(
|
|
@Inject(DI.notesRepository)
|
|
private notesRepository: NotesRepository,
|
|
|
|
@Inject(DI.pollVotesRepository)
|
|
private pollVotesRepository: PollVotesRepository,
|
|
|
|
private notificationService: NotificationService,
|
|
private queueLoggerService: QueueLoggerService,
|
|
) {
|
|
this.logger = this.queueLoggerService.logger.createSubLogger('ended-poll-notification');
|
|
}
|
|
|
|
@bindThis
|
|
public async process(job: Bull.Job<EndedPollNotificationJobData>): Promise<void> {
|
|
const note = await this.notesRepository.findOneBy({ id: job.data.noteId });
|
|
if (note == null || !note.hasPoll) {
|
|
return;
|
|
}
|
|
|
|
const votes = await this.pollVotesRepository.createQueryBuilder('vote')
|
|
.select('vote.userId')
|
|
.where('vote.noteId = :noteId', { noteId: note.id })
|
|
.innerJoinAndSelect('vote.user', 'user')
|
|
.andWhere('user.host IS NULL')
|
|
.getMany();
|
|
|
|
const userIds = [...new Set([note.userId, ...votes.map(v => v.userId)])];
|
|
|
|
for (const userId of userIds) {
|
|
this.notificationService.createNotification(userId, 'pollEnded', {
|
|
noteId: note.id,
|
|
});
|
|
}
|
|
}
|
|
}
|