Skip to content

Commit 06d724b

Browse files
committed
fix: merge main
2 parents d04c93a + 73f3e9c commit 06d724b

File tree

10 files changed

+342
-267
lines changed

10 files changed

+342
-267
lines changed

packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export type SubscribeUnsubscribeOptions = {
2121

2222
export type UserSetting = {
2323
enabled: boolean;
24-
value?: number;
24+
value?: number | {lower: number, upper: number};
2525
};
2626

2727
export type AliasOptions = Omit<GetAliasInfoOptionsType, 'env'>;
@@ -100,7 +100,7 @@ export type CreateChannelOptions = {
100100

101101
export type NotificationSetting = {
102102
type: number;
103-
default: number;
103+
default: number | { upper: number; lower: number };
104104
description: string;
105105
data?: {
106106
upper: number;

packages/restapi/src/lib/pushNotification/pushNotificationBase.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const LENGTH_UPPER_LIMIT = 125;
3636
const LENGTH_LOWER_LIMTI = 1;
3737
const SETTING_DELIMITER = '-';
3838
const SETTING_SEPARATOR = '+';
39+
const RANGE_TYPE = 3;
3940
const SLIDER_TYPE = 2;
4041
const BOOLEAN_TYPE = 1;
4142
const DEFAULT_ENABLE_VALUE = '1';
@@ -160,17 +161,25 @@ export class PushNotificationBaseClass {
160161
// fetch the minimal version based on conifg that was passed
161162
let index = '';
162163
if (options.payload?.category && settings) {
163-
if (settings[options.payload.category - 1].type == 2) {
164+
if (settings[options.payload.category - 1].type == SLIDER_TYPE) {
164165
index =
165166
options.payload.category +
166167
SETTING_DELIMITER +
167168
SLIDER_TYPE +
168169
SETTING_DELIMITER +
169170
settings[options.payload.category - 1].default;
170171
}
171-
if (settings[options.payload.category - 1].type == 1) {
172+
if (settings[options.payload.category - 1].type == BOOLEAN_TYPE) {
172173
index = options.payload.category + SETTING_DELIMITER + BOOLEAN_TYPE;
173174
}
175+
if (settings[options.payload.category - 1].type == RANGE_TYPE) {
176+
index =
177+
options.payload.category +
178+
SETTING_DELIMITER +
179+
RANGE_TYPE +
180+
SETTING_DELIMITER +
181+
settings[options.payload.category - 1].default.lower;
182+
}
174183
}
175184
const notificationPayload: ISendNotificationInputOptions = {
176185
signer: signer,
@@ -715,6 +724,31 @@ export class PushNotificationBaseClass {
715724
ele.description;
716725
}
717726
}
727+
if (ele.type == RANGE_TYPE) {
728+
if (ele.default && typeof ele.default == 'object' && ele.data) {
729+
const enabled =
730+
ele.data && ele.data.enabled != undefined
731+
? Number(ele.data.enabled).toString()
732+
: DEFAULT_ENABLE_VALUE;
733+
const ticker = ele.data.ticker ?? DEFAULT_TICKER_VALUE;
734+
notificationSetting =
735+
notificationSetting +
736+
SETTING_SEPARATOR +
737+
RANGE_TYPE +
738+
SETTING_DELIMITER +
739+
enabled +
740+
SETTING_DELIMITER +
741+
ele.default.lower +
742+
SETTING_DELIMITER +
743+
ele.default.upper +
744+
SETTING_DELIMITER +
745+
ele.data.lower +
746+
SETTING_DELIMITER +
747+
ele.data.upper +
748+
SETTING_DELIMITER +
749+
ticker;
750+
}
751+
}
718752
}
719753
return {
720754
setting: notificationSetting.replace(/^\+/, ''),

packages/restapi/src/lib/pushapi/PushAPI.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Constants, { ENV } from '../constants';
22
import { SignerType, ProgressHookType } from '../types';
3-
import { PushAPIInitializeProps } from './pushAPITypes';
3+
import { InfoOptions, PushAPIInitializeProps } from './pushAPITypes';
44
import * as PUSH_USER from '../user';
55
import * as PUSH_CHAT from '../chat';
66
import { getAccountAddress, getWallet } from '../chat/helpers';
@@ -240,9 +240,10 @@ export class PushAPI {
240240
return this.stream;
241241
}
242242

243-
async info() {
243+
async info(options?: InfoOptions) {
244+
const accountToUse = options?.overrideAccount || this.account;
244245
return await PUSH_USER.get({
245-
account: this.account,
246+
account: accountToUse,
246247
env: this.env,
247248
});
248249
}

packages/restapi/src/lib/pushapi/chat.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,13 @@ export class Chat {
6161
*/
6262
page?: number;
6363
limit?: number;
64+
overrideAccount?: string;
6465
}
6566
): Promise<IFeeds[]> {
67+
const accountToUse = options?.overrideAccount || this.account;
68+
6669
const listParams = {
67-
account: this.account,
70+
account: accountToUse,
6871
pgpPrivateKey: this.decryptedPgpPvtKey,
6972
page: options?.page,
7073
limit: options?.limit,
@@ -188,7 +191,7 @@ export class Chat {
188191
}
189192

190193
async block(users: Array<string>): Promise<IUser> {
191-
if (!this.signer) {
194+
if (!this.signer || !this.decryptedPgpPvtKey) {
192195
throw new Error(PushAPI.ensureSignerMessage());
193196
}
194197
const user = await PUSH_USER.get({

packages/restapi/src/lib/pushapi/profile.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ProgressHookType } from '../types';
22
import * as PUSH_USER from '../user';
33
import { ENV } from '../constants';
44
import { PushAPI } from './PushAPI';
5+
import { InfoOptions } from './pushAPITypes';
56

67
export class Profile {
78
constructor(
@@ -11,18 +12,19 @@ export class Profile {
1112
private progressHook?: (progress: ProgressHookType) => void
1213
) {}
1314

14-
async info() {
15+
async info(options?: InfoOptions) {
16+
const accountToUse = options?.overrideAccount || this.account;
1517
const response = await PUSH_USER.get({
16-
account: this.account,
18+
account: accountToUse,
1719
env: this.env,
1820
});
1921
return response.profile;
2022
}
2123

2224
async update(options: { name?: string; desc?: string; picture?: string }) {
23-
if (!this.decryptedPgpPvtKey) {
24-
throw new Error(PushAPI.ensureSignerMessage());
25-
}
25+
if (!this.decryptedPgpPvtKey) {
26+
throw new Error(PushAPI.ensureSignerMessage());
27+
}
2628
const { name, desc, picture } = options;
2729
const response = await PUSH_USER.profile.update({
2830
pgpPrivateKey: this.decryptedPgpPvtKey,

packages/restapi/src/lib/pushapi/pushAPITypes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,8 @@ export interface GroupUpdateOptions {
5252
meta?: string | null;
5353
rules?: Rules | null;
5454
}
55+
56+
export interface InfoOptions {
57+
overrideAccount?: string;
58+
}
59+

packages/restapi/src/lib/pushapi/user.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import * as PUSH_USER from '../user';
22
import { ENV } from '../constants';
3+
import { InfoOptions } from './pushAPITypes';
34

45
export class User {
56
constructor(private account: string, private env: ENV) {}
67

7-
async info() {
8+
async info(options?: InfoOptions) {
9+
const accountToUse = options?.overrideAccount || this.account;
810
return await PUSH_USER.get({
9-
account: this.account,
11+
account: accountToUse,
1012
env: this.env,
1113
});
1214
}

0 commit comments

Comments
 (0)