From 481e08978a926af564c03bb4894acbb59f9d5914 Mon Sep 17 00:00:00 2001 From: gbhrdt Date: Mon, 19 Jun 2023 22:13:25 +0200 Subject: [PATCH] Release 1.5.0 --- CHANGELOG.md | 5 + android/build.gradle | 2 +- .../cleverpush/reactnative/RNCleverPush.java | 205 ++++++++++-------- cleverpush-react-native.podspec | 2 +- index.js | 30 +++ ios/RCTCleverPush/RCTCleverPushEventEmitter.m | 22 ++ package.json | 2 +- 7 files changed, 169 insertions(+), 99 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0ec883..3b5656b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.5.0 +* Updated to latest iOS + Android SDKs +* Implemented new topic-related methods +* Fixed callback arguments for some Android methods + ## 1.4.11 * Updated to latest iOS + Android SDKs diff --git a/android/build.gradle b/android/build.gradle index 1949f62..5abc00d 100755 --- a/android/build.gradle +++ b/android/build.gradle @@ -40,7 +40,7 @@ dependencies { implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs') implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}" - implementation('com.cleverpush:cleverpush:1.29.4') { + implementation('com.cleverpush:cleverpush:1.30.15') { exclude group: 'com.android.support' } } diff --git a/android/src/main/java/com/cleverpush/reactnative/RNCleverPush.java b/android/src/main/java/com/cleverpush/reactnative/RNCleverPush.java index cc31e26..090f098 100755 --- a/android/src/main/java/com/cleverpush/reactnative/RNCleverPush.java +++ b/android/src/main/java/com/cleverpush/reactnative/RNCleverPush.java @@ -7,22 +7,21 @@ import android.content.pm.ApplicationInfo; import android.os.Bundle; import android.util.Log; - import com.cleverpush.ActivityLifecycleListener; import com.cleverpush.ChannelTag; +import com.cleverpush.ChannelTopic; import com.cleverpush.CleverPush; import com.cleverpush.CustomAttribute; import com.cleverpush.Notification; import com.cleverpush.Subscription; import com.cleverpush.listener.SubscribedListener; -import com.cleverpush.listener.AppBannerOpenedListener; -import com.cleverpush.banner.models.BannerAction; import com.facebook.react.bridge.Callback; import com.facebook.react.bridge.LifecycleEventListener; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; +import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.ReadableMapKeySetIterator; import com.facebook.react.bridge.WritableArray; @@ -30,13 +29,11 @@ import com.facebook.react.bridge.WritableNativeArray; import com.facebook.react.bridge.WritableNativeMap; import com.facebook.react.modules.core.DeviceEventManagerModule; - -import org.json.JSONException; -import org.json.JSONObject; - import java.util.HashMap; import java.util.Map; import java.util.Set; +import org.json.JSONException; +import org.json.JSONObject; public class RNCleverPush extends ReactContextBaseJavaModule implements LifecycleEventListener { public static final String NOTIFICATION_OPENED_INTENT_FILTER = "CPNotificationOpened"; @@ -47,15 +44,6 @@ public class RNCleverPush extends ReactContextBaseJavaModule implements Lifecycl private boolean cleverPushInitDone; private boolean registeredEvents = false; - private Callback pendingGetAvailableTagsCallback; - private Callback pendingGetAvailableAttributesCallback; - private Callback pendingGetSubscriptionTagsCallback; - private Callback pendingGetSubscriptionAttributesCallback; - private Callback pendingHasSubscriptionTagCallback; - private Callback pendingGetSubscriptionAttributeCallback; - private Callback pendingIsSubscribedCallback; - private Callback pendingGetNotificationsCallback; - public RNCleverPush(ReactApplicationContext reactContext) { super(reactContext); mReactApplicationContext = reactContext; @@ -127,118 +115,123 @@ public void subscribed(String subscriptionId) { } }); - this.cleverPush.setAppBannerOpenedListener(new AppBannerOpenedListener() { - @Override - public void opened(BannerAction action) { - WritableMap result = new WritableNativeMap(); - result.putString("type", action.getType()); - result.putString("name", action.getName()); - result.putString("url", action.getUrl()); - result.putString("urlType", action.getUrlType()); + this.cleverPush.setAppBannerOpenedListener(action -> { + WritableMap result = new WritableNativeMap(); + result.putString("type", action.getType()); + result.putString("name", action.getName()); + result.putString("url", action.getUrl()); + result.putString("urlType", action.getUrlType()); - sendEvent("CleverPush-appBannerOpened", result); - } - }); + sendEvent("CleverPush-appBannerOpened", result); + }); } @ReactMethod public void getSubscriptionTags(final Callback callback) { - if (pendingGetSubscriptionTagsCallback == null) - pendingGetSubscriptionTagsCallback = callback; - Set tags = this.cleverPush.getSubscriptionTags(); WritableArray writableArray = new WritableNativeArray(); for (String tag : tags) { writableArray.pushString(tag); } - if (pendingGetSubscriptionTagsCallback != null) - pendingGetSubscriptionTagsCallback.invoke(writableArray); - - pendingGetSubscriptionTagsCallback = null; + if (callback != null) { + callback.invoke(null, writableArray); + } } @ReactMethod public void hasSubscriptionTag(String tagId, final Callback callback) { - if (pendingHasSubscriptionTagCallback == null) - pendingHasSubscriptionTagCallback = callback; - boolean hasTag = this.cleverPush.hasSubscriptionTag(tagId); - if (pendingHasSubscriptionTagCallback != null) - pendingHasSubscriptionTagCallback.invoke(hasTag); + if (callback != null) { + callback.invoke(null, hasTag); + } + } - pendingHasSubscriptionTagCallback = null; + @ReactMethod + public void getSubscriptionTopics(final Callback callback) { + Set topics = this.cleverPush.getSubscriptionTopics(); + WritableArray writableArray = new WritableNativeArray(); + for (String topic : topics) { + writableArray.pushString(topic); + } + + if (callback != null) { + callback.invoke(null, writableArray); + } } @ReactMethod public void getSubscriptionAttributes(final Callback callback) { - if (pendingGetSubscriptionAttributesCallback == null) - pendingGetSubscriptionAttributesCallback = callback; - Map attributes = this.cleverPush.getSubscriptionAttributes(); WritableMap writableMap = new WritableNativeMap(); for (Map.Entry attribute : attributes.entrySet()) { writableMap.putString(attribute.getKey(), attribute.getValue().toString()); } - if (pendingGetSubscriptionAttributesCallback != null) - pendingGetSubscriptionAttributesCallback.invoke(writableMap); - - pendingGetSubscriptionAttributesCallback = null; + if (callback != null) { + callback.invoke(null, writableMap); + } } @ReactMethod public void getSubscriptionAttribute(String attributeId, final Callback callback) { - if (pendingGetSubscriptionAttributeCallback == null) - pendingGetSubscriptionAttributeCallback = callback; - Object value = this.cleverPush.getSubscriptionAttribute(attributeId); - if (pendingGetSubscriptionAttributeCallback != null) - pendingGetSubscriptionAttributeCallback.invoke(value); - - pendingGetSubscriptionAttributeCallback = null; + if (callback != null) { + callback.invoke(null, value); + } } @ReactMethod public void getAvailableTags(final Callback callback) { - if (pendingGetAvailableTagsCallback == null) - pendingGetAvailableTagsCallback = callback; + this.cleverPush.getAvailableTags(tags -> { + WritableArray writableArray = new WritableNativeArray(); + for (ChannelTag tag : tags) { + WritableMap writeableMapTag = new WritableNativeMap(); + writeableMapTag.putString("id", tag.getId()); + writeableMapTag.putString("name", tag.getName()); + writableArray.pushMap(writeableMapTag); + } - Set tags = this.cleverPush.getAvailableTags(); - WritableArray writableArray = new WritableNativeArray(); - for (ChannelTag tag : tags) { - WritableMap writeableMapTag = new WritableNativeMap(); - writeableMapTag.putString("id", tag.getId()); - writeableMapTag.putString("name", tag.getName()); - writableArray.pushMap(writeableMapTag); - } + if (callback != null) { + callback.invoke(null, writableArray); + } + }); + } - if (pendingGetAvailableTagsCallback != null) - pendingGetAvailableTagsCallback.invoke(writableArray); + @ReactMethod + public void getAvailableTopics(final Callback callback) { + this.cleverPush.getAvailableTopics(topics -> { + WritableArray writableArray = new WritableNativeArray(); + for (ChannelTopic topic : topics) { + WritableMap writeableMapTopic = new WritableNativeMap(); + writeableMapTopic.putString("id", topic.getId()); + writeableMapTopic.putString("name", topic.getName()); + writableArray.pushMap(writeableMapTopic); + } - pendingGetAvailableTagsCallback = null; + if (callback != null) { + callback.invoke(null, writableArray); + } + }); } @ReactMethod public void getAvailableAttributes(final Callback callback) { - if (pendingGetAvailableAttributesCallback == null) - pendingGetAvailableAttributesCallback = callback; - - Set attributes = this.cleverPush.getAvailableAttributes(); - WritableArray writableArray = new WritableNativeArray(); - for (CustomAttribute attribute : attributes) { - WritableMap writeableMapTag = new WritableNativeMap(); - writeableMapTag.putString("id", attribute.getId()); - writeableMapTag.putString("name", attribute.getName()); - writableArray.pushMap(writeableMapTag); - } - - if (pendingGetAvailableAttributesCallback != null) - pendingGetAvailableAttributesCallback.invoke(writableArray); + this.cleverPush.getAvailableAttributes(attributes -> { + WritableArray writableArray = new WritableNativeArray(); + for (CustomAttribute attribute : attributes) { + WritableMap writeableMapTag = new WritableNativeMap(); + writeableMapTag.putString("id", attribute.getId()); + writeableMapTag.putString("name", attribute.getName()); + writableArray.pushMap(writeableMapTag); + } - pendingGetAvailableAttributesCallback = null; + if (callback != null) { + callback.invoke(null, writableArray); + } + }); } @ReactMethod @@ -257,6 +250,34 @@ public void removeSubscriptionTag(String tagId) { this.cleverPush.removeSubscriptionTag(tagId); } + @ReactMethod + public void setSubscriptionTopics(ReadableArray topicIdsReadableArray) { + if (this.cleverPush == null) { + return; + } + String[] topicIds = new String[topicIdsReadableArray.size()]; + for (int i = 0; i < topicIdsReadableArray.size(); i++) { + topicIds[i] = topicIdsReadableArray.getString(i); + } + this.cleverPush.setSubscriptionTopics(topicIds); + } + + @ReactMethod + public void addSubscriptionTopic(String topicId) { + if (this.cleverPush == null) { + return; + } + this.cleverPush.addSubscriptionTopic(topicId); + } + + @ReactMethod + public void removeSubscriptionTopic(String topicId) { + if (this.cleverPush == null) { + return; + } + this.cleverPush.removeSubscriptionTopic(topicId); + } + @ReactMethod public void setSubscriptionAttribute(String attributeId, String value) { if (this.cleverPush == null) { @@ -267,15 +288,11 @@ public void setSubscriptionAttribute(String attributeId, String value) { @ReactMethod public void isSubscribed(final Callback callback) { - if (pendingIsSubscribedCallback == null) - pendingIsSubscribedCallback = callback; - boolean isSubscribed = this.cleverPush.isSubscribed(); - if (pendingIsSubscribedCallback != null) - pendingIsSubscribedCallback.invoke(null, isSubscribed); - - pendingIsSubscribedCallback = null; + if (callback != null) { + callback.invoke(null, isSubscribed); + } } @ReactMethod @@ -333,9 +350,6 @@ public void showAppBanners(final Callback callback) { @ReactMethod public void getNotifications(final Callback callback) { - if (pendingGetNotificationsCallback == null) - pendingGetNotificationsCallback = callback; - Set notifications = this.cleverPush.getNotifications(); WritableArray writableArray = new WritableNativeArray(); for (Notification notification : notifications) { @@ -350,10 +364,9 @@ public void getNotifications(final Callback callback) { writableArray.pushMap(writeableMap); } - if (pendingGetNotificationsCallback != null) - pendingGetNotificationsCallback.invoke(null, writableArray); - - pendingGetNotificationsCallback = null; + if (callback != null) { + callback.invoke(null, writableArray); + } } @ReactMethod diff --git a/cleverpush-react-native.podspec b/cleverpush-react-native.podspec index 444f341..d0ee901 100755 --- a/cleverpush-react-native.podspec +++ b/cleverpush-react-native.podspec @@ -14,6 +14,6 @@ Pod::Spec.new do |s| s.source_files = 'ios/RCTCleverPush/*.{h,m}' s.dependency 'React' - s.dependency 'CleverPush', '~> 1.26.4' + s.dependency 'CleverPush', '~> 1.27.13' end diff --git a/index.js b/index.js index 710fbe5..ceba615 100755 --- a/index.js +++ b/index.js @@ -94,6 +94,12 @@ export default class CleverPush { RNCleverPush.getAvailableTags(callback); } + static getAvailableTopics(callback) { + if (!checkIfInitialized()) return; + + RNCleverPush.getAvailableTopics(callback); + } + static getAvailableAttributes(callback) { if (!checkIfInitialized()) return; @@ -124,6 +130,30 @@ export default class CleverPush { RNCleverPush.hasSubscriptionTag(tagId, callback); } + static getSubscriptionTopics(callback) { + if (!checkIfInitialized()) return; + + RNCleverPush.getSubscriptionTopics(callback); + } + + static setSubscriptionTopics(topicIds) { + if (!checkIfInitialized()) return; + + RNCleverPush.setSubscriptionTopics(topicIds); + } + + static addSubscriptionTopic(topicId) { + if (!checkIfInitialized()) return; + + RNCleverPush.addSubscriptionTopic(topicId); + } + + static removeSubscriptionTopic(topicId) { + if (!checkIfInitialized()) return; + + RNCleverPush.removeSubscriptionTopic(topicId); + } + static getSubscriptionAttributes(callback) { if (!checkIfInitialized()) return; diff --git a/ios/RCTCleverPush/RCTCleverPushEventEmitter.m b/ios/RCTCleverPush/RCTCleverPushEventEmitter.m index 775366d..0c097b5 100755 --- a/ios/RCTCleverPush/RCTCleverPushEventEmitter.m +++ b/ios/RCTCleverPush/RCTCleverPushEventEmitter.m @@ -86,6 +86,11 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body { callback(@[[NSNull null], channelTags]); } +RCT_EXPORT_METHOD(getAvailableTopics:(RCTResponseSenderBlock)callback) { + NSArray* channelTopics = [CleverPush getAvailableTopics]; + callback(@[[NSNull null], channelTopics]); +} + RCT_EXPORT_METHOD(getAvailableAttributes:(RCTResponseSenderBlock)callback) { NSDictionary* customAttributes = [CleverPush getAvailableAttributes]; callback(@[[NSNull null], customAttributes]); @@ -96,6 +101,11 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body { callback(@[[NSNull null], subscriptionTags]); } +RCT_EXPORT_METHOD(getSubscriptionTopics:(RCTResponseSenderBlock)callback) { + NSArray* subscriptionTopics = [CleverPush getSubscriptionTopics]; + callback(@[[NSNull null], subscriptionTopics]); +} + RCT_EXPORT_METHOD(getSubscriptionAttributes:(RCTResponseSenderBlock)callback) { NSDictionary* subscriptionAttributes = [CleverPush getSubscriptionAttributes]; callback(@[[NSNull null], subscriptionAttributes]); @@ -119,6 +129,18 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body { [CleverPush removeSubscriptionTag:tagId]; } +RCT_EXPORT_METHOD(addSubscriptionTopic:(NSString *)topicId) { + [CleverPush addSubscriptionTopic:topicId]; +} + +RCT_EXPORT_METHOD(removeSubscriptionTopic:(NSString *)topicId) { + [CleverPush removeSubscriptionTopic:topicId]; +} + +RCT_EXPORT_METHOD(setSubscriptionTopics:(NSArray *)topicIds) { + [CleverPush setSubscriptionTopics:topicIds]; +} + RCT_EXPORT_METHOD(setSubscriptionAttribute:(NSString *)attributeId value:(NSString*)value) { [CleverPush setSubscriptionAttribute:attributeId value:value]; } diff --git a/package.json b/package.json index 5a93e5d..470cf27 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cleverpush-react-native", - "version": "1.4.11", + "version": "1.5.0", "description": "CleverPush React Native SDK", "main": "index", "scripts": {