diff --git a/packages/backend/src/nest/storage/UserProfileStore.ts b/packages/backend/src/nest/storage/UserProfileStore.ts index 8a970da95c..c6caa3f682 100644 --- a/packages/backend/src/nest/storage/UserProfileStore.ts +++ b/packages/backend/src/nest/storage/UserProfileStore.ts @@ -1,3 +1,4 @@ +import { Injectable } from '@nestjs/common' import { EventEmitter } from 'events' import KeyValueStore from 'orbit-db-kvstore' import OrbitDB from 'orbit-db' @@ -54,6 +55,7 @@ export const base64DataURLToByteArray = (contents: string): Uint8Array => { return new Uint8Array(bytes) } +@Injectable() export class UserProfileStore { public orbitDb: OrbitDB public store: KeyValueStore @@ -65,13 +67,11 @@ export class UserProfileStore { public static readonly codec = dagCbor public static readonly hasher = sha256 - constructor(orbitDb: OrbitDB) { - this.orbitDb = orbitDb - } - - public async init(emitter: EventEmitter) { + public async init(orbitDb: OrbitDB, emitter: EventEmitter) { logger('Initializing user profiles key/value store') + this.orbitDb = orbitDb + this.store = await this.orbitDb.keyvalue('user-profiles', { replicate: false, Index: UserProfileKeyValueIndex, diff --git a/packages/backend/src/nest/storage/storage.module.ts b/packages/backend/src/nest/storage/storage.module.ts index 6d4efd74a6..9a9013f7c1 100644 --- a/packages/backend/src/nest/storage/storage.module.ts +++ b/packages/backend/src/nest/storage/storage.module.ts @@ -1,11 +1,12 @@ import { Module } from '@nestjs/common' import { StorageService } from './storage.service' +import { UserProfileStore } from './UserProfileStore' import { LocalDbModule } from '../local-db/local-db.module' import { IpfsFileManagerModule } from '../ipfs-file-manager/ipfs-file-manager.module' @Module({ imports: [LocalDbModule, IpfsFileManagerModule], - providers: [StorageService], - exports: [StorageService], + providers: [StorageService, UserProfileStore], + exports: [StorageService, UserProfileStore], }) export class StorageModule {} diff --git a/packages/backend/src/nest/storage/storage.service.ts b/packages/backend/src/nest/storage/storage.service.ts index 6d1fa50e17..47ed2fa1b1 100644 --- a/packages/backend/src/nest/storage/storage.service.ts +++ b/packages/backend/src/nest/storage/storage.service.ts @@ -69,8 +69,6 @@ export class StorageService extends EventEmitter { private certificatesRequests: EventStore private communityMetadata: KeyValueStore - public userProfileStore: UserProfileStore - private ipfs: IPFS private orbitDb: OrbitDB private filesManager: IpfsFileManagerService @@ -83,7 +81,8 @@ export class StorageService extends EventEmitter { @Inject(QUIET_DIR) public readonly quietDir: string, @Inject(ORBIT_DB_DIR) public readonly orbitDbDir: string, @Inject(IPFS_REPO_PATCH) public readonly ipfsRepoPath: string, - private readonly lazyModuleLoader: LazyModuleLoader + private readonly lazyModuleLoader: LazyModuleLoader, + public readonly userProfileStore: UserProfileStore ) { super() } @@ -233,8 +232,7 @@ export class StorageService extends EventEmitter { this.logger('4/6') await this.createDbForCommunityMetadata() this.logger('5/6') - this.userProfileStore = new UserProfileStore(this.orbitDb) - await this.userProfileStore.init(this) + await this.userProfileStore.init(this.orbitDb, this) this.logger('6/6') await this.initAllChannels() this.logger('Initialized DBs')