Skip to content

Commit

Permalink
[MALI-1400] Create interfaces for managing notifications and badge nu…
Browse files Browse the repository at this point in the history
…mbers (#286)

* [MALI-1400] Create interfaces for managing notifications and badge numbers

* Prettier fix

* Prettier fix
  • Loading branch information
rleojoseph authored Jan 17, 2024
1 parent 3104dce commit 8fc3597
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 0 deletions.
24 changes: 24 additions & 0 deletions js-miniapp-bridge/src/common-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ import { HostThemeColor } from './types/host-color-scheme';
import { MAAnalyticsInfo } from './types/analytics/analytics';
import { UniversalBridgeInfo } from './types/universal-bridge';
import { CookieInfo } from './types/cookie-info';
import { NotificationBridge } from './notification-bridge';
import {
NotificationDetailedInfo,
NotificationInfo,
NotificationInfoType,
} from './types/notification/notification-info';

/** @internal */
const mabMessageQueue: Callback[] = [];
Expand Down Expand Up @@ -81,10 +87,12 @@ export class MiniAppBridge {
platform: string;
isSecureStorageReady = false;
secureStorageLoadError: MiniAppError | null = null;
private notificationBridge: NotificationBridge;

constructor(executor: PlatformExecutor) {
this.executor = executor;
this.platform = executor.getPlatform();
this.notificationBridge = new NotificationBridge(executor);

if (window) {
window.addEventListener(
Expand Down Expand Up @@ -840,6 +848,22 @@ export class MiniAppBridge {
);
});
}

shouldClearNotifications(notificationType: NotificationInfoType) {
this.notificationBridge.shouldClearNotifications(notificationType);
}

shouldUpdateBadgeNumber(notificationInfo: NotificationInfo) {
this.notificationBridge.shouldUpdateBadgeNumber(notificationInfo);
}

shouldUpdateNotificationInfo(
notificationDetailedInfo: NotificationDetailedInfo
) {
this.notificationBridge.shouldUpdateNotificationInfo(
notificationDetailedInfo
);
}
}

/**
Expand Down
10 changes: 10 additions & 0 deletions js-miniapp-bridge/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ import {
ProductPrice,
} from './types/in-app-purchase';
import { CookieInfo } from './types/cookie-info';
import {
NotificationDetailedInfo,
NotificationInfo,
NotificationInfoType,
NotificationInfoPriority,
} from './types/notification/notification-info';

export {
MiniAppBridge,
Expand Down Expand Up @@ -113,4 +119,8 @@ export {
MAAnalyticsEventType,
UniversalBridgeInfo,
CookieInfo,
NotificationInfo,
NotificationDetailedInfo,
NotificationInfoType,
NotificationInfoPriority,
};
66 changes: 66 additions & 0 deletions js-miniapp-bridge/src/notification-bridge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { PlatformExecutor } from './common-bridge';
import {
NotificationDetailedInfo,
NotificationInfo,
NotificationInfoType,
} from './types/notification/notification-info';

export class NotificationBridge {
executor: PlatformExecutor;
platform: string;

constructor(executor: PlatformExecutor) {
this.executor = executor;
this.platform = executor.getPlatform();
}

/**
* This method is used to clear any notifications in the Host application
* @param {notificationType} NotificationInfoType
* @see {shouldClearNotifications}
*/
shouldClearNotifications(notificationType: NotificationInfoType) {
return new Promise<string>((resolve, reject) => {
return this.executor.exec(
'shouldClearNotifications',
{ notificationType },
result => resolve(result),
error => reject(error)
);
});
}

/**
* This method is used to to update badge number for a specific notification info
* @param {notificationInfo} NotificationInfo
* @see {shouldUpdateBadgeNumber}
*/
shouldUpdateBadgeNumber(notificationInfo: NotificationInfo) {
return new Promise<string>((resolve, reject) => {
return this.executor.exec(
'shouldUpdateBadgeNumber',
{ notificationInfo },
result => resolve(result),
error => reject(error)
);
});
}

/**
* This method is used to share the notification detailed information to Host app
* @param {notificationDetailedInfo} NotificationDetailedInfo
* @see {shouldUpdateNotificationInfo}
*/
shouldUpdateNotificationInfo(
notificationDetailedInfo: NotificationDetailedInfo
) {
return new Promise<string>((resolve, reject) => {
return this.executor.exec(
'shouldUpdateNotificationInfo',
{ notificationDetailedInfo },
result => resolve(result),
error => reject(error)
);
});
}
}
44 changes: 44 additions & 0 deletions js-miniapp-bridge/src/types/notification/notification-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
export enum NotificationInfoType {
CALLS,
MESSAGES,
HOME,
MAIL,
PROFILE,
SUPPORT,
CUSTOM,
}

export enum NotificationInfoPriority {
CRITICAL,
MAJOR,
MINOR,
NORMAL,
OFFERS,
MAINTENANCE,
}

/**
* Notification Info
*/
export interface NotificationInfo {
badgeNumber?: number;
notificationInfoType?: NotificationInfoType;
notificationInfoPriority?: NotificationInfoPriority;
clearAfterRead?: boolean;
}

/**
* Notification DetailedInfo
*/
export interface NotificationDetailedInfo {
title?: string;
body?: string;
icon?: string;
url?: string;
timestamp?: Date;
additionalData?: string;
badgeNumber?: number;
notificationInfoType?: NotificationInfoType;
notificationInfoPriority?: NotificationInfoPriority;
clearAfterRead?: boolean;
}

0 comments on commit 8fc3597

Please sign in to comment.