Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
UPCOMING
----
**Plugin**
- Updated Batch to 3.3

**Profile**
- Added `setTopicPreferences` API to the `BatchProfileAttributeEditor`.
- Added `addToTopicPreferences` API to the `BatchProfileAttributeEditor`.
- Added `removeFromTopicPreferences` API to the `BatchProfileAttributeEditor`.

**Push**
- Added `BatchPush.requestNotificationAuthorizationAsync()` to request notification authorization and return a promise that resolve with the authorization result.
Expand Down
2 changes: 1 addition & 1 deletion RNBatchPush.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Pod::Spec.new do |s|
install_modules_dependencies(s)

s.dependency "React"
s.dependency 'Batch', '~> 3.1.0'
s.dependency 'Batch', '~> 3.3.0'

s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
end
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ def DEFAULT_MIN_SDK_VERSION = 21
def DEFAULT_COMPILE_SDK_VERSION = 36
def DEFAULT_BUILD_TOOLS_VERSION = "36.0.0"
def DEFAULT_TARGET_SDK_VERSION = 36
def DEFAULT_BATCH_SDK_VERSION = "3.1.+"
def DEFAULT_BATCH_SDK_VERSION = "3.3.+"

def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
Expand Down
14 changes: 14 additions & 0 deletions android/src/main/java/com/batch/batch_rn/RNBatchModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,20 @@ public void profile_saveEditor(ReadableArray actions) {
} else if (type.equals("setSMSMarketingSubscription")) {
String value = action.getString("value");
editor.setSMSMarketingSubscription(BatchSMSSubscriptionState.valueOf(value));
} else if (type.equals("setTopicPreferences")) {
ReadableType valueType = action.getType("value");
if (valueType.equals(ReadableType.Null)) {
editor.setTopicPreferences(null);
} else {
ReadableArray arrayValue = action.getArray("value");
editor.setTopicPreferences(RNUtils.convertReadableArrayToList(arrayValue));
}
} else if (type.equals("addToTopicPreferences")) {
ReadableArray arrayValue = action.getArray("value");
editor.addToTopicPreferences(RNUtils.convertReadableArrayToList(arrayValue));
} else if (type.equals("removeFromTopicPreferences")) {
ReadableArray arrayValue = action.getArray("value");
editor.removeFromTopicPreferences(RNUtils.convertReadableArrayToList(arrayValue));
} else if (type.equals("setLanguage")) {
ReadableType valueType = action.getType("value");
if (valueType.equals(ReadableType.Null)) {
Expand Down
12 changes: 12 additions & 0 deletions ios/RNBatch.mm
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,18 @@ - (void)profile_saveEditor:(NSArray*)actions
}
}

else if([type isEqualToString:@"setTopicPreferences"]) {
[editor setTopicPreferences:[self safeNilValue:action[@"value"]] error:nil];
}

else if([type isEqualToString:@"addToTopicPreferences"]) {
[editor addToTopicPreferences:action[@"value"] error:nil];
}

else if([type isEqualToString:@"removeFromTopicPreferences"]) {
[editor removeFromTopicPreferences:action[@"value"] error:nil];
}

else if([type isEqualToString:@"setLanguage"]) {
[editor setLanguage:[self safeNilValue:action[@"value"]] error:nil];
}
Expand Down
90 changes: 77 additions & 13 deletions src/BatchProfileAttributeEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ interface IUserSettingsSetSMSMarketingSubscriptionAction {
value: BatchSMSSubscriptionState;
}

interface IUserSettingsSetTopicPreferencesAction {
type: 'setTopicPreferences';
value: string[] | null;
}

interface IUserSettingsAddToTopicPreferencesAction {
type: 'addToTopicPreferences';
value: string[];
}

interface IUserSettingsRemoveFromTopicPreferencesAction {
type: 'removeFromTopicPreferences';
value: string[];
}

interface IUserSettingsAddToArrayAction {
type: 'addToArray';
key: string;
Expand All @@ -93,7 +108,10 @@ type IUserSettingsAction =
| IUserSettingsSetEmailAddressAction
| IUserSettingsSetEmailMarketingSubscriptionAction
| IUserSettingsSetPhoneNumberAction
| IUserSettingsSetSMSMarketingSubscriptionAction;
| IUserSettingsSetSMSMarketingSubscriptionAction
| IUserSettingsSetTopicPreferencesAction
| IUserSettingsAddToTopicPreferencesAction
| IUserSettingsRemoveFromTopicPreferencesAction;

type IUserSettingsActions = IUserSettingsAction[];

Expand All @@ -114,9 +132,10 @@ export class BatchProfileAttributeEditor {

/**
* Set an attribute for a key
* @param key Attribute key. Cannot be null, empty or undefined. It should be made of letters, numbers or underscores
*
* @param key Attribute key. Cannot be null, empty, or undefined. It should be made of letters, numbers or underscores
* ([a-z0-9_]) and can't be longer than 30 characters.
* @param value Attribute value. Accepted types are strings, numbers, booleans and array of strings.
* @param value Attribute value. Accepted types are strings, numbers, booleans, and array of strings.
*/
public setAttribute(key: string, value: string | boolean | number | string[] | null): BatchProfileAttributeEditor {
return this.addAction({
Expand All @@ -129,7 +148,7 @@ export class BatchProfileAttributeEditor {
/**
* Set a Date attribute for a key
*
* @param key Attribute key. Cannot be null, empty or undefined. It should be made of letters, numbers or underscores
* @param key Attribute key. Cannot be null, empty, or undefined. It should be made of letters, numbers or underscores
* ([a-z0-9_]) and can't be longer than 30 characters.
* @param value The date value
*
Expand All @@ -150,7 +169,7 @@ export class BatchProfileAttributeEditor {
/**
* Set an URL attribute for a key
*
* @param key Attribute key. Cannot be null, empty or undefined. It should be made of letters, numbers or underscores
* @param key Attribute key. Cannot be null, empty, or undefined. It should be made of letters, numbers or underscores
* ([a-z0-9_]) and can't be longer than 30 characters.
* @param value The URL value
*
Expand All @@ -170,6 +189,7 @@ export class BatchProfileAttributeEditor {

/**
* Remove an attribute
*
* @param key The key of the attribute to remove
*/
public removeAttribute(key: string): BatchProfileAttributeEditor {
Expand All @@ -182,7 +202,7 @@ export class BatchProfileAttributeEditor {
/**
* Set the profile email address.
*
* This requires to have a custom user ID registered
* This requires having a custom user ID registered
* or to call the `setIdentifier` method on the editor instance beforehand.
* @param value A valid email address. Null to erase.
*/
Expand All @@ -208,7 +228,7 @@ export class BatchProfileAttributeEditor {
/**
* Set the profile phone number.
*
* This requires to have a custom profile ID registered or to call the `identify` method beforehand.
* This requires having a custom profile ID registered or to call the `identify` method beforehand.
* @param value A valid E.164 formatted string. Must start with a `+` and not be longer than 15 digits
* without special characters (eg: "+33123456789"). Null to reset.
*/
Expand All @@ -222,7 +242,7 @@ export class BatchProfileAttributeEditor {
/**
* Set the profile SMS marketing subscription state.
*
* Note that profile's subscription status is automatically set to unsubscribed when users send a STOP message.
* Note that a profile's subscription status is automatically set to unsubscribed when users send a STOP message.
* @param value The state of the SMS marketing subscription. Must be "subscribed" or "unsubscribed".
*/
public setSMSMarketingSubscription(value: BatchSMSSubscriptionState): BatchProfileAttributeEditor {
Expand All @@ -232,6 +252,50 @@ export class BatchProfileAttributeEditor {
});
}

/**
* Set the profile topic preferences.
*
* @param value Array of topics to set. Null to reset.
* Must be a valid string array not longer than 25 items.
* String should be made of letters, numbers or underscores ([a-z0-9_]) and can't be longer than 300 characters.
*/
public setTopicPreferences(value: string[] | null): BatchProfileAttributeEditor {
return this.addAction({
type: 'setTopicPreferences',
value,
});
}

/**
* Add topics to the profile topic preferences.
*
* @param value Topics to add.
* Must be a valid string array not longer than 25 items or a single string.
* String should be made of letters, numbers or underscores ([a-z0-9_]) and can't be longer than 300 characters.
*/
public addToTopicPreferences(value: string | string[]): BatchProfileAttributeEditor {
const arrayValue = Array.isArray(value) ? value : [value];
return this.addAction({
type: 'addToTopicPreferences',
value: arrayValue,
});
}

/**
* Remove topics from the profile topic preferences.
*
* @param value Topics to remove.
* Must be a valid string array not longer than 25 items or a single string.
* String should be made of letters, numbers or underscores ([a-z0-9_]) and can't be longer than 300 characters.
*/
public removeFromTopicPreferences(value: string | string[]): BatchProfileAttributeEditor {
const arrayValue = Array.isArray(value) ? value : [value];
return this.addAction({
type: 'removeFromTopicPreferences',
value: arrayValue,
});
}

/**
* Set the application language. Overrides Batch's automatically detected language.
*
Expand Down Expand Up @@ -259,11 +323,11 @@ export class BatchProfileAttributeEditor {
}

/**
* Add value to an array attribute. If the array doesn't exist it will be created.
* Add value to an array attribute. If the array doesn't exist, it will be created.
*
* @param key Attribute key. Cannot be null, empty or undefined. It should be made of letters, numbers or underscores
* @param key Attribute key. Cannot be null, empty, or undefined. It should be made of letters, numbers or underscores
* ([a-z0-9_]) and can't be longer than 30 characters.
* @param value The value to add. Cannot be null, undefined or empty. Must be an array of string or a string no longer
* @param value The value to add. Cannot be null, undefined, or empty. Must be an array of string or a string no longer
* than 64 characters.
*/
public addToArray(key: string, value: string | string[]): BatchProfileAttributeEditor {
Expand All @@ -277,9 +341,9 @@ export class BatchProfileAttributeEditor {
/**
* Remove a value from an array attribute.
*
* @param key Attribute key. Cannot be null, empty or undefined. It should be made of letters, numbers or underscores
* @param key Attribute key. Cannot be null, empty, or undefined. It should be made of letters, numbers or underscores
* ([a-z0-9_]) and can't be longer than 30 characters.
* @param value The value to remove. Can be a String or an Array of String. Cannot be null, empty or undefined.
* @param value The value to remove. Can be a String or an Array of String. Cannot be null, empty, or undefined.
*/
public removeFromArray(key: string, value: string | string[]): BatchProfileAttributeEditor {
return this.addAction({
Expand Down
Loading