Skip to content

Commit

Permalink
fix: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammeds1992 committed Nov 27, 2023
2 parents d04c93a + 73f3e9c commit 06d724b
Show file tree
Hide file tree
Showing 10 changed files with 342 additions and 267 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type SubscribeUnsubscribeOptions = {

export type UserSetting = {
enabled: boolean;
value?: number;
value?: number | {lower: number, upper: number};
};

export type AliasOptions = Omit<GetAliasInfoOptionsType, 'env'>;
Expand Down Expand Up @@ -100,7 +100,7 @@ export type CreateChannelOptions = {

export type NotificationSetting = {
type: number;
default: number;
default: number | { upper: number; lower: number };
description: string;
data?: {
upper: number;
Expand Down
38 changes: 36 additions & 2 deletions packages/restapi/src/lib/pushNotification/pushNotificationBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const LENGTH_UPPER_LIMIT = 125;
const LENGTH_LOWER_LIMTI = 1;
const SETTING_DELIMITER = '-';
const SETTING_SEPARATOR = '+';
const RANGE_TYPE = 3;
const SLIDER_TYPE = 2;
const BOOLEAN_TYPE = 1;
const DEFAULT_ENABLE_VALUE = '1';
Expand Down Expand Up @@ -160,17 +161,25 @@ export class PushNotificationBaseClass {
// fetch the minimal version based on conifg that was passed
let index = '';
if (options.payload?.category && settings) {
if (settings[options.payload.category - 1].type == 2) {
if (settings[options.payload.category - 1].type == SLIDER_TYPE) {
index =
options.payload.category +
SETTING_DELIMITER +
SLIDER_TYPE +
SETTING_DELIMITER +
settings[options.payload.category - 1].default;
}
if (settings[options.payload.category - 1].type == 1) {
if (settings[options.payload.category - 1].type == BOOLEAN_TYPE) {
index = options.payload.category + SETTING_DELIMITER + BOOLEAN_TYPE;
}
if (settings[options.payload.category - 1].type == RANGE_TYPE) {
index =
options.payload.category +
SETTING_DELIMITER +
RANGE_TYPE +
SETTING_DELIMITER +
settings[options.payload.category - 1].default.lower;
}
}
const notificationPayload: ISendNotificationInputOptions = {
signer: signer,
Expand Down Expand Up @@ -715,6 +724,31 @@ export class PushNotificationBaseClass {
ele.description;
}
}
if (ele.type == RANGE_TYPE) {
if (ele.default && typeof ele.default == 'object' && ele.data) {
const enabled =
ele.data && ele.data.enabled != undefined
? Number(ele.data.enabled).toString()
: DEFAULT_ENABLE_VALUE;
const ticker = ele.data.ticker ?? DEFAULT_TICKER_VALUE;
notificationSetting =
notificationSetting +
SETTING_SEPARATOR +
RANGE_TYPE +
SETTING_DELIMITER +
enabled +
SETTING_DELIMITER +
ele.default.lower +
SETTING_DELIMITER +
ele.default.upper +
SETTING_DELIMITER +
ele.data.lower +
SETTING_DELIMITER +
ele.data.upper +
SETTING_DELIMITER +
ticker;
}
}
}
return {
setting: notificationSetting.replace(/^\+/, ''),
Expand Down
7 changes: 4 additions & 3 deletions packages/restapi/src/lib/pushapi/PushAPI.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Constants, { ENV } from '../constants';
import { SignerType, ProgressHookType } from '../types';
import { PushAPIInitializeProps } from './pushAPITypes';
import { InfoOptions, PushAPIInitializeProps } from './pushAPITypes';
import * as PUSH_USER from '../user';
import * as PUSH_CHAT from '../chat';
import { getAccountAddress, getWallet } from '../chat/helpers';
Expand Down Expand Up @@ -240,9 +240,10 @@ export class PushAPI {
return this.stream;
}

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
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 @@ -61,10 +61,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 @@ -188,7 +191,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 @@ -52,3 +52,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
Loading

0 comments on commit 06d724b

Please sign in to comment.