From f5318e2b5654cd26501f4754ace6e57036bc7e0e Mon Sep 17 00:00:00 2001 From: Hussein Habibi Juybari Date: Sat, 10 Nov 2018 18:59:43 +0330 Subject: [PATCH 01/15] Fix call rejector in getInstallationId --- ios/AdpPushClient.m | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ios/AdpPushClient.m b/ios/AdpPushClient.m index 4b0c36b..3aee2af 100644 --- a/ios/AdpPushClient.m +++ b/ios/AdpPushClient.m @@ -138,7 +138,16 @@ @implementation AdpPushClient RCT_EXPORT_METHOD(getInstallationId:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { NSString *installationId = [PushClientManager.defaultManager getInstallationId]; - resolve(installationId); + if (!installationId) { + NSError *error = [NSError.alloc initWithDomain:@"Not registered" + code:500 + userInfo:@{ + @"message":@"The installationId is null, You didn't register yet!" + }]; + reject(@"500",@"The installationId is null, You didn't register yet!",error); + } else { + resolve(installationId); +} } RCT_EXPORT_METHOD(getUserId:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { From 0b9c1599f6847d6f9d3136a7600ee978407d9c4a Mon Sep 17 00:00:00 2001 From: Hussein Habibi Juybari Date: Sat, 10 Nov 2018 19:00:04 +0330 Subject: [PATCH 02/15] Fix call rejector in getUserId --- ios/AdpPushClient.m | 47 +++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/ios/AdpPushClient.m b/ios/AdpPushClient.m index 3aee2af..51f92d0 100644 --- a/ios/AdpPushClient.m +++ b/ios/AdpPushClient.m @@ -147,12 +147,21 @@ @implementation AdpPushClient reject(@"500",@"The installationId is null, You didn't register yet!",error); } else { resolve(installationId); -} + } } RCT_EXPORT_METHOD(getUserId:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { NSString *userId = [PushClientManager.defaultManager userId]; - resolve(userId); + if (!userId) { + NSError *error = [NSError.alloc initWithDomain:@"Not registered" + code:500 + userInfo:@{ + @"message":@"The userId is null, You didn't register yet!" + }]; + reject(@"500",@"The userId is null, You didn't register yet!",error); + } else { + resolve(userId); + } } #pragma mark - dev @@ -240,7 +249,7 @@ @implementation AdpPushClient RCT_EXPORT_METHOD(publishEvent:(NSString *) eventName data:(NSDictionary *) data resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { - [PushClientManager.defaultManager publishEvent:eventName data:data]; + [PushClientManager.defaultManager publishEvent:eventName data:data]; } #pragma mark - subscribe @@ -249,7 +258,7 @@ @implementation AdpPushClient } RCT_EXPORT_METHOD(subscribeEvent:(NSString *) eventName) { - [PushClientManager.defaultManager subscribeEvent:eventName]; + [PushClientManager.defaultManager subscribeEvent:eventName]; } RCT_EXPORT_METHOD(subscribeEvent:(NSString *) eventName installationId:(NSString *) installationId) { @@ -266,7 +275,7 @@ @implementation AdpPushClient } RCT_EXPORT_METHOD(unSubscribeEvent:(NSString *) eventName) { - [PushClientManager.defaultManager unsubscribeEvent:eventName]; + [PushClientManager.defaultManager unsubscribeEvent:eventName]; } RCT_EXPORT_METHOD(unSubscribeEvent:(NSString *) eventName installationId:(NSString *) installationId) { @@ -294,24 +303,24 @@ @implementation AdpPushClient -(void) pushClientManagerDidReceivedMessage:(PushClientMessage *)message{ if (self.bridge) { - NSMutableDictionary *messageDict = [NSMutableDictionary.alloc initWithDictionary:[message toDict]]; - [messageDict setObject:message.channel forKey:@"channel"]; - - [self sendEventWithName:@"onMessage" body:messageDict]; - [self sendEventWithName:@"ChabokMessageReceived" body:messageDict]; + NSMutableDictionary *messageDict = [NSMutableDictionary.alloc initWithDictionary:[message toDict]]; + [messageDict setObject:message.channel forKey:@"channel"]; + + [self sendEventWithName:@"onMessage" body:messageDict]; + [self sendEventWithName:@"ChabokMessageReceived" body:messageDict]; } } -(void) pushClientManagerDidReceivedEventMessage:(EventMessage *)eventMessage{ - if (self.bridge) { - NSDictionary *event = @{ - @"id":eventMessage.id, - @"installationId":eventMessage.deviceId, - @"eventName":eventMessage.eventName, - @"data":eventMessage.data - }; - [self sendEventWithName:@"onEvent" body:event]; - } + if (self.bridge) { + NSDictionary *event = @{ + @"id":eventMessage.id, + @"installationId":eventMessage.deviceId, + @"eventName":eventMessage.eventName, + @"data":eventMessage.data + }; + [self sendEventWithName:@"onEvent" body:event]; + } } -(void) pushClientManagerDidChangedServerConnectionState { From 238ff0464b6b706cdc62a40632a2b69d0ef84d10 Mon Sep 17 00:00:00 2001 From: Hussein Habibi Juybari Date: Sun, 11 Nov 2018 18:08:30 +0330 Subject: [PATCH 03/15] Fix parse eventMessage data --- .../push/rn/AdpPushClientModule.java | 82 +++++++++++++------ 1 file changed, 59 insertions(+), 23 deletions(-) diff --git a/android/src/main/java/com/adpdigital/push/rn/AdpPushClientModule.java b/android/src/main/java/com/adpdigital/push/rn/AdpPushClientModule.java index 72a380c..83beeea 100644 --- a/android/src/main/java/com/adpdigital/push/rn/AdpPushClientModule.java +++ b/android/src/main/java/com/adpdigital/push/rn/AdpPushClientModule.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.os.Debug; import android.support.v4.content.LocalBroadcastManager; import android.text.TextUtils; import android.util.Log; @@ -23,6 +24,7 @@ import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.ReadableMapKeySetIterator; import com.facebook.react.bridge.ReadableType; +import com.facebook.react.bridge.WritableArray; import com.facebook.react.bridge.WritableMap; import com.facebook.react.modules.core.DeviceEventManagerModule; import com.google.android.gms.common.ConnectionResult; @@ -32,6 +34,7 @@ import org.json.JSONException; import org.json.JSONObject; +import java.io.Console; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -159,11 +162,19 @@ public void run() { response.putDouble("createdAt", msg.getCreatedAt()); response.putDouble("expireAt", msg.getExpireAt()); if (msg.getData() != null) { - response.putMap("data", toWritableMap(msg.getData())); + try { + response.putMap("data", toWritableMap(msg.getData())); + } catch (JSONException e) { + e.printStackTrace(); + } } if (msg.getNotification() != null) { - response.putMap("notification", toWritableMap(msg.getNotification())); + try { + response.putMap("notification", toWritableMap(msg.getNotification())); + } catch (JSONException e) { + e.printStackTrace(); + } } //sendEvent("onMessage", response); @@ -181,35 +192,60 @@ public void run() { response.putString("id", eventMessage.getId()); response.putString("eventName", eventMessage.getName()); response.putString("installationId", eventMessage.getInstallationId()); - response.putMap("data", toWritableMap(eventMessage.getData())); + try { + response.putMap("data", toWritableMap(eventMessage.getData())); + } catch (JSONException e) { + e.printStackTrace(); + } sendEvent("onEvent", response); } }); } - WritableMap toWritableMap(JSONObject json) { - WritableMap response = Arguments.createMap(); - Iterator iter = json.keys(); - while (iter.hasNext()) { - String key = iter.next().toString(); - try { - if (json.get(key) instanceof Integer) { - response.putInt(key, (Integer) json.get(key)); - } else if (json.get(key) instanceof String) { - response.putString(key, (String) json.get(key)); - } else if (json.get(key) instanceof JSONObject) { - response.putMap(key, toWritableMap((JSONObject) json.get(key))); - } else if (json.get(key) instanceof Double) { - response.putDouble(key, (Double) json.get(key)); - } else if (json.get(key) instanceof Boolean) { - response.putBoolean(key, (Boolean) json.get(key)); - } - } catch (JSONException e) { - // Something went wrong! + public static WritableMap toWritableMap(JSONObject jsonObject) throws JSONException { + WritableMap writableMap = Arguments.createMap(); + Iterator iterator = jsonObject.keys(); + while(iterator.hasNext()) { + String key = (String) iterator.next(); + Object value = jsonObject.get(key); + if (value instanceof Float || value instanceof Double) { + writableMap.putDouble(key, jsonObject.getDouble(key)); + } else if (value instanceof Number) { + writableMap.putInt(key, jsonObject.getInt(key)); + } else if (value instanceof String) { + writableMap.putString(key, jsonObject.getString(key)); + } else if (value instanceof JSONObject) { + writableMap.putMap(key,toWritableMap(jsonObject.getJSONObject(key))); + } else if (value instanceof JSONArray){ + writableMap.putArray(key, toWritableMap(jsonObject.getJSONArray(key))); + } else if (value == JSONObject.NULL){ + writableMap.putNull(key); + } + } + + return writableMap; + } + + public static WritableArray toWritableMap(JSONArray jsonArray) throws JSONException { + WritableArray writableArray = Arguments.createArray(); + for(int i=0; i < jsonArray.length(); i++) { + Object value = jsonArray.get(i); + if (value instanceof Float || value instanceof Double) { + writableArray.pushDouble(jsonArray.getDouble(i)); + } else if (value instanceof Number) { + writableArray.pushInt(jsonArray.getInt(i)); + } else if (value instanceof String) { + writableArray.pushString(jsonArray.getString(i)); + } else if (value instanceof JSONObject) { + writableArray.pushMap(toWritableMap(jsonArray.getJSONObject(i))); + } else if (value instanceof JSONArray){ + writableArray.pushArray(toWritableMap(jsonArray.getJSONArray(i))); + } else if (value == JSONObject.NULL){ + writableArray.pushNull(); } } - return response; + return writableArray; } private void attachChabokClient() { From b23a678fa62fbc00680dc681d64dc73bc3b2944d Mon Sep 17 00:00:00 2001 From: Hussein Habibi Juybari Date: Sun, 11 Nov 2018 18:08:45 +0330 Subject: [PATCH 04/15] Add google to build script to gradle --- android/build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/android/build.gradle b/android/build.gradle index 86a0473..5bf941a 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,6 +1,7 @@ buildscript { repositories { jcenter() + google() } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' @@ -17,6 +18,7 @@ allprojects { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url "$rootDir/../node_modules/react-native/android" } + google() } } apply plugin: 'com.android.library' From 2f2b63dda1bd5473a7d42b81675a3206e751fe53 Mon Sep 17 00:00:00 2001 From: Hussein Habibi Juybari Date: Sun, 11 Nov 2018 18:12:54 +0330 Subject: [PATCH 05/15] Update Chabok version --- android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/build.gradle b/android/build.gradle index 5bf941a..70c8b40 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -55,5 +55,5 @@ dependencies { compile 'com.google.android.gms:play-services-gcm:10.2.6' compile 'me.leolin:ShortcutBadger:1.1.22@aar' - compile 'com.adpdigital.push:chabok-lib:2.13.3' + compile 'com.adpdigital.push:chabok-lib:2.13.4' } From ae2b481658589a8d4fec29bb449fc9f84ddf7c7d Mon Sep 17 00:00:00 2001 From: Hussein Habibi Juybari Date: Sun, 11 Nov 2018 18:16:01 +0330 Subject: [PATCH 06/15] Update history file --- history.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/history.md b/history.md index bfd0a15..d760d8a 100644 --- a/history.md +++ b/history.md @@ -1,7 +1,11 @@ ## History +### v1.0.4 (10/11/2018) +- Update Chabok android SDK version to [v2.13.4](https://github.com/chabokpush/chabok-client-android/releases/tag/v2.13.4) +- Fix promise reject for calling `getUserId` and `getInstallationId` + ### v1.0.3 (10/11/2018) -- Update chabok android SDK version to v2.13.3 +- Update chabok android SDK version to [v2.13.3](https://github.com/chabokpush/chabok-client-android/releases/tag/v2.13.3) ### v1.0.2 (6/11/2018) - Update android bridge compileSdkVersion to 26 From a1f5df0cb2aa769960f790aef29c1157c1b4ca42 Mon Sep 17 00:00:00 2001 From: Hussein Habibi Juybari Date: Sun, 11 Nov 2018 18:17:39 +0330 Subject: [PATCH 07/15] v1.0.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c076f47..d7fc51d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-chabok", - "version": "1.0.3", + "version": "1.0.4", "description": "React native wrapper for Chabok SDK", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" From 0d9fdf8dd42c67e63c6fe4e65d59bc2b31699e3f Mon Sep 17 00:00:00 2001 From: Hussein Habibi Juybari Date: Sun, 11 Nov 2018 18:24:41 +0330 Subject: [PATCH 08/15] remove google to gradle --- android/build.gradle | 2 -- 1 file changed, 2 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 70c8b40..0c8cb97 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,7 +1,6 @@ buildscript { repositories { jcenter() - google() } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' @@ -18,7 +17,6 @@ allprojects { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url "$rootDir/../node_modules/react-native/android" } - google() } } apply plugin: 'com.android.library' From f6e469d1cd0d13e5240067374f79b47ee8fdd139 Mon Sep 17 00:00:00 2001 From: Hussein Habibi Juybari Date: Mon, 12 Nov 2018 13:49:03 +0330 Subject: [PATCH 09/15] Check data exist in eventMessage --- android/build.gradle | 2 ++ .../push/rn/AdpPushClientModule.java | 10 ++++++---- ios/AdpPushClient.m | 18 +++++++++++------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 0c8cb97..70c8b40 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,6 +1,7 @@ buildscript { repositories { jcenter() + google() } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' @@ -17,6 +18,7 @@ allprojects { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url "$rootDir/../node_modules/react-native/android" } + google() } } apply plugin: 'com.android.library' diff --git a/android/src/main/java/com/adpdigital/push/rn/AdpPushClientModule.java b/android/src/main/java/com/adpdigital/push/rn/AdpPushClientModule.java index 83beeea..9498eea 100644 --- a/android/src/main/java/com/adpdigital/push/rn/AdpPushClientModule.java +++ b/android/src/main/java/com/adpdigital/push/rn/AdpPushClientModule.java @@ -192,10 +192,12 @@ public void run() { response.putString("id", eventMessage.getId()); response.putString("eventName", eventMessage.getName()); response.putString("installationId", eventMessage.getInstallationId()); - try { - response.putMap("data", toWritableMap(eventMessage.getData())); - } catch (JSONException e) { - e.printStackTrace(); + if (eventMessage.getData() != null) { + try { + response.putMap("data", toWritableMap(eventMessage.getData())); + } catch (JSONException e) { + e.printStackTrace(); + } } sendEvent("onEvent", response); diff --git a/ios/AdpPushClient.m b/ios/AdpPushClient.m index 51f92d0..a550aff 100644 --- a/ios/AdpPushClient.m +++ b/ios/AdpPushClient.m @@ -313,13 +313,17 @@ -(void) pushClientManagerDidReceivedMessage:(PushClientMessage *)message{ -(void) pushClientManagerDidReceivedEventMessage:(EventMessage *)eventMessage{ if (self.bridge) { - NSDictionary *event = @{ - @"id":eventMessage.id, - @"installationId":eventMessage.deviceId, - @"eventName":eventMessage.eventName, - @"data":eventMessage.data - }; - [self sendEventWithName:@"onEvent" body:event]; + NSDictionary *eventMessageDic = @{ + @"id":eventMessage.id, + @"installationId":eventMessage.deviceId, + @"eventName":eventMessage.eventName + }; + NSMutableDictionary *eventPayload = [NSMutableDictionary.alloc initWithDictionary:eventMessageDic]; + if (eventMessage.data) { + [eventPayload setObject:eventMessage.data forKey:@"data"]; + } + + [self sendEventWithName:@"onEvent" body:[eventPayload copy]]; } } From a2d37aeede56483ef68200c4ce73b9839a300903 Mon Sep 17 00:00:00 2001 From: Hussein Habibi Juybari Date: Mon, 12 Nov 2018 13:57:58 +0330 Subject: [PATCH 10/15] Update history --- history.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/history.md b/history.md index d760d8a..b0fed6c 100644 --- a/history.md +++ b/history.md @@ -1,7 +1,8 @@ ## History ### v1.0.4 (10/11/2018) -- Update Chabok android SDK version to [v2.13.4](https://github.com/chabokpush/chabok-client-android/releases/tag/v2.13.4) +- Update Chabok android SDK version to [v2.14.0](https://github.com/chabokpush/chabok-client-android/releases/tag/v2.14.0) +- Update Chabok iOS SDK version to [v1.18.0](https://github.com/chabokpush/chabok-client-android/releases/tag/v1.18.0) - Fix promise reject for calling `getUserId` and `getInstallationId` ### v1.0.3 (10/11/2018) From f4256edafd34e03a1a593f49d7b8b3d2eaf7e094 Mon Sep 17 00:00:00 2001 From: Hussein Habibi Juybari Date: Mon, 12 Nov 2018 14:12:26 +0330 Subject: [PATCH 11/15] Update android SDK version to 2.14.0 --- android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/build.gradle b/android/build.gradle index 70c8b40..4b63763 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -55,5 +55,5 @@ dependencies { compile 'com.google.android.gms:play-services-gcm:10.2.6' compile 'me.leolin:ShortcutBadger:1.1.22@aar' - compile 'com.adpdigital.push:chabok-lib:2.13.4' + compile 'com.adpdigital.push:chabok-lib:2.14.0' } From 5b4bf5ccf4cb53d8b4bfc1221d4fca27358f3899 Mon Sep 17 00:00:00 2001 From: Hussein Habibi Juybari Date: Mon, 12 Nov 2018 14:44:03 +0330 Subject: [PATCH 12/15] Remove google --- android/build.gradle | 2 -- 1 file changed, 2 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 4b63763..fe44a14 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,7 +1,6 @@ buildscript { repositories { jcenter() - google() } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' @@ -18,7 +17,6 @@ allprojects { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url "$rootDir/../node_modules/react-native/android" } - google() } } apply plugin: 'com.android.library' From ffeaff7983a20bda33fb3371ac272f80108b9b9e Mon Sep 17 00:00:00 2001 From: Hussein Habibi Juybari Date: Mon, 12 Nov 2018 16:51:06 +0330 Subject: [PATCH 13/15] v1.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d7fc51d..c3345ee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-chabok", - "version": "1.0.4", + "version": "1.1.0", "description": "React native wrapper for Chabok SDK", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" From deedbe4f50f43b4b2ade82764e06c8c3292ed89a Mon Sep 17 00:00:00 2001 From: Hussein Habibi Juybari Date: Mon, 12 Nov 2018 16:53:13 +0330 Subject: [PATCH 14/15] Update history for v1.1.0 --- history.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/history.md b/history.md index b0fed6c..00fe166 100644 --- a/history.md +++ b/history.md @@ -1,6 +1,6 @@ ## History -### v1.0.4 (10/11/2018) +### v1.1.0 (12/11/2018) - Update Chabok android SDK version to [v2.14.0](https://github.com/chabokpush/chabok-client-android/releases/tag/v2.14.0) - Update Chabok iOS SDK version to [v1.18.0](https://github.com/chabokpush/chabok-client-android/releases/tag/v1.18.0) - Fix promise reject for calling `getUserId` and `getInstallationId` From f483ba6465fe8235adb943550db61a703ab274a0 Mon Sep 17 00:00:00 2001 From: Hussein Habibi Juybari Date: Mon, 12 Nov 2018 16:54:32 +0330 Subject: [PATCH 15/15] Update history --- history.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/history.md b/history.md index 00fe166..e93d03c 100644 --- a/history.md +++ b/history.md @@ -2,7 +2,7 @@ ### v1.1.0 (12/11/2018) - Update Chabok android SDK version to [v2.14.0](https://github.com/chabokpush/chabok-client-android/releases/tag/v2.14.0) -- Update Chabok iOS SDK version to [v1.18.0](https://github.com/chabokpush/chabok-client-android/releases/tag/v1.18.0) +- Update Chabok iOS SDK version to [v1.18.0](https://github.com/chabokpush/chabok-client-ios/releases/tag/v1.18.0) - Fix promise reject for calling `getUserId` and `getInstallationId` ### v1.0.3 (10/11/2018)