From 01b5fb8172f1d6090d503f97579b82ffae3fa450 Mon Sep 17 00:00:00 2001 From: akp111 Date: Thu, 26 Oct 2023 11:46:58 +0530 Subject: [PATCH] fix: changed index to category --- .../pushNotification/PushNotificationTypes.ts | 5 +-- .../src/lib/pushNotification/channel.ts | 6 ++++ .../pushNotification/pushNotificationBase.ts | 36 +++++++++++-------- .../lib/pushNotification/channel.test.ts | 5 +-- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts b/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts index a4ac86d79..c67947978 100644 --- a/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts +++ b/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts @@ -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}`; diff --git a/packages/restapi/src/lib/pushNotification/channel.ts b/packages/restapi/src/lib/pushNotification/channel.ts index da57c04bb..33612be94 100644 --- a/packages/restapi/src/lib/pushNotification/channel.ts +++ b/packages/restapi/src/lib/pushNotification/channel.ts @@ -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) { diff --git a/packages/restapi/src/lib/pushNotification/pushNotificationBase.ts b/packages/restapi/src/lib/pushNotification/pushNotificationBase.ts index 6e2bbb0ff..30a06c6c4 100644 --- a/packages/restapi/src/lib/pushNotification/pushNotificationBase.ts +++ b/packages/restapi/src/lib/pushNotification/pushNotificationBase.ts @@ -135,12 +135,14 @@ 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}`; @@ -148,17 +150,18 @@ export class PushNotificationBaseClass { 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 = { @@ -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, @@ -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 + @@ -709,7 +715,7 @@ export class PushNotificationBaseClass { } protected getMinimalUserSetting(setting: UserSetting[]) { - if(!setting){ + if (!setting) { return null; } let userSetting = ''; diff --git a/packages/restapi/tests/lib/pushNotification/channel.test.ts b/packages/restapi/tests/lib/pushNotification/channel.test.ts index c5789d573..8a8f0375b 100644 --- a/packages/restapi/tests/lib/pushNotification/channel.test.ts +++ b/packages/restapi/tests/lib/pushNotification/channel.test.ts @@ -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 }, } );