2022-09-18 03:27:08 +09:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2022-09-21 05:33:11 +09:00
|
|
|
import type { UsersRepository } from '@/models/index.js';
|
|
|
|
import type { Config } from '@/config.js';
|
2022-09-18 03:27:08 +09:00
|
|
|
import type { User } from '@/models/entities/User.js';
|
2022-12-04 10:16:03 +09:00
|
|
|
import { ApRendererService } from '@/core/activitypub/ApRendererService.js';
|
2022-09-18 03:27:08 +09:00
|
|
|
import { RelayService } from '@/core/RelayService.js';
|
2022-12-04 10:16:03 +09:00
|
|
|
import { ApDeliverManagerService } from '@/core/activitypub/ApDeliverManagerService.js';
|
|
|
|
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
2022-12-04 15:03:09 +09:00
|
|
|
import { bindThis } from '@/decorators.js';
|
2022-09-18 03:27:08 +09:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class AccountUpdateService {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.config)
|
|
|
|
private config: Config,
|
|
|
|
|
|
|
|
@Inject(DI.usersRepository)
|
|
|
|
private usersRepository: UsersRepository,
|
|
|
|
|
|
|
|
private userEntityService: UserEntityService,
|
|
|
|
private apRendererService: ApRendererService,
|
|
|
|
private apDeliverManagerService: ApDeliverManagerService,
|
|
|
|
private relayService: RelayService,
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2022-12-04 15:03:09 +09:00
|
|
|
@bindThis
|
2022-09-18 03:27:08 +09:00
|
|
|
public async publishToFollowers(userId: User['id']) {
|
|
|
|
const user = await this.usersRepository.findOneBy({ id: userId });
|
|
|
|
if (user == null) throw new Error('user not found');
|
2023-04-08 14:16:26 +09:00
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
// フォロワーがリモートユーザーかつ投稿者がローカルユーザーならUpdateを配信
|
|
|
|
if (this.userEntityService.isLocalUser(user)) {
|
2023-02-12 18:47:30 +09:00
|
|
|
const content = this.apRendererService.addContext(this.apRendererService.renderUpdate(await this.apRendererService.renderPerson(user), user));
|
2022-09-18 03:27:08 +09:00
|
|
|
this.apDeliverManagerService.deliverToFollowers(user, content);
|
|
|
|
this.relayService.deliverToRelays(user, content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|