Skip to content

Commit ecb2a17

Browse files
Merge pull request #901 from Iterable/feature/SDK-550-disable-device-all-users
feat(SDK-550): expose disableDeviceForAllUsers on the RN SDK
2 parents e0b46ae + 8c0841b commit ecb2a17

12 files changed

Lines changed: 143 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## Unreleased
2+
3+
### Updates
4+
5+
- Added `Iterable.disableDeviceForAllUsers()` to unregister this device's push token from every user associated with the device (SDK-550).
6+
- iOS: forwards to native `IterableAPI.disableDeviceForAllUsers()`.
7+
- Android: graceful no-op that logs a warning; use `disableDeviceForCurrentUser()` to disable push for the current user. There is no public native "all users" equivalent.
8+
19
## 3.1.0
210

311
### Fixes

‎android/src/main/java/com/iterable/reactnative/RNIterableAPIModuleImpl.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,10 @@ public void disableDeviceForCurrentUser() {
373373
IterableApi.getInstance().disablePush();
374374
}
375375

376+
public void disableDeviceForAllUsers() {
377+
IterableLogger.w(TAG, "disableDeviceForAllUsers is not supported on Android; use disableDeviceForCurrentUser. There is no public native equivalent.");
378+
}
379+
376380
public void registerDeviceToken(String token) {
377381
IterableLogger.v(TAG, "registerDeviceToken");
378382
IterableApi.getInstance().registerDeviceToken(token);

‎android/src/newarch/java/com/RNIterableAPIModule.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ public void disableDeviceForCurrentUser() {
137137
moduleImpl.disableDeviceForCurrentUser();
138138
}
139139

140+
@Override
141+
public void disableDeviceForAllUsers() {
142+
moduleImpl.disableDeviceForAllUsers();
143+
}
144+
140145
@Override
141146
public void registerDeviceToken(String token) {
142147
moduleImpl.registerDeviceToken(token);

‎android/src/oldarch/java/com/RNIterableAPIModule.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ public void disableDeviceForCurrentUser() {
138138
moduleImpl.disableDeviceForCurrentUser();
139139
}
140140

141+
@ReactMethod
142+
public void disableDeviceForAllUsers() {
143+
moduleImpl.disableDeviceForAllUsers();
144+
}
145+
141146
@ReactMethod
142147
public void registerDeviceToken(String token) {
143148
moduleImpl.registerDeviceToken(token);

‎ios/RNIterableAPI/RNIterableAPI.mm‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ - (void)disableDeviceForCurrentUser {
230230
[_swiftAPI disableDeviceForCurrentUser];
231231
}
232232

233+
- (void)disableDeviceForAllUsers {
234+
[_swiftAPI disableDeviceForAllUsers];
235+
}
236+
233237
- (void)registerDeviceToken:(NSString *)token {
234238
[_swiftAPI registerDeviceToken:token];
235239
}
@@ -516,6 +520,10 @@ - (void)wakeApp {
516520
[_swiftAPI disableDeviceForCurrentUser];
517521
}
518522

523+
RCT_EXPORT_METHOD(disableDeviceForAllUsers) {
524+
[_swiftAPI disableDeviceForAllUsers];
525+
}
526+
519527
RCT_EXPORT_METHOD(registerDeviceToken : (NSString *)token) {
520528
[_swiftAPI registerDeviceToken:token];
521529
}

‎ios/RNIterableAPI/ReactIterableAPI.swift‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ import React
144144
IterableAPI.disableDeviceForCurrentUser()
145145
}
146146

147+
@objc(disableDeviceForAllUsers)
148+
public func disableDeviceForAllUsers() {
149+
ITBInfo()
150+
IterableAPI.disableDeviceForAllUsers()
151+
}
152+
147153
@objc(registerDeviceToken:)
148154
public func registerDeviceToken(token: String) {
149155
ITBInfo()

‎src/__mocks__/MockRNIterableAPI.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export class MockRNIterableAPI {
3434

3535
static disableDeviceForCurrentUser = jest.fn();
3636

37+
static disableDeviceForAllUsers = jest.fn();
38+
3739
static registerDeviceToken = jest.fn((token: string): void => {
3840
MockRNIterableAPI.token = token;
3941
});

‎src/api/NativeRNIterableAPI.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ export interface Spec extends TurboModule {
147147

148148
// Device management
149149
disableDeviceForCurrentUser(): void;
150+
disableDeviceForAllUsers(): void;
150151
registerDeviceToken(token: string): void;
151152
getLastPushPayload(): Promise<{
152153
[key: string]: string | number | boolean;

‎src/core/classes/Iterable.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ describe('Iterable', () => {
143143
});
144144
});
145145

146+
describe('disableDeviceForAllUsers', () => {
147+
it('should disable the device for all users', () => {
148+
// GIVEN no parameters
149+
// WHEN Iterable.disableDeviceForAllUsers is called
150+
Iterable.disableDeviceForAllUsers();
151+
// THEN corresponding method is called on RNIterableAPI
152+
expect(MockRNIterableAPI.disableDeviceForAllUsers).toBeCalled();
153+
});
154+
});
155+
146156
describe('registerDeviceToken', () => {
147157
it('should register the device token for the current user', () => {
148158
// GIVEN a device token

‎src/core/classes/Iterable.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,27 @@ export class Iterable {
345345
IterableApi.disableDeviceForCurrentUser();
346346
}
347347

348+
/**
349+
* Disable this device's push token for every user associated with the device,
350+
* not only the currently signed-in user.
351+
*
352+
* On iOS this forwards to native `IterableAPI.disableDeviceForAllUsers()`.
353+
* On Android this is a no-op that logs a warning in Metro and logcat: the
354+
* native Android SDK has no public "all users" equivalent. Use
355+
* {@link disableDeviceForCurrentUser} to disable push for the current user
356+
* on both platforms. The native Android method is still invoked.
357+
*
358+
* Fire-and-forget: native success or failure is not surfaced to JS.
359+
*
360+
* @example
361+
* ```typescript
362+
* Iterable.disableDeviceForAllUsers();
363+
* ```
364+
*/
365+
static disableDeviceForAllUsers() {
366+
IterableApi.disableDeviceForAllUsers();
367+
}
368+
348369
/**
349370
* Register the device's token for the current user, re-enabling push notifications.
350371
*

0 commit comments

Comments
 (0)