2023-07-27 07:31:52 +02:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-04-12 02:13:58 +02:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
|
|
|
|
import { UserFollowingService } from '@/core/UserFollowingService.js';
|
|
|
|
import { UserBlockingService } from '@/core/UserBlockingService.js';
|
|
|
|
import { bindThis } from '@/decorators.js';
|
|
|
|
import type Logger from '@/logger.js';
|
|
|
|
|
2023-09-15 07:28:29 +02:00
|
|
|
import type { UsersRepository } from '@/models/_.js';
|
2023-04-12 02:13:58 +02:00
|
|
|
import { DI } from '@/di-symbols.js';
|
2023-09-20 04:33:36 +02:00
|
|
|
import { MiLocalUser, MiRemoteUser } from '@/models/User.js';
|
2023-07-19 04:27:50 +02:00
|
|
|
import { RelationshipJobData } from '../types.js';
|
|
|
|
import { QueueLoggerService } from '../QueueLoggerService.js';
|
|
|
|
import type * as Bull from 'bullmq';
|
2023-04-12 02:13:58 +02:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class RelationshipProcessorService {
|
|
|
|
private logger: Logger;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.usersRepository)
|
|
|
|
private usersRepository: UsersRepository,
|
|
|
|
|
|
|
|
private queueLoggerService: QueueLoggerService,
|
|
|
|
private userFollowingService: UserFollowingService,
|
|
|
|
private userBlockingService: UserBlockingService,
|
|
|
|
) {
|
|
|
|
this.logger = this.queueLoggerService.logger.createSubLogger('follow-block');
|
|
|
|
}
|
|
|
|
|
|
|
|
@bindThis
|
|
|
|
public async processFollow(job: Bull.Job<RelationshipJobData>): Promise<string> {
|
2023-10-17 13:56:17 +02:00
|
|
|
this.logger.info(`${job.data.from.id} is trying to follow ${job.data.to.id} ${job.data.withReplies ? "with replies" : "without replies"}`);
|
|
|
|
await this.userFollowingService.follow(job.data.from, job.data.to, {
|
|
|
|
requestId: job.data.requestId,
|
|
|
|
silent: job.data.silent,
|
|
|
|
withReplies: job.data.withReplies,
|
|
|
|
});
|
2023-04-12 02:13:58 +02:00
|
|
|
return 'ok';
|
|
|
|
}
|
|
|
|
|
|
|
|
@bindThis
|
|
|
|
public async processUnfollow(job: Bull.Job<RelationshipJobData>): Promise<string> {
|
|
|
|
this.logger.info(`${job.data.from.id} is trying to unfollow ${job.data.to.id}`);
|
|
|
|
const [follower, followee] = await Promise.all([
|
|
|
|
this.usersRepository.findOneByOrFail({ id: job.data.from.id }),
|
|
|
|
this.usersRepository.findOneByOrFail({ id: job.data.to.id }),
|
2023-08-16 10:51:28 +02:00
|
|
|
]) as [MiLocalUser | MiRemoteUser, MiLocalUser | MiRemoteUser];
|
2023-04-12 02:13:58 +02:00
|
|
|
await this.userFollowingService.unfollow(follower, followee, job.data.silent);
|
|
|
|
return 'ok';
|
|
|
|
}
|
|
|
|
|
|
|
|
@bindThis
|
|
|
|
public async processBlock(job: Bull.Job<RelationshipJobData>): Promise<string> {
|
|
|
|
this.logger.info(`${job.data.from.id} is trying to block ${job.data.to.id}`);
|
|
|
|
const [blockee, blocker] = await Promise.all([
|
|
|
|
this.usersRepository.findOneByOrFail({ id: job.data.from.id }),
|
|
|
|
this.usersRepository.findOneByOrFail({ id: job.data.to.id }),
|
|
|
|
]);
|
|
|
|
await this.userBlockingService.block(blockee, blocker, job.data.silent);
|
|
|
|
return 'ok';
|
|
|
|
}
|
|
|
|
|
|
|
|
@bindThis
|
|
|
|
public async processUnblock(job: Bull.Job<RelationshipJobData>): Promise<string> {
|
|
|
|
this.logger.info(`${job.data.from.id} is trying to unblock ${job.data.to.id}`);
|
|
|
|
const [blockee, blocker] = await Promise.all([
|
|
|
|
this.usersRepository.findOneByOrFail({ id: job.data.from.id }),
|
|
|
|
this.usersRepository.findOneByOrFail({ id: job.data.to.id }),
|
|
|
|
]);
|
|
|
|
await this.userBlockingService.unblock(blockee, blocker);
|
|
|
|
return 'ok';
|
|
|
|
}
|
|
|
|
}
|