Skip to content

Commit

Permalink
fix: overrride account options (#884)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammeds1992 authored Nov 24, 2023
1 parent 317ad5f commit d3dd7f0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
7 changes: 5 additions & 2 deletions packages/restapi/src/lib/pushapi/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ export class Chat {
*/
page?: number;
limit?: number;
overrideAccount?: string;
}
): Promise<IFeeds[]> {
const accountToUse = options?.overrideAccount || this.account;

const listParams = {
account: this.account,
account: accountToUse,
pgpPrivateKey: this.decryptedPgpPvtKey,
page: options?.page,
limit: options?.limit,
Expand Down Expand Up @@ -174,7 +177,7 @@ export class Chat {
}

async block(users: Array<string>): Promise<IUser> {
if (!this.signer) {
if (!this.signer || !this.decryptedPgpPvtKey) {
throw new Error(PushAPI.ensureSignerMessage());
}
const user = await PUSH_USER.get({
Expand Down
12 changes: 7 additions & 5 deletions packages/restapi/src/lib/pushapi/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions packages/restapi/src/lib/pushapi/pushAPITypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ export interface GroupUpdateOptions {
meta?: string | null;
rules?: Rules | null;
}

export interface InfoOptions {
overrideAccount?: string;
}

6 changes: 4 additions & 2 deletions packages/restapi/src/lib/pushapi/user.ts
Original file line number Diff line number Diff line change
@@ -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,
});
}
Expand Down

0 comments on commit d3dd7f0

Please sign in to comment.