Skip to content

[MOB-11436] Android: add serialization of placements #651

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

Draft
wants to merge 8 commits into
base: evan/embedded-message-class
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -486,20 +486,17 @@ public void updateVisibleRows(ReadableArray visibleRows) {
// region Embedded APIs

@ReactMethod
public void getEmbeddedPlacements(Promise promise) {
IterableLogger.d(TAG, "getEmbeddedPlacements");

JSONArray testPlacements = new JSONArray();
int[] testPlacementIds = {808, 1121, 112};

public void getEmbeddedMessages(Integer placementId, Promise promise) {
IterableLogger.d(TAG, "getEmbeddedMessages for placement: " + placementId);

try {
for (int placementId : testPlacementIds) {
testPlacements.put(createTestPlacement(placementId));
}

promise.resolve(Serialization.convertJsonToArray(testPlacements));
JSONArray embeddedMessageJsonArray = Serialization.serializeEmbeddedMessages(IterableApi.getInstance().getEmbeddedManager().getMessages(placementId));
IterableLogger.d(TAG, "Messages for placement: " + embeddedMessageJsonArray);

promise.resolve(Serialization.convertJsonToArray(embeddedMessageJsonArray));
} catch (JSONException e) {
promise.reject("", "Failed to create test placements");
IterableLogger.e(TAG, e.getLocalizedMessage());
promise.reject("", "Failed to fetch messages with error " + e.getLocalizedMessage());
}
}

Expand Down
12 changes: 12 additions & 0 deletions android/src/main/java/com/iterable/reactnative/Serialization.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.iterable.iterableapi.IterableActionContext;
import com.iterable.iterableapi.IterableConfig;
import com.iterable.iterableapi.IterableDataRegion;
import com.iterable.iterableapi.IterableEmbeddedMessage;
import com.iterable.iterableapi.IterableInAppCloseAction;
import com.iterable.iterableapi.IterableInAppDeleteActionType;
import com.iterable.iterableapi.IterableInAppHandler;
Expand Down Expand Up @@ -136,6 +137,17 @@ static JSONArray serializeInAppMessages(List<IterableInAppMessage> inAppMessages
return inAppMessagesJson;
}

static JSONArray serializeEmbeddedMessages(List<IterableEmbeddedMessage> embeddedMessages) {
JSONArray embeddedMessagesJson = new JSONArray();
if (embeddedMessages != null) {
for (IterableEmbeddedMessage message : embeddedMessages) {
JSONObject messageJson = IterableEmbeddedMessage.Companion.toJSONObject(message);
embeddedMessagesJson.put(messageJson);
}
}
return embeddedMessagesJson;
}

static IterableConfig.Builder getConfigFromReadableMap(ReadableMap iterableContextMap) {
try {
JSONObject iterableContextJSON = convertMapToJson(iterableContextMap);
Expand Down
11 changes: 7 additions & 4 deletions src/embedded/classes/IterableEmbeddedManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NativeModules } from 'react-native';

import { Iterable } from '../../core/classes/Iterable';
import { IterableEmbeddedPlacement } from './IterableEmbeddedPlacement';
import type { IterableEmbeddedMessage } from './IterableEmbeddedMessage';

const RNIterableAPI = NativeModules.RNIterableAPI;

Expand All @@ -14,11 +14,14 @@ export class IterableEmbeddedManager {
/**
* Retrieve the current user's list of embedded placements.
*
* @param {number} placementId The ID of the placement to retrieve messages from.
Copy link

Choose a reason for hiding this comment

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

tsdoc-param-tag-with-invalid-type: The @param block should not include a JSDoc-style '{type}' [eslint:tsdoc/syntax]

Copy link

Choose a reason for hiding this comment

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

tsdoc-param-tag-with-invalid-type: The @param block should not include a JSDoc-style '{type}' [eslint:tsdoc/syntax]

Copy link

Choose a reason for hiding this comment

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

tsdoc-param-tag-with-invalid-type: The @param block should not include a JSDoc-style '{type}' [eslint:tsdoc/syntax]

* @returns A Promise that resolves to an array of embedded placements.
*/
getPlacements(): Promise<IterableEmbeddedPlacement[]> {
Iterable?.logger?.log('EmbeddedManager.getPlacements');
getMessages(placementId: number): Promise<IterableEmbeddedMessage[]> {
Iterable?.logger?.log(
`EmbeddedManager.getMessages for placement ${placementId}`
);

return RNIterableAPI.getEmbeddedPlacements();
return RNIterableAPI.getEmbeddedMessages(placementId);
}
}