Skip to content
Merged
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
12.1.0
----

**Inbox**
- Added `androidCustomLargeIcon` property to `IInboxNotification`.
- Added `androidBigPicture` property to `IInboxNotification`.
- Added `deeplink` property to `IInboxNotification`.


12.0.0
----

Expand Down
31 changes: 28 additions & 3 deletions android/src/main/java/com/batch/batch_rn/RNBatchInbox.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.batch.batch_rn;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;

import com.batch.android.BatchInboxNotificationContent;
import com.batch.android.BatchPushPayload;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeArray;
Expand All @@ -11,17 +14,20 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import androidx.annotation.NonNull;

public class RNBatchInbox {
final private static String TAG = "BatchRNPluginInbox";

protected static WritableArray getSuccessResponse(List<BatchInboxNotificationContent> notifications)
protected static WritableArray getSuccessResponse(List<BatchInboxNotificationContent> notifications, Context context)
{
final WritableArray rnNotifications = new WritableNativeArray();
for (BatchInboxNotificationContent notification : notifications) {
rnNotifications.pushMap(getWritableMapNotification(notification));
rnNotifications.pushMap(getWritableMapNotification(notification, context));
}

return rnNotifications;
Expand All @@ -44,7 +50,7 @@ protected static JSONObject getErrorResponse(String reason)
}
}

private static WritableMap getWritableMapNotification(BatchInboxNotificationContent notification)
private static WritableMap getWritableMapNotification(BatchInboxNotificationContent notification, Context context)
{
final WritableMap output = new WritableNativeMap();

Expand Down Expand Up @@ -72,6 +78,25 @@ private static WritableMap getWritableMapNotification(BatchInboxNotificationCont

output.putMap("payload", RNUtils.convertMapToWritableMap((Map) notification.getRawPayload()));
output.putBoolean("hasLandingMessage", notification.hasLandingMessage());

try {
BatchPushPayload pushPayload = notification.getPushPayload();

// Deeplink
output.putString("deeplink", pushPayload.getDeeplink());

// Custom large icon
output.putString("androidCustomLargeIcon", pushPayload.getCustomLargeIconURL(context));

// Big picture
output.putString("androidBigPicture", pushPayload.getBigPictureURL(context));
} catch (BatchPushPayload.ParsingException e) {
Log.d(TAG, "Failed to parse push payload: " + e.getMessage());
output.putNull("deeplink");
output.putNull("androidCustomLargeIcon");
output.putNull("androidBigPicture");
}

return output;
}
}
6 changes: 3 additions & 3 deletions android/src/main/java/com/batch/batch_rn/RNBatchModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class RNBatchModule extends NativeRNBatchModuleSpec {

private static final String PLUGIN_VERSION_ENVIRONMENT_VARIABLE = "batch.plugin.version";

public static final String PLUGIN_VERSION = "ReactNative/12.0.0";
public static final String PLUGIN_VERSION = "ReactNative/12.1.0";

public static final String LOGGER_TAG = "RNBatchBridge";

Expand Down Expand Up @@ -439,7 +439,7 @@ public void inbox_fetcher_fetchNewNotifications(String fetcherIdentifier, Promis
public void onFetchSuccess(@NonNull List<BatchInboxNotificationContent> notifications,
boolean foundNewNotifications,
boolean endReached) {
WritableArray formattedNotifications = RNBatchInbox.getSuccessResponse(notifications);
WritableArray formattedNotifications = RNBatchInbox.getSuccessResponse(notifications, getReactApplicationContext());
WritableMap results = new WritableNativeMap();
results.putArray("notifications", formattedNotifications);
results.putBoolean("foundNewNotifications", foundNewNotifications);
Expand All @@ -465,7 +465,7 @@ public void inbox_fetcher_fetchNextPage(String fetcherIdentifier, Promise promis
fetcher.fetchNextPage(new BatchInboxFetcher.OnNextPageFetchedListener() {
@Override
public void onFetchSuccess(@NonNull List<BatchInboxNotificationContent> notifications, boolean endReached) {
WritableArray formattedNotifications = RNBatchInbox.getSuccessResponse(notifications);
WritableArray formattedNotifications = RNBatchInbox.getSuccessResponse(notifications, getReactApplicationContext());
WritableMap results = new WritableNativeMap();
results.putArray("notifications", formattedNotifications);
results.putBoolean("endReached", endReached);
Expand Down
2 changes: 1 addition & 1 deletion ios/RNBatch.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define PluginVersion "ReactNative/12.0.0"
#define PluginVersion "ReactNative/12.1.0"

@interface RNBatch: NSObject

Expand Down
43 changes: 40 additions & 3 deletions ios/RNBatch.mm
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,9 @@ - (NSDictionary*) dictionaryWithNotification:(BatchInboxNotificationContent*)not
@"date": [NSNumber numberWithDouble:notification.date.timeIntervalSince1970 * 1000],
@"source": source,
@"payload": notification.payload,
@"hasLandingMessage": @(notification.hasLandingMessage)
@"hasLandingMessage": @(notification.hasLandingMessage),
@"deeplink": [self deeplinkFromPushPayload:notification.payload] ?: [NSNull null],
@"iOSAttachmentURL": notification.attachmentURL.absoluteString ?: [NSNull null],
};

NSMutableDictionary *mutableOutput = [output mutableCopy];
Expand All @@ -926,8 +928,43 @@ - (NSDictionary*) dictionaryWithNotification:(BatchInboxNotificationContent*)not
if (body != nil) {
mutableOutput[@"body"] = body;
}
output = mutableOutput;
return output;
return [mutableOutput copy];
}

- (nullable NSString*) deeplinkFromPushPayload:(NSDictionary*)payload
{
NSString *deeplink = nil;
id batchData = @{};

if ([payload isKindOfClass:[NSDictionary class]]) {
batchData = payload[@"com.batch"] ?: @{};

deeplink = [self extractDeeplinkFromBatchData:batchData];

if (!deeplink) {
id rootDeeplink = payload[@"deeplink"];
if (rootDeeplink && [rootDeeplink isKindOfClass:[NSString class]]) {
deeplink = (NSString *)rootDeeplink;
}
}
}

return deeplink;
}

- (NSString*) extractDeeplinkFromBatchData:(id)batchData
{
if (![batchData isKindOfClass:[NSDictionary class]]) {
return nil;
}

NSDictionary *batchDict = (NSDictionary *)batchData;
id deepLinkValue = batchDict[@"l"];
if (deepLinkValue && [deepLinkValue isKindOfClass:[NSString class]]) {
return (NSString *)deepLinkValue;
}

return nil;
}

// Messaging module
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@batch.com/react-native-plugin",
"version": "12.0.0",
"version": "12.1.0",
"description": "Batch.com React-Native Plugin",
"homepage": "https://github.com/BatchLabs/Batch-React-Native-Plugin",
"main": "dist/Batch.js",
Expand Down
15 changes: 15 additions & 0 deletions src/BatchInbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ export interface IInboxNotification {
*/
payload: unknown;

/**
* URL of the custom large icon (if present) - Android Only
*/
androidCustomLargeIcon?: string;

/**
* URL of the big picture (if present) - Android Only
*/
androidBigPicture?: string;

/**
* Deeplink attached to the notification (if present)
*/
deeplink?: string;

/**
* Date at which the push notification has been sent to the device
*/
Expand Down