Skip to content

Commit 276f3c7

Browse files
alyezzAliAbdelfattah
authored andcommitted
Map setPushNotificationsEnabled API on android
1 parent d241867 commit 276f3c7

File tree

5 files changed

+27
-21
lines changed

5 files changed

+27
-21
lines changed

__tests__/index.spec.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,6 @@ describe('Instabug Module', () => {
196196

197197
});
198198

199-
it('should not call the native method setPushNotificationsEnabled when platform is android', () => {
200-
201-
Platform.OS = 'android';
202-
Instabug.setPushNotificationsEnabled(true);
203-
204-
expect(setPushNotificationsEnabled.notCalled).toBe(true);
205-
206-
});
207-
208199
it('should call the native method setLocale', () => {
209200

210201
const locale = Instabug.locale.english;

__tests__/replies.spec.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,12 @@ describe('Replies Module', () => {
126126

127127
it('should call the native method setPushNotificationsEnabled', () => {
128128

129-
Platform.OS = 'ios';
130129
Replies.setPushNotificationsEnabled(true);
131130

132131
expect(setPushNotificationsEnabled.calledOnceWithExactly(true)).toBe(true);
133132

134133
});
135134

136-
it('should not call the native method setPushNotificationsEnabled when platform is android', () => {
137-
138-
Platform.OS = 'android';
139-
Replies.setPushNotificationsEnabled(true);
140-
141-
expect(setPushNotificationsEnabled.notCalled).toBe(true);
142-
143-
});
144-
145135

146136
it('should call the native method setPushNotificationRegistrationToken on Android', () => {
147137
Platform.OS = 'android';

android/src/main/java/com/instabug/reactlibrary/RNInstabugRepliesModule.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,29 @@ public void run() {
108108
});
109109
}
110110

111+
/**
112+
* Enabled/disable push notifications
113+
*
114+
* @param isEnabled whether chat push notifications is enabled or not
115+
*/
116+
@ReactMethod
117+
public void setPushNotificationsEnabled(final boolean isEnabled) {
118+
MainThreadHandler.runOnMainThread(new Runnable() {
119+
@Override
120+
public void run() {
121+
try {
122+
if (isEnabled) {
123+
Replies.setPushNotificationState(Feature.State.ENABLED);
124+
} else {
125+
Replies.setPushNotificationState(Feature.State.DISABLED);
126+
}
127+
} catch (Exception e) {
128+
e.printStackTrace();
129+
}
130+
}
131+
});
132+
}
133+
111134
/**
112135
* Enabled/disable chat notification
113136
*

index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ export namespace Replies {
9494
function setInAppNotificationsEnabled(
9595
inAppNotificationsEnabled: boolean
9696
): void;
97+
function setPushNotificationsEnabled(
98+
isPushNotificationEnabled: boolean
99+
): void;
97100
function setInAppNotificationSound(shouldPlaySound: boolean): void;
98101
function setPushNotificationRegistrationTokenAndroid(token: string): void;
99102
function setNotificationIconAndroid(notificationIcon: int): void;

modules/Replies.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ export default {
9696
* notifications are enabled or disabled.
9797
*/
9898
setPushNotificationsEnabled(isPushNotificationEnabled) {
99-
if (Platform.OS === 'ios')
100-
IBGReplies.setPushNotificationsEnabled(isPushNotificationEnabled);
99+
IBGReplies.setPushNotificationsEnabled(isPushNotificationEnabled);
101100
},
102101

103102
/**

0 commit comments

Comments
 (0)