From 2abf1e84967ca3ef410584d02819633a48826680 Mon Sep 17 00:00:00 2001 From: Mohammed S Date: Fri, 24 Nov 2023 18:31:47 +0530 Subject: [PATCH] fix: overrride account options --- packages/restapi/src/lib/pushapi/chat.ts | 7 +++++-- packages/restapi/src/lib/pushapi/profile.ts | 12 +++++++----- packages/restapi/src/lib/pushapi/pushAPITypes.ts | 5 +++++ packages/restapi/src/lib/pushapi/user.ts | 6 ++++-- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/packages/restapi/src/lib/pushapi/chat.ts b/packages/restapi/src/lib/pushapi/chat.ts index 6cd5117e2..62387c035 100644 --- a/packages/restapi/src/lib/pushapi/chat.ts +++ b/packages/restapi/src/lib/pushapi/chat.ts @@ -48,10 +48,13 @@ export class Chat { */ page?: number; limit?: number; + overrideAccount?: string; } ): Promise { + const accountToUse = options?.overrideAccount || this.account; + const listParams = { - account: this.account, + account: accountToUse, pgpPrivateKey: this.decryptedPgpPvtKey, page: options?.page, limit: options?.limit, @@ -174,7 +177,7 @@ export class Chat { } async block(users: Array): Promise { - if (!this.signer) { + if (!this.signer || !this.decryptedPgpPvtKey) { throw new Error(PushAPI.ensureSignerMessage()); } const user = await PUSH_USER.get({ diff --git a/packages/restapi/src/lib/pushapi/profile.ts b/packages/restapi/src/lib/pushapi/profile.ts index efe602841..156947e1e 100644 --- a/packages/restapi/src/lib/pushapi/profile.ts +++ b/packages/restapi/src/lib/pushapi/profile.ts @@ -2,6 +2,7 @@ import { ProgressHookType } from '../types'; import * as PUSH_USER from '../user'; import { ENV } from '../constants'; import { PushAPI } from './PushAPI'; +import { InfoOptions } from './pushAPITypes'; export class Profile { constructor( @@ -11,18 +12,19 @@ export class Profile { private progressHook?: (progress: ProgressHookType) => void ) {} - async info() { + async info(options?: InfoOptions) { + const accountToUse = options?.overrideAccount || this.account; const response = await PUSH_USER.get({ - account: this.account, + account: accountToUse, env: this.env, }); return response.profile; } async update(options: { name?: string; desc?: string; picture?: string }) { - if (!this.decryptedPgpPvtKey) { - throw new Error(PushAPI.ensureSignerMessage()); - } + if (!this.decryptedPgpPvtKey) { + throw new Error(PushAPI.ensureSignerMessage()); + } const { name, desc, picture } = options; const response = await PUSH_USER.profile.update({ pgpPrivateKey: this.decryptedPgpPvtKey, diff --git a/packages/restapi/src/lib/pushapi/pushAPITypes.ts b/packages/restapi/src/lib/pushapi/pushAPITypes.ts index 6431800d4..4b0e2939b 100644 --- a/packages/restapi/src/lib/pushapi/pushAPITypes.ts +++ b/packages/restapi/src/lib/pushapi/pushAPITypes.ts @@ -40,3 +40,8 @@ export interface GroupUpdateOptions { meta?: string | null; rules?: Rules | null; } + +export interface InfoOptions { + overrideAccount?: string; +} + diff --git a/packages/restapi/src/lib/pushapi/user.ts b/packages/restapi/src/lib/pushapi/user.ts index 4a485e787..c640c2fd3 100644 --- a/packages/restapi/src/lib/pushapi/user.ts +++ b/packages/restapi/src/lib/pushapi/user.ts @@ -1,12 +1,14 @@ import * as PUSH_USER from '../user'; import { ENV } from '../constants'; +import { InfoOptions } from './pushAPITypes'; export class User { constructor(private account: string, private env: ENV) {} - async info() { + async info(options?: InfoOptions) { + const accountToUse = options?.overrideAccount || this.account; return await PUSH_USER.get({ - account: this.account, + account: accountToUse, env: this.env, }); }