Skip to content

[MOB-11175] make-rn-sdk-compatible-with-expo #629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
191 changes: 73 additions & 118 deletions src/core/classes/Iterable.ts

Large diffs are not rendered by default.

26 changes: 0 additions & 26 deletions src/core/classes/RNIterableAPI.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/core/classes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ export * from './IterableConfig';
export * from './IterableEdgeInsets';
export * from './IterableLogger';
export * from './IterableUtil';
export * from './RNIterableAPI';
36 changes: 16 additions & 20 deletions src/inApp/classes/IterableInAppManager.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Iterable, RNIterableAPI } from '../../core';
import type {
IterableInAppDeleteSource,
IterableInAppLocation,
} from '../enums';
import { NativeModules } from 'react-native';

import { Iterable } from '../../core';
import type { IterableInAppDeleteSource, IterableInAppLocation } from '../enums';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused expression, expected an assignment or function call

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use comma operator here because it can be easily misunderstood or lead to unintended bugs.

import { IterableHtmlInAppContent } from './IterableHtmlInAppContent';
import { IterableInAppMessage } from './IterableInAppMessage';

const RNIterableAPI = NativeModules.RNIterableAPI;

/**
* Manages in-app messages for the current user.
*
Expand All @@ -32,7 +33,7 @@ export class IterableInAppManager {
* @returns A Promise that resolves to an array of in-app messages.
*/
getMessages(): Promise<IterableInAppMessage[]> {
Iterable.logger.log('InAppManager.getMessages');
Iterable?.logger?.log('InAppManager.getMessages');

return RNIterableAPI.getInAppMessages();
}
Expand All @@ -55,7 +56,7 @@ export class IterableInAppManager {
* @returns A Promise that resolves to an array of messages marked as `saveToInbox`.
*/
getInboxMessages(): Promise<IterableInAppMessage[]> {
Iterable.logger.log('InAppManager.getInboxMessages');
Iterable?.logger?.log('InAppManager.getInboxMessages');

return RNIterableAPI.getInboxMessages();
}
Expand All @@ -78,11 +79,8 @@ export class IterableInAppManager {
*
* @returns A Promise that resolves to the URL of the button or link the user tapped to close the in-app message.
*/
showMessage(
message: IterableInAppMessage,
consume: boolean
): Promise<string | undefined> {
Iterable.logger.log('InAppManager.show');
showMessage(message: IterableInAppMessage, consume: boolean): Promise<string | undefined> {
Iterable?.logger?.log('InAppManager.show');

return RNIterableAPI.showMessage(message.messageId, consume);
}
Expand All @@ -108,9 +106,9 @@ export class IterableInAppManager {
removeMessage(
message: IterableInAppMessage,
location: IterableInAppLocation,
source: IterableInAppDeleteSource
source: IterableInAppDeleteSource,
): void {
Iterable.logger.log('InAppManager.remove');
Iterable?.logger?.log('InAppManager.remove');

return RNIterableAPI.removeMessage(message.messageId, location, source);
}
Expand All @@ -127,7 +125,7 @@ export class IterableInAppManager {
* ```
*/
setReadForMessage(message: IterableInAppMessage, read: boolean) {
Iterable.logger.log('InAppManager.setRead');
Iterable?.logger?.log('InAppManager.setRead');

RNIterableAPI.setReadForMessage(message.messageId, read);
}
Expand All @@ -144,10 +142,8 @@ export class IterableInAppManager {
* Iterable.inAppManager.getHtmlContentForMessage(message);
* ```
*/
getHtmlContentForMessage(
message: IterableInAppMessage
): Promise<IterableHtmlInAppContent> {
Iterable.logger.log('InAppManager.getHtmlContentForMessage');
getHtmlContentForMessage(message: IterableInAppMessage): Promise<IterableHtmlInAppContent> {
Iterable?.logger?.log('InAppManager.getHtmlContentForMessage');

return RNIterableAPI.getHtmlInAppContentForMessage(message.messageId);
}
Expand All @@ -167,7 +163,7 @@ export class IterableInAppManager {
* ```
*/
setAutoDisplayPaused(paused: boolean) {
Iterable.logger.log('InAppManager.setAutoDisplayPaused');
Iterable?.logger?.log('InAppManager.setAutoDisplayPaused');

RNIterableAPI.setAutoDisplayPaused(paused);
}
Expand Down
51 changes: 19 additions & 32 deletions src/inbox/classes/IterableInboxDataModel.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Iterable, RNIterableAPI } from '../../core';
import { NativeModules } from 'react-native';

import { Iterable } from '../../core';
import {
IterableHtmlInAppContent,
IterableInAppDeleteSource,
IterableInAppLocation,
IterableInAppMessage,
type IterableHtmlInAppContentRaw,
} from '../../inApp';
import type {
IterableInboxImpressionRowInfo,
IterableInboxRowViewModel,
} from '../types';
import type { IterableInboxImpressionRowInfo, IterableInboxRowViewModel } from '../types';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused expression, expected an assignment or function call

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use comma operator here because it can be easily misunderstood or lead to unintended bugs.


const RNIterableAPI = NativeModules.RNIterableAPI;

/**
* The `IterableInboxDataModel` class provides methods to manage and manipulate
Expand All @@ -35,10 +36,7 @@ export class IterableInboxDataModel {
* a positive number if `message1` should come after `message2`,
* or 0 if they are considered equal.
*/
comparatorFn?: (
message1: IterableInAppMessage,
message2: IterableInAppMessage
) => number;
comparatorFn?: (message1: IterableInAppMessage, message2: IterableInAppMessage) => number;
/**
* Optional function to map an IterableInAppMessage to a date string or undefined.
* This function can be used to extract and format the date from a message.
Expand All @@ -57,11 +55,8 @@ export class IterableInboxDataModel {
*/
set(
filter?: (message: IterableInAppMessage) => boolean,
comparator?: (
message1: IterableInAppMessage,
message2: IterableInAppMessage
) => number,
dateMapper?: (message: IterableInAppMessage) => string | undefined
comparator?: (message1: IterableInAppMessage, message2: IterableInAppMessage) => number,
dateMapper?: (message: IterableInAppMessage) => string | undefined,
) {
this.filterFn = filter;
this.comparatorFn = comparator;
Expand Down Expand Up @@ -93,14 +88,12 @@ export class IterableInboxDataModel {
* @returns A promise that resolves to the HTML content of the specified message.
*/
getHtmlContentForMessageId(id: string): Promise<IterableHtmlInAppContent> {
Iterable.logger.log(
'IterableInboxDataModel.getHtmlContentForItem messageId: ' + id
);
Iterable?.logger?.log('IterableInboxDataModel.getHtmlContentForItem messageId: ' + id);

return RNIterableAPI.getHtmlInAppContentForMessage(id).then(
(content: IterableHtmlInAppContentRaw) => {
return IterableHtmlInAppContent.fromDict(content);
}
},
);
}

Expand All @@ -110,7 +103,7 @@ export class IterableInboxDataModel {
* @param id - The unique identifier of the message to be marked as read.
*/
setMessageAsRead(id: string) {
Iterable.logger.log('IterableInboxDataModel.setMessageAsRead');
Iterable?.logger?.log('IterableInboxDataModel.setMessageAsRead');

RNIterableAPI.setReadForMessage(id, true);
}
Expand All @@ -122,7 +115,7 @@ export class IterableInboxDataModel {
* @param deleteSource - The source from which the delete action is initiated.
*/
deleteItemById(id: string, deleteSource: IterableInAppDeleteSource) {
Iterable.logger.log('IterableInboxDataModel.deleteItemById');
Iterable?.logger?.log('IterableInboxDataModel.deleteItemById');

RNIterableAPI.removeMessage(id, IterableInAppLocation.inbox, deleteSource);
}
Expand All @@ -140,7 +133,7 @@ export class IterableInboxDataModel {
},
() => {
return [];
}
},
);
}

Expand Down Expand Up @@ -192,7 +185,7 @@ export class IterableInboxDataModel {
*/
private static sortByMostRecent = (
message1: IterableInAppMessage,
message2: IterableInAppMessage
message2: IterableInAppMessage,
) => {
const createdAt1 = message1.createdAt ?? new Date(0);
const createdAt2 = message2.createdAt ?? new Date(0);
Expand Down Expand Up @@ -235,12 +228,8 @@ export class IterableInboxDataModel {
* @param messages - An array of `IterableInAppMessage` objects to be processed.
* @returns An array of `IterableInboxRowViewModel` objects representing the processed messages.
*/
private processMessages(
messages: IterableInAppMessage[]
): IterableInboxRowViewModel[] {
return this.sortAndFilter(messages).map(
IterableInboxDataModel.getInboxRowViewModelForMessage
);
private processMessages(messages: IterableInAppMessage[]): IterableInboxRowViewModel[] {
return this.sortAndFilter(messages).map(IterableInboxDataModel.getInboxRowViewModelForMessage);
}

/**
Expand All @@ -249,9 +238,7 @@ export class IterableInboxDataModel {
* @param messages - The array of messages to be sorted and filtered.
* @returns The sorted and filtered array of messages.
*/
private sortAndFilter(
messages: IterableInAppMessage[]
): IterableInAppMessage[] {
private sortAndFilter(messages: IterableInAppMessage[]): IterableInAppMessage[] {
let sortedFilteredMessages = messages.slice();

// MOB-10424: Figure out if this is purposeful
Expand All @@ -278,7 +265,7 @@ export class IterableInboxDataModel {
* @returns An object representing the inbox row view model.
*/
private static getInboxRowViewModelForMessage(
message: IterableInAppMessage
message: IterableInAppMessage,
): IterableInboxRowViewModel {
return {
title: message.inboxMetadata?.title ?? '',
Expand Down
Loading