From 524980742304e61ca7293ed86c6dc76ac7d33252 Mon Sep 17 00:00:00 2001 From: Vin Kabuki Date: Tue, 12 Sep 2023 13:22:47 +0200 Subject: [PATCH] Emit csrs on replicated event --- .../connections-manager/connections-manager.service.ts | 8 +++++--- packages/backend/src/nest/storage/storage.service.ts | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/nest/connections-manager/connections-manager.service.ts b/packages/backend/src/nest/connections-manager/connections-manager.service.ts index bb4314540f..ded2a58bed 100644 --- a/packages/backend/src/nest/connections-manager/connections-manager.service.ts +++ b/packages/backend/src/nest/connections-manager/connections-manager.service.ts @@ -567,10 +567,12 @@ export class ConnectionsManagerService extends EventEmitter implements OnModuleI console.log('emitting deleted channel event back to state manager') this.serverIoProvider.io.emit(SocketActionTypes.CHANNEL_DELETION_RESPONSE, payload) }) - this.storageService.on(StorageEvents.REPLICATED_CSR, async (payload: { csr: string }) => { + this.storageService.on(StorageEvents.REPLICATED_CSR, async (payload: string[]) => { console.log(`On ${StorageEvents.REPLICATED_CSR}`) - this.serverIoProvider.io.emit(SocketActionTypes.RESPONSE_GET_CSRS, { csrs: [payload.csr] }) - this.registrationService.emit(RegistrationEvents.REGISTER_USER_CERTIFICATE, payload.csr) + this.serverIoProvider.io.emit(SocketActionTypes.RESPONSE_GET_CSRS, { csrs: payload }) + payload.forEach(csr => + this.registrationService.emit(RegistrationEvents.REGISTER_USER_CERTIFICATE, csr) + ) }) this.storageService.on(StorageEvents.REPLICATED_COMMUNITY_METADATA, (payload: CommunityMetadata) => { console.log(`On ${StorageEvents.REPLICATED_COMMUNITY_METADATA}: ${payload}`) diff --git a/packages/backend/src/nest/storage/storage.service.ts b/packages/backend/src/nest/storage/storage.service.ts index 78a5afe999..6a8a54273d 100644 --- a/packages/backend/src/nest/storage/storage.service.ts +++ b/packages/backend/src/nest/storage/storage.service.ts @@ -415,16 +415,18 @@ export class StorageService extends EventEmitter { ) return } - this.emit(StorageEvents.REPLICATED_CSR, { csr }) + this.emit(StorageEvents.REPLICATED_CSR, [csr]) }) this.certificatesRequests.events.on('replicated', async () => { this.logger('REPLICATED: CSRs') + const allCsrs = this.getAllEventLogEntries(this.certificatesRequests) + this.emit(StorageEvents.REPLICATED_CSR, allCsrs) await this.updatePeersList() }) this.certificatesRequests.events.on('write', async (_address, entry) => { const csr: string = entry.payload.value this.logger('Saved CSR locally', csr) - this.emit(StorageEvents.REPLICATED_CSR, { csr }) + this.emit(StorageEvents.REPLICATED_CSR, [csr]) await this.updatePeersList() })