2023-07-27 14:31:52 +09:00
|
|
|
/*
|
2024-02-13 15:59:27 +00:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 14:31:52 +09:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2024-07-18 01:28:17 +09:00
|
|
|
import { Inject, Injectable, OnModuleInit } from '@nestjs/common';
|
|
|
|
import { ModuleRef } from '@nestjs/core';
|
2022-09-18 03:27:08 +09:00
|
|
|
import { DI } from '@/di-symbols.js';
|
2023-09-15 14:28:29 +09:00
|
|
|
import type { UsersRepository } from '@/models/_.js';
|
2023-09-20 11:33:36 +09:00
|
|
|
import type { MiUser } from '@/models/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';
|
2024-07-18 01:28:17 +09:00
|
|
|
import type { PrivateKeyWithPem } from '@misskey-dev/node-http-message-signatures';
|
2022-09-18 03:27:08 +09:00
|
|
|
|
|
|
|
@Injectable()
|
2024-07-18 01:28:17 +09:00
|
|
|
export class AccountUpdateService implements OnModuleInit {
|
|
|
|
private apDeliverManagerService: ApDeliverManagerService;
|
2022-09-18 03:27:08 +09:00
|
|
|
constructor(
|
2024-07-18 01:28:17 +09:00
|
|
|
private moduleRef: ModuleRef,
|
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
@Inject(DI.usersRepository)
|
|
|
|
private usersRepository: UsersRepository,
|
|
|
|
|
|
|
|
private userEntityService: UserEntityService,
|
|
|
|
private apRendererService: ApRendererService,
|
|
|
|
private relayService: RelayService,
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2024-07-18 01:28:17 +09:00
|
|
|
async onModuleInit() {
|
|
|
|
this.apDeliverManagerService = this.moduleRef.get(ApDeliverManagerService.name);
|
|
|
|
}
|
|
|
|
|
2022-12-04 15:03:09 +09:00
|
|
|
@bindThis
|
2024-07-18 01:28:17 +09:00
|
|
|
/**
|
|
|
|
* Deliver account update to followers
|
|
|
|
* @param userId user id
|
|
|
|
* @param deliverKey optional. Private key to sign the deliver.
|
|
|
|
*/
|
|
|
|
public async publishToFollowers(userId: MiUser['id'], deliverKey?: PrivateKeyWithPem) {
|
2022-09-18 03:27:08 +09:00
|
|
|
const user = await this.usersRepository.findOneBy({ id: userId });
|
|
|
|
if (user == null) throw new Error('user not found');
|
2023-04-08 01:16:26 -04: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));
|
2024-07-18 01:28:17 +09:00
|
|
|
await Promise.allSettled([
|
|
|
|
this.apDeliverManagerService.deliverToFollowers(user, content, deliverKey),
|
|
|
|
this.relayService.deliverToRelays(user, content, deliverKey),
|
|
|
|
]);
|
2022-09-18 03:27:08 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|