diff --git a/CHANGELOG.md b/CHANGELOG.md index 77c5076..79d5399 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ---- diff --git a/android/src/main/java/com/batch/batch_rn/RNBatchInbox.java b/android/src/main/java/com/batch/batch_rn/RNBatchInbox.java index 086898c..e446bf2 100644 --- a/android/src/main/java/com/batch/batch_rn/RNBatchInbox.java +++ b/android/src/main/java/com/batch/batch_rn/RNBatchInbox.java @@ -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; @@ -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 notifications) + protected static WritableArray getSuccessResponse(List notifications, Context context) { final WritableArray rnNotifications = new WritableNativeArray(); for (BatchInboxNotificationContent notification : notifications) { - rnNotifications.pushMap(getWritableMapNotification(notification)); + rnNotifications.pushMap(getWritableMapNotification(notification, context)); } return rnNotifications; @@ -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(); @@ -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; } } diff --git a/android/src/main/java/com/batch/batch_rn/RNBatchModule.java b/android/src/main/java/com/batch/batch_rn/RNBatchModule.java index 05154f4..4d7ae1f 100644 --- a/android/src/main/java/com/batch/batch_rn/RNBatchModule.java +++ b/android/src/main/java/com/batch/batch_rn/RNBatchModule.java @@ -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"; @@ -439,7 +439,7 @@ public void inbox_fetcher_fetchNewNotifications(String fetcherIdentifier, Promis public void onFetchSuccess(@NonNull List 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); @@ -465,7 +465,7 @@ public void inbox_fetcher_fetchNextPage(String fetcherIdentifier, Promise promis fetcher.fetchNextPage(new BatchInboxFetcher.OnNextPageFetchedListener() { @Override public void onFetchSuccess(@NonNull List 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); diff --git a/ios/RNBatch.h b/ios/RNBatch.h index 1a2a569..1d44b2b 100644 --- a/ios/RNBatch.h +++ b/ios/RNBatch.h @@ -1,4 +1,4 @@ -#define PluginVersion "ReactNative/12.0.0" +#define PluginVersion "ReactNative/12.1.0" @interface RNBatch: NSObject diff --git a/ios/RNBatch.mm b/ios/RNBatch.mm index 2d76382..0d45bec 100644 --- a/ios/RNBatch.mm +++ b/ios/RNBatch.mm @@ -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]; @@ -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 diff --git a/package.json b/package.json index 0f1bef2..42572a0 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/BatchInbox.ts b/src/BatchInbox.ts index a0c57c1..86ecd7a 100644 --- a/src/BatchInbox.ts +++ b/src/BatchInbox.ts @@ -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 */