Skip to content

Commit

Permalink
fix: changed index to category
Browse files Browse the repository at this point in the history
  • Loading branch information
akp111 committed Oct 26, 2023
1 parent 87f469d commit 01b5fb8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ export type IPayload = {
body?: string;
cta?: string;
embed?: string;
index?: {
index: number;
value?: number;
};
category?: number;
meta?: {
domain?: string;
type: `${ADDITIONAL_META_TYPE}+${number}`;
Expand Down
6 changes: 6 additions & 0 deletions packages/restapi/src/lib/pushNotification/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,18 @@ export class Channel extends PushNotificationBaseClass {
send = async (recipients: string[], options: NotificationOptions) => {
try {
this.checkSignerObjectExists();
const info = await this.info(options.channel?? this.account);
let settings = null;
if(info && info.channel_settings){
settings = JSON.parse(info.channel_settings);
}
const lowLevelPayload = this.generateNotificationLowLevelPayload({
signer: this.signer!,
env: this.env!,
recipients: recipients,
options: options,
channel: options.channel ?? this.account,
settings: settings,
});
return await PUSH_PAYLOAD.sendNotification(lowLevelPayload);
} catch (error) {
Expand Down
36 changes: 21 additions & 15 deletions packages/restapi/src/lib/pushNotification/pushNotificationBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,30 +135,33 @@ export class PushNotificationBaseClass {
recipients,
options,
channel,
settings,
}: {
signer: SignerType;
env: ENV;
recipients: string[];
options: NotificationOptions;
channel?: string;
settings: any | null;
}): ISendNotificationInputOptions {
if (!channel) {
channel = `${this.account}`;
}
const notificationType = this.getNotificationType(recipients, channel);
const identityType = IDENTITY_TYPE.DIRECT_PAYLOAD;
// fetch the minimal version based on conifg that was passed
let index;
if (options.payload?.index) {
if (options.payload?.index.value) {
let index = '';
if (options.payload?.category && settings) {
if (settings[options.payload.category - 1].type == 2) {
index =
options.payload.index.index +
options.payload.category +
SETTING_DELIMITER +
SLIDER_TYPE +
SETTING_DELIMITER +
options.payload.index.value;
} else {
index = options.payload.index.index + SETTING_DELIMITER + BOOLEAN_TYPE;
settings[options.payload.category - 1].default;
}
if (settings[options.payload.category - 1].type == 1) {
index = options.payload.category + SETTING_DELIMITER + BOOLEAN_TYPE;
}
}
const notificationPayload: ISendNotificationInputOptions = {
Expand All @@ -176,7 +179,7 @@ export class PushNotificationBaseClass {
etime: options.config?.expiry,
silent: options.config?.silent,
additionalMeta: options.payload?.meta,
index: options.payload?.index ? index : '',
index: options.payload?.category ? index : '',
},
recipients: notificationType.recipient,
graph: options.advanced?.graph,
Expand Down Expand Up @@ -678,22 +681,25 @@ export class PushNotificationBaseClass {
}
if (ele.type == SLIDER_TYPE) {
if (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
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 +
SLIDER_TYPE +
SETTING_DELIMITER+
enabled+
SETTING_DELIMITER +
enabled +
SETTING_DELIMITER +
ele.default +
SETTING_DELIMITER +
ele.data.lower +
SETTING_DELIMITER +
ele.data.upper +
SETTING_DELIMITER+
ticker
SETTING_DELIMITER +
ticker;

notificationSettingDescription =
notificationSettingDescription +
Expand All @@ -709,7 +715,7 @@ export class PushNotificationBaseClass {
}

protected getMinimalUserSetting(setting: UserSetting[]) {
if(!setting){
if (!setting) {
return null;
}
let userSetting = '';
Expand Down
5 changes: 1 addition & 4 deletions packages/restapi/tests/lib/pushNotification/channel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,7 @@ describe('PushAPI.channel functionality', () => {
body: 'testing with random body',
cta: 'https://google.com/',
embed: 'https://avatars.githubusercontent.com/u/64157541?s=200&v=4',
index: {
index: 1,
value: 10 // for slider type and omit it for boolean type
}
category: 2
},
}
);
Expand Down

0 comments on commit 01b5fb8

Please sign in to comment.