From 31bf1dbc95953fe481975fcf1edbd4b092be1f18 Mon Sep 17 00:00:00 2001 From: tamaina Date: Tue, 5 Mar 2024 05:22:09 +0000 Subject: [PATCH] a --- packages/backend/src/core/UserKeypairService.ts | 13 +++++++++++-- .../src/core/activitypub/ApDeliverManagerService.ts | 10 ++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/backend/src/core/UserKeypairService.ts b/packages/backend/src/core/UserKeypairService.ts index c27f8fc71a..2341976068 100644 --- a/packages/backend/src/core/UserKeypairService.ts +++ b/packages/backend/src/core/UserKeypairService.ts @@ -49,17 +49,26 @@ export class UserKeypairService implements OnApplicationShutdown { return await this.cache.refresh(userId); } + /** + * + * @param userId user id + * @returns Promise true if keypair is created, false if keypair is already exists + */ @bindThis - public async refreshAndprepareEd25519KeyPair(userId: MiUser['id']): Promise { + public async refreshAndprepareEd25519KeyPair(userId: MiUser['id']): Promise { await this.refresh(userId); const keypair = await this.cache.fetch(userId); - if (keypair.ed25519PublicKey != null) return; + if (keypair.ed25519PublicKey != null) { + return false; + } + const ed25519 = await genEd25519KeyPair(); await this.userKeypairsRepository.update({ userId }, { ed25519PublicKey: ed25519.publicKey, ed25519PrivateKey: ed25519.privateKey, }); this.globalEventService.publishInternalEvent('userKeypairUpdated', { userId }); + return true; } @bindThis diff --git a/packages/backend/src/core/activitypub/ApDeliverManagerService.ts b/packages/backend/src/core/activitypub/ApDeliverManagerService.ts index cf3dce465e..e161ac9973 100644 --- a/packages/backend/src/core/activitypub/ApDeliverManagerService.ts +++ b/packages/backend/src/core/activitypub/ApDeliverManagerService.ts @@ -12,8 +12,8 @@ import { QueueService } from '@/core/QueueService.js'; import { bindThis } from '@/decorators.js'; import type { IActivity } from '@/core/activitypub/type.js'; import { ThinUser } from '@/queue/types.js'; -import { UserKeypairService } from '../UserKeypairService.js'; import { AccountUpdateService } from '@/core/AccountUpdateService.js'; +import { UserKeypairService } from '../UserKeypairService.js'; interface IRecipe { type: string; @@ -112,9 +112,11 @@ class DeliverManager { /** * ed25519の署名がなければ追加する */ - await this.userKeypairService.refreshAndprepareEd25519KeyPair(this.actor.id); - // リモートに配信 - await this.accountUpdateService.publishToFollowers(this.actor.id, true); + const created = await this.userKeypairService.refreshAndprepareEd25519KeyPair(this.actor.id); + if (created) { + // リモートに配信 + await this.accountUpdateService.publishToFollowers(this.actor.id, true); + } } //#endregion