Skip to content

Commit 53c015b

Browse files
inbox: add new properties to IInboxNotification
1 parent f18f34e commit 53c015b

File tree

5 files changed

+93
-8
lines changed

5 files changed

+93
-8
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
INCOMING
2+
----
3+
4+
**Inbox**
5+
- Added `androidCustomLargeIcon` property to `IInboxNotification`.
6+
- Added `androidBigPicture` property to `IInboxNotification`.
7+
- Added `deeplink` property to `IInboxNotification`.
8+
19
12.0.0
210
----
311

android/src/main/java/com/batch/batch_rn/RNBatchInbox.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package com.batch.batch_rn;
22

3+
import android.content.Context;
4+
import android.os.Bundle;
35
import android.util.Log;
46

57
import com.batch.android.BatchInboxNotificationContent;
8+
import com.batch.android.BatchPushPayload;
69
import com.facebook.react.bridge.WritableArray;
710
import com.facebook.react.bridge.WritableMap;
811
import com.facebook.react.bridge.WritableNativeArray;
@@ -11,17 +14,20 @@
1114
import org.json.JSONException;
1215
import org.json.JSONObject;
1316

17+
import java.util.HashMap;
1418
import java.util.List;
1519
import java.util.Map;
1620

21+
import androidx.annotation.NonNull;
22+
1723
public class RNBatchInbox {
1824
final private static String TAG = "BatchRNPluginInbox";
1925

20-
protected static WritableArray getSuccessResponse(List<BatchInboxNotificationContent> notifications)
26+
protected static WritableArray getSuccessResponse(List<BatchInboxNotificationContent> notifications, Context context)
2127
{
2228
final WritableArray rnNotifications = new WritableNativeArray();
2329
for (BatchInboxNotificationContent notification : notifications) {
24-
rnNotifications.pushMap(getWritableMapNotification(notification));
30+
rnNotifications.pushMap(getWritableMapNotification(notification, context));
2531
}
2632

2733
return rnNotifications;
@@ -44,7 +50,7 @@ protected static JSONObject getErrorResponse(String reason)
4450
}
4551
}
4652

47-
private static WritableMap getWritableMapNotification(BatchInboxNotificationContent notification)
53+
private static WritableMap getWritableMapNotification(BatchInboxNotificationContent notification, Context context)
4854
{
4955
final WritableMap output = new WritableNativeMap();
5056

@@ -72,6 +78,25 @@ private static WritableMap getWritableMapNotification(BatchInboxNotificationCont
7278

7379
output.putMap("payload", RNUtils.convertMapToWritableMap((Map) notification.getRawPayload()));
7480
output.putBoolean("hasLandingMessage", notification.hasLandingMessage());
81+
82+
try {
83+
BatchPushPayload pushPayload = notification.getPushPayload();
84+
85+
// Deeplink
86+
output.putString("deeplink", pushPayload.getDeeplink());
87+
88+
// Custom large icon
89+
output.putString("androidCustomLargeIcon", pushPayload.getCustomLargeIconURL(context));
90+
91+
// Big picture
92+
output.putString("androidBigPicture", pushPayload.getBigPictureURL(context));
93+
} catch (BatchPushPayload.ParsingException e) {
94+
Log.d(TAG, "Failed to parse push payload: " + e.getMessage());
95+
output.putNull("deeplink");
96+
output.putNull("androidCustomLargeIcon");
97+
output.putNull("androidBigPicture");
98+
}
99+
75100
return output;
76101
}
77102
}

android/src/main/java/com/batch/batch_rn/RNBatchModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ public void inbox_fetcher_fetchNewNotifications(String fetcherIdentifier, Promis
439439
public void onFetchSuccess(@NonNull List<BatchInboxNotificationContent> notifications,
440440
boolean foundNewNotifications,
441441
boolean endReached) {
442-
WritableArray formattedNotifications = RNBatchInbox.getSuccessResponse(notifications);
442+
WritableArray formattedNotifications = RNBatchInbox.getSuccessResponse(notifications, getReactApplicationContext());
443443
WritableMap results = new WritableNativeMap();
444444
results.putArray("notifications", formattedNotifications);
445445
results.putBoolean("foundNewNotifications", foundNewNotifications);
@@ -465,7 +465,7 @@ public void inbox_fetcher_fetchNextPage(String fetcherIdentifier, Promise promis
465465
fetcher.fetchNextPage(new BatchInboxFetcher.OnNextPageFetchedListener() {
466466
@Override
467467
public void onFetchSuccess(@NonNull List<BatchInboxNotificationContent> notifications, boolean endReached) {
468-
WritableArray formattedNotifications = RNBatchInbox.getSuccessResponse(notifications);
468+
WritableArray formattedNotifications = RNBatchInbox.getSuccessResponse(notifications, getReactApplicationContext());
469469
WritableMap results = new WritableNativeMap();
470470
results.putArray("notifications", formattedNotifications);
471471
results.putBoolean("endReached", endReached);

ios/RNBatch.mm

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,9 @@ - (NSDictionary*) dictionaryWithNotification:(BatchInboxNotificationContent*)not
916916
@"date": [NSNumber numberWithDouble:notification.date.timeIntervalSince1970 * 1000],
917917
@"source": source,
918918
@"payload": notification.payload,
919-
@"hasLandingMessage": @(notification.hasLandingMessage)
919+
@"hasLandingMessage": @(notification.hasLandingMessage),
920+
@"deeplink": [self deeplinkFromPushPayload:notification.payload] ?: [NSNull null],
921+
@"iOSAttachmentURL": notification.attachmentURL.absoluteString ?: [NSNull null],
920922
};
921923

922924
NSMutableDictionary *mutableOutput = [output mutableCopy];
@@ -926,8 +928,43 @@ - (NSDictionary*) dictionaryWithNotification:(BatchInboxNotificationContent*)not
926928
if (body != nil) {
927929
mutableOutput[@"body"] = body;
928930
}
929-
output = mutableOutput;
930-
return output;
931+
return [mutableOutput copy];
932+
}
933+
934+
- (nullable NSString*) deeplinkFromPushPayload:(NSDictionary*)payload
935+
{
936+
NSString *deeplink = nil;
937+
id batchData = @{};
938+
939+
if ([payload isKindOfClass:[NSDictionary class]]) {
940+
batchData = payload[@"com.batch"] ?: @{};
941+
942+
deeplink = [self extractDeeplinkFromBatchData:batchData];
943+
944+
if (!deeplink) {
945+
id rootDeeplink = payload[@"deeplink"];
946+
if (rootDeeplink && [rootDeeplink isKindOfClass:[NSString class]]) {
947+
deeplink = (NSString *)rootDeeplink;
948+
}
949+
}
950+
}
951+
952+
return deeplink;
953+
}
954+
955+
- (NSString*) extractDeeplinkFromBatchData:(id)batchData
956+
{
957+
if (![batchData isKindOfClass:[NSDictionary class]]) {
958+
return nil;
959+
}
960+
961+
NSDictionary *batchDict = (NSDictionary *)batchData;
962+
id deepLinkValue = batchDict[@"l"];
963+
if (deepLinkValue && [deepLinkValue isKindOfClass:[NSString class]]) {
964+
return (NSString *)deepLinkValue;
965+
}
966+
967+
return nil;
931968
}
932969

933970
// Messaging module

src/BatchInbox.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ export interface IInboxNotification {
3434
*/
3535
payload: unknown;
3636

37+
/**
38+
* URL of the custom large icon (if present) - Android Only
39+
*/
40+
androidCustomLargeIcon?: string;
41+
42+
/**
43+
* URL of the big picture (if present) - Android Only
44+
*/
45+
androidBigPicture?: string;
46+
47+
/**
48+
* Deeplink attached to the notification (if present)
49+
*/
50+
deeplink?: string;
51+
3752
/**
3853
* Date at which the push notification has been sent to the device
3954
*/

0 commit comments

Comments
 (0)