Skip to content
This repository was archived by the owner on Jul 28, 2022. It is now read-only.

Commit 8e787eb

Browse files
committed
Add BatchMessaging.disableDoNotDisturbAndShowPendingMessage to save a roundtrip
1 parent 47f50de commit 8e787eb

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ When your app is ready to be interacted with (for example, after showing the spl
171171
```js
172172
import { BatchMessaging } from '@bam.tech/react-native-batch';
173173

174-
await BatchMessaging.setNotDisturbed(false);
175-
await BatchMessaging.showPendingMessage();
174+
await BatchMessaging.disableDoNotDisturbAndShowPendingMessage();
176175
```
177176

178177
**NB:** Batch's Do Not Disturb mode is enabled by default in React Native because your JS app might not be loaded when the user interacts with it. This could lead to problems when a button should redirect inside your JS app. You can disable this behaviour (see below).

android/src/main/java/tech/bam/RNBatchPush/RNBatchModule.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,16 @@ public void push_getLastKnownPushToken(Promise promise) {
156156

157157
// MESSAGING MODULE
158158

159+
private void showPendingMessage() {
160+
BatchMessage message = Batch.Messaging.popPendingMessage();
161+
if (message != null) {
162+
Batch.Messaging.show(getCurrentActivity(), message);
163+
}
164+
}
165+
159166
@ReactMethod
160167
public void messaging_showPendingMessage(Promise promise) {
161-
BatchMessage msg = Batch.Messaging.popPendingMessage();
162-
if (msg != null) {
163-
Batch.Messaging.show(getCurrentActivity(), msg);
164-
}
168+
showPendingMessage();
165169

166170
promise.resolve(null);
167171
}
@@ -173,6 +177,14 @@ public void messaging_setNotDisturbed(final boolean active, Promise promise) {
173177
promise.resolve(null);
174178
}
175179

180+
@ReactMethod
181+
public void messaging_disableDoNotDisturbAndShowPendingMessage(Promise promise) {
182+
Batch.Messaging.setDoNotDisturbEnabled(false);
183+
showPendingMessage();
184+
185+
promise.resolve(null);
186+
}
187+
176188
@ReactMethod
177189
public void messaging_setTypefaceOverride(@Nullable String normalTypefaceName, @Nullable String boldTypefaceName, Promise promise) {
178190
AssetManager assetManager = this.reactContext.getAssets();

ios/RNBatch.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,15 @@ - (NSDictionary*) dictionaryWithNotification:(BatchInboxNotificationContent*)not
590590
});
591591
}
592592

593+
RCT_EXPORT_METHOD(messaging_disableDoNotDisturbAndShowPendingMessage:(RCTPromiseResolveBlock)resolve
594+
rejecter:(RCTPromiseRejectBlock)reject) {
595+
dispatch_async(dispatch_get_main_queue(), ^{
596+
[BatchMessaging setDoNotDisturb:false];
597+
[BatchMessaging showPendingMessage];
598+
resolve([NSNull null]);
599+
});
600+
}
601+
593602
RCT_EXPORT_METHOD(messaging_setFontOverride:(nullable NSString*) normalFontName boldFontName:(nullable NSString*) boldFontName italicFontName:(nullable NSString*) italicFontName italicBoldFontName:(nullable NSString*) italicBoldFontName
594603
resolver: (RCTPromiseResolveBlock)resolve
595604
rejecter:(RCTPromiseRejectBlock)reject)

src/BatchMessaging.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ export const BatchMessaging = {
1616
setNotDisturbed: (active: boolean): Promise<void> =>
1717
RNBatch.messaging_setNotDisturbed(active),
1818

19+
/**
20+
* Disables do not disturb mode and shows the currently enqueued message, if any.
21+
*/
22+
disableDoNotDisturbAndShowPendingMessage: (): Promise<void> =>
23+
RNBatch.messaging_disableDoNotDisturbAndShowPendingMessage(),
24+
1925
/**
2026
* Override the font used in message views. Not applicable for standard alerts.
2127
* [iOS](https://doc.batch.com/ios-api-reference/Classes/BatchMessaging.html#/c:objc(cs)BatchMessaging(cm)setFontOverride:boldFont:italicFont:boldItalicFont:)

0 commit comments

Comments
 (0)