2023-07-27 07:31:52 +02:00
|
|
|
/*
|
2024-02-12 03:37:45 +01:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 07:31:52 +02:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2023-09-15 07:28:29 +02:00
|
|
|
import type { UsersRepository } from '@/models/_.js';
|
2023-09-20 04:33:36 +02:00
|
|
|
import type { MiUser } from '@/models/User.js';
|
2022-12-04 02:16:03 +01:00
|
|
|
import { ApRendererService } from '@/core/activitypub/ApRendererService.js';
|
2022-09-17 20:27:08 +02:00
|
|
|
import { RelayService } from '@/core/RelayService.js';
|
2022-12-04 02:16:03 +01:00
|
|
|
import { ApDeliverManagerService } from '@/core/activitypub/ApDeliverManagerService.js';
|
|
|
|
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
2022-12-04 07:03:09 +01:00
|
|
|
import { bindThis } from '@/decorators.js';
|
2022-09-17 20:27:08 +02:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class AccountUpdateService {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.usersRepository)
|
|
|
|
private usersRepository: UsersRepository,
|
|
|
|
|
|
|
|
private userEntityService: UserEntityService,
|
|
|
|
private apRendererService: ApRendererService,
|
|
|
|
private apDeliverManagerService: ApDeliverManagerService,
|
|
|
|
private relayService: RelayService,
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2022-12-04 07:03:09 +01:00
|
|
|
@bindThis
|
2023-08-16 10:51:28 +02:00
|
|
|
public async publishToFollowers(userId: MiUser['id']) {
|
2022-09-17 20:27:08 +02:00
|
|
|
const user = await this.usersRepository.findOneBy({ id: userId });
|
|
|
|
if (user == null) throw new Error('user not found');
|
2023-04-08 07:16:26 +02:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
// フォロワーがリモートユーザーかつ投稿者がローカルユーザーならUpdateを配信
|
|
|
|
if (this.userEntityService.isLocalUser(user)) {
|
2023-02-12 10:47:30 +01:00
|
|
|
const content = this.apRendererService.addContext(this.apRendererService.renderUpdate(await this.apRendererService.renderPerson(user), user));
|
2022-09-17 20:27:08 +02:00
|
|
|
this.apDeliverManagerService.deliverToFollowers(user, content);
|
|
|
|
this.relayService.deliverToRelays(user, content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|