From d249f217dd7550ec10afc3c77c92579959081600 Mon Sep 17 00:00:00 2001 From: AlexNi245 Date: Tue, 26 Nov 2024 11:00:32 +0700 Subject: [PATCH] wip make conversation props readonly --- packages/js-sdk/src/Dm3Sdk.ts | 16 ++++++++++++---- .../js-sdk/src/conversation/Conversations.ts | 10 ++++++++++ .../js-sdk/src/storage/EncryptedCloudStorage.ts | 8 ++++---- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/packages/js-sdk/src/Dm3Sdk.ts b/packages/js-sdk/src/Dm3Sdk.ts index 6a85a6232..30cfe975a 100644 --- a/packages/js-sdk/src/Dm3Sdk.ts +++ b/packages/js-sdk/src/Dm3Sdk.ts @@ -100,6 +100,8 @@ export class Dm3Sdk { profile: SignedUserProfile; accountAddress: string; }) { + console.log('hello sdk'); + const tld = this._tld ?? new Tld( @@ -131,14 +133,19 @@ export class Dm3Sdk { ); await beConnector.login(profile); - - this.storageApi = this.storageApi ?? new EncryptedCloudStorage( + const encCS = new EncryptedCloudStorage( beConnector, account, this.profileKeys, - ).getCloudStorage(); + ); + console.log('encCS', encCS.account); + this.storageApi = encCS.getCloudStorage(); console.log('this.storageApi', this.storageApi); + console.log( + 'SAPI account', + (this.storageApi as unknown as EncryptedCloudStorage).account, + ); const conversations = new Conversations( this.storageApi, @@ -148,6 +155,7 @@ export class Dm3Sdk { profileKeys, this.addressEnsSubdomain, ); + await conversations._init(); return new Dm3(conversations, tld); } @@ -163,7 +171,7 @@ export class Dm3Sdk { this.defaultDeliveryService, ); - console.log('lc', lc, typeof lc.login); + console.log('lcgoo', lc, typeof lc.login); const loginResult = await lc.login(); console.log('loginResult', loginResult); diff --git a/packages/js-sdk/src/conversation/Conversations.ts b/packages/js-sdk/src/conversation/Conversations.ts index 59d8b18e7..8848e8704 100644 --- a/packages/js-sdk/src/conversation/Conversations.ts +++ b/packages/js-sdk/src/conversation/Conversations.ts @@ -40,6 +40,16 @@ export class Conversations { this.list = []; } + public async _init() { + const conversations = await this.storageApi.getConversations(10, 0); + await Promise.all( + conversations.map((conversation) => + this._addConversation(conversation), + ), + ); + console.log('tinit done'); + } + public async addConversation(_ensName: string) { const contactTldName = normalizeEnsName(_ensName); diff --git a/packages/js-sdk/src/storage/EncryptedCloudStorage.ts b/packages/js-sdk/src/storage/EncryptedCloudStorage.ts index e03aa46af..6300e2eb4 100644 --- a/packages/js-sdk/src/storage/EncryptedCloudStorage.ts +++ b/packages/js-sdk/src/storage/EncryptedCloudStorage.ts @@ -9,16 +9,16 @@ import { encryptAsymmetric, } from '@dm3-org/dm3-lib-crypto'; export class EncryptedCloudStorage { - private backendConnector: IBackendConnector; - private account: Account; - private profileKeys: ProfileKeys; + private readonly backendConnector: IBackendConnector; + public readonly account: Account; + private readonly profileKeys: ProfileKeys; constructor( backendConnector: IBackendConnector, account: Account, profileKeys: ProfileKeys, ) { - if(!account.ensName) { + if (!account.ensName) { throw new Error('Account must have an ENS name'); }