-
Notifications
You must be signed in to change notification settings - Fork 35
[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
Changes from 7 commits
11174ca
eecd501
440b326
f87662d
32da43e
5c6da49
7aecec5
00ee6ad
525eab2
449c68d
392b51a
2ed58ad
f935077
ae85bdb
bf51fd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
This file was deleted.
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'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
* | ||
|
@@ -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(); | ||
} | ||
|
@@ -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(); | ||
} | ||
|
@@ -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); | ||
} | ||
|
@@ -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); | ||
} | ||
|
@@ -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); | ||
} | ||
|
@@ -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); | ||
} | ||
|
@@ -167,7 +163,7 @@ export class IterableInAppManager { | |
* ``` | ||
*/ | ||
setAutoDisplayPaused(paused: boolean) { | ||
Iterable.logger.log('InAppManager.setAutoDisplayPaused'); | ||
Iterable?.logger?.log('InAppManager.setAutoDisplayPaused'); | ||
|
||
RNIterableAPI.setAutoDisplayPaused(paused); | ||
} | ||
|
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'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused expression, expected an assignment or function call There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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. | ||
|
@@ -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; | ||
|
@@ -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); | ||
} | ||
}, | ||
); | ||
} | ||
|
||
|
@@ -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); | ||
} | ||
|
@@ -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); | ||
} | ||
|
@@ -140,7 +133,7 @@ export class IterableInboxDataModel { | |
}, | ||
() => { | ||
return []; | ||
} | ||
}, | ||
); | ||
} | ||
|
||
|
@@ -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); | ||
|
@@ -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); | ||
} | ||
|
||
/** | ||
|
@@ -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 | ||
|
@@ -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 ?? '', | ||
|
There was a problem hiding this comment.
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