Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: overrride account options #884

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: overrride account options
mohammeds1992 committed Nov 24, 2023
commit 2abf1e84967ca3ef410584d02819633a48826680
7 changes: 5 additions & 2 deletions packages/restapi/src/lib/pushapi/chat.ts
Original file line number Diff line number Diff line change
@@ -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,
@@ -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({
12 changes: 7 additions & 5 deletions packages/restapi/src/lib/pushapi/profile.ts
Original file line number Diff line number Diff line change
@@ -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,
5 changes: 5 additions & 0 deletions packages/restapi/src/lib/pushapi/pushAPITypes.ts
Original file line number Diff line number Diff line change
@@ -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,
});
}