Skip to content

Commit

Permalink
wip make conversation props readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexNi245 committed Nov 26, 2024
1 parent 471b117 commit d249f21
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
16 changes: 12 additions & 4 deletions packages/js-sdk/src/Dm3Sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ export class Dm3Sdk {
profile: SignedUserProfile;
accountAddress: string;
}) {
console.log('hello sdk');

const tld =
this._tld ??
new Tld(
Expand Down Expand Up @@ -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,
Expand All @@ -148,6 +155,7 @@ export class Dm3Sdk {
profileKeys,
this.addressEnsSubdomain,
);
await conversations._init();

return new Dm3(conversations, tld);
}
Expand All @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions packages/js-sdk/src/conversation/Conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 4 additions & 4 deletions packages/js-sdk/src/storage/EncryptedCloudStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down

0 comments on commit d249f21

Please sign in to comment.