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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.7.0
## Update
* Updated channeltalk plugin v10

# 0.6.8

## Update
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ repositories {

dependencies {
implementation 'com.facebook.react:react-native:+'
api 'io.channel:plugin-android:9.0.9'
api 'io.channel:plugin-android:10.0.0'
}
9 changes: 4 additions & 5 deletions android/src/main/java/com/zoyi/channel/rn/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public class Const {
public static final String KEY_MEMBER_HASH = "memberHash";
public static final String KEY_PROFILE = "profile";
public static final String KEY_LANGUAGE = "language";
public static final String KEY_UNSUBSCRIBED = "unsubscribed";
public static final String KEY_UNSUBSCRIBED_EMAIL = "unsubscribedEmail";
public static final String KEY_UNSUBSCRIBED_TEXTING = "unsubscribedTexting";
public static final String KEY_TRACK_DEFAULT_EVENT = "trackDefaultEvent";
public static final String KEY_HIDE_POPUP = "hidePopup";
public static final String KEY_CHANNEL_BUTTON_OPTION = "channelButtonOption";
Expand Down Expand Up @@ -57,11 +58,9 @@ public class Const {
public static final String KEY_EVENT_COUNT = "count";
public static final String KEY_EVENT_URL = "url";
public static final String KEY_EVENT_POPUP = "popup";
public static final String KEY_PROFILE_KEY = "key";
public static final String KEY_PROFILE_VALUE = "value";

public static final String KEY_ON_BADGE_CHANGED = "ON_BADGE_CHANGED";
public static final String KEY_ON_PROFILE_CHANGED = "ON_PROFILE_CHANGED";
public static final String KEY_ON_FOLLOW_UP_CHANGED = "ON_FOLLOW_UP_CHANGED";
public static final String KEY_ON_POPUP_DATA_RECEIVED = "ON_POPUP_DATA_RECEIVED";
public static final String KEY_ON_SHOW_MESSENGER = "ON_SHOW_MESSENGER";
public static final String KEY_ON_HIDE_MESSENGER = "ON_HIDE_MESSENGER";
Expand All @@ -70,7 +69,7 @@ public class Const {
public static final String KEY_ON_PRE_URL_CLICKED = "ON_PRE_URL_CLICKED";

public static final String EVENT_ON_BADGE_CHANGED = "ChannelIO:Event:OnBadgeChanged";
public static final String EVENT_ON_PROFILE_CHANGED = "ChannelIO:Event:OnProfileChanged";
public static final String EVENT_ON_FOLLOW_UP_CHANGED = "ChannelIO:Event:OnFollowUpChanged";
public static final String EVENT_ON_POPUP_DATA_RECEIVED = "ChannelIO:Event:OnPopupDataReceive";
public static final String EVENT_ON_SHOW_MESSENGER = "ChannelIO:Event:OnShowMessenger";
public static final String EVENT_ON_HIDE_MESSENGER = "ChannelIO:Event:OnHideMessenger";
Expand Down
46 changes: 32 additions & 14 deletions android/src/main/java/com/zoyi/channel/rn/ParseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ public static WritableMap toWritableMap(Map<String, Object> map) {
return writableMap;
}

public static WritableMap toWritableStringMap(Map<String, String> map) {
WritableMap writableMap = Arguments.createMap();

if (map == null) {
return writableMap;
}

for (Map.Entry<String, String> pair : map.entrySet()) {
writableMap.putString(pair.getKey(), pair.getValue());
}

return writableMap;
}

public static Map<String, Object> toHashMap(ReadableMap readableMap) {
HashMap<String, Object> hashMap = new HashMap<>();

Expand Down Expand Up @@ -261,9 +275,14 @@ public static BootConfig toBootConfig(ReadableMap configMap) {
bootConfig.setHidePopup(hidePopup.getValue());
}

MapEntry<Boolean> unsubscribed = Utils.getBoolean(configMap, Const.KEY_UNSUBSCRIBED);
if (unsubscribed.hasValue()) {
bootConfig.setUnsubscribed(unsubscribed.getValue());
MapEntry<Boolean> unsubscribedEmail = Utils.getBoolean(configMap, Const.KEY_UNSUBSCRIBED_EMAIL);
if (unsubscribedEmail.hasValue()) {
bootConfig.setUnsubscribeEmail(unsubscribedEmail.getValue());
}

MapEntry<Boolean> unsubscribedTexting = Utils.getBoolean(configMap, Const.KEY_UNSUBSCRIBED_TEXTING);
if (unsubscribedTexting.hasValue()) {
bootConfig.setUnsubscribeTexting(unsubscribedTexting.getValue());
}

MapEntry<ReadableMap> channelButtonOption = Utils.getReadableMap(configMap, Const.KEY_CHANNEL_BUTTON_OPTION, Const.KEY_LAUNCHER_CONFIG);
Expand Down Expand Up @@ -320,9 +339,14 @@ public static UserData toUserData(ReadableMap userDataMap) {
userDataBuilder.setProfileOnceMap(toHashMap(profileOnce.getValue()));
}

MapEntry<Boolean> unsubscribed = Utils.getBoolean(userDataMap, Const.KEY_UNSUBSCRIBED);
if (unsubscribed.hasValue()) {
userDataBuilder.setUnsubscribed(unsubscribed.getValue());
MapEntry<Boolean> unsubscribedEmail = Utils.getBoolean(userDataMap, Const.KEY_UNSUBSCRIBED_EMAIL);
if (unsubscribedEmail.hasValue()) {
userDataBuilder.setUnsubscribeEmail(unsubscribedEmail.getValue());
}

MapEntry<Boolean> unsubscribedTexting = Utils.getBoolean(userDataMap, Const.KEY_UNSUBSCRIBED_TEXTING);
if (unsubscribedTexting.hasValue()) {
userDataBuilder.setUnsubscribeTexting(unsubscribedTexting.getValue());
}

return userDataBuilder.build();
Expand Down Expand Up @@ -391,7 +415,8 @@ public static WritableMap userToWritableMap(User user) {
userMap.putString(Const.KEY_NAME, user.getName());
userMap.putString(Const.KEY_AVATAR_URL, user.getAvatarUrl());
userMap.putInt(Const.KEY_ALERT, user.getAlert());
userMap.putBoolean(Const.KEY_UNSUBSCRIBED, user.isUnsubscribed());
userMap.putBoolean(Const.KEY_UNSUBSCRIBED_EMAIL, user.isUnsubscribeEmail());
userMap.putBoolean(Const.KEY_UNSUBSCRIBED_TEXTING, user.isUnsubscribeTexting());
userMap.putString(Const.KEY_LANGUAGE, user.getLanguage());

Map<String, Object> profile = user.getProfile();
Expand Down Expand Up @@ -421,13 +446,6 @@ public static WritableMap popupDataToWritableMap(PopupData popupData) {
return resultMap;
}

public static WritableMap createKeyValueMap(String keyName, String keyContent, String valueName, Object valueContent) {
Map<String, Object> map = new HashMap<>();
map.put(keyName, keyContent);
map.put(valueName, valueContent);
return toWritableMap(map);
}

public static WritableMap createSingleMap(String key, Object object) {
Map<String, Object> map = new HashMap<>();
map.put(key, object);
Expand Down
8 changes: 4 additions & 4 deletions android/src/main/java/com/zoyi/channel/rn/RNChannelIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Map<String, Object> getConstants() {
eventMap.put(Const.KEY_ON_SHOW_MESSENGER, Const.EVENT_ON_SHOW_MESSENGER);
eventMap.put(Const.KEY_ON_HIDE_MESSENGER, Const.EVENT_ON_HIDE_MESSENGER);
eventMap.put(Const.KEY_ON_CHAT_CREATED, Const.EVENT_ON_CHAT_CREATED);
eventMap.put(Const.KEY_ON_PROFILE_CHANGED, Const.EVENT_ON_PROFILE_CHANGED);
eventMap.put(Const.KEY_ON_FOLLOW_UP_CHANGED, Const.EVENT_ON_FOLLOW_UP_CHANGED);
eventMap.put(Const.KEY_ON_URL_CLICKED, Const.EVENT_ON_URL_CLICKED);
eventMap.put(Const.KEY_ON_PRE_URL_CLICKED, Const.EVENT_ON_PRE_URL_CLICKED);

Expand Down Expand Up @@ -226,11 +226,11 @@ public void onBadgeChanged(int count) {
}

@Override
public void onProfileChanged(String key, @Nullable Object value) {
public void onFollowUpChanged(Map<String, String> data) {
Utils.sendEvent(
reactContext,
Const.EVENT_ON_PROFILE_CHANGED,
ParseUtils.createKeyValueMap(Const.KEY_PROFILE_KEY, key, Const.KEY_PROFILE_VALUE, value)
Const.EVENT_ON_FOLLOW_UP_CHANGED,
ParseUtils.toWritableStringMap(data)
);
}

Expand Down
34 changes: 17 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,32 +340,32 @@ export const ChannelIO = {

/**
* @deprecated
* Event listener that triggers when guest profile is updated
* @param {Function} cb a callback function that takes a key, value
* 'onChangeProfile' is deprecated. Please use 'onFollowUpChanged'.
*/
onChangeProfile: (cb) => {
console.log('ChannelIO', 'ChannelIO.onChangeProfile(cb) is deprecated. Please use ChannelIO.onProfileChanged(cb)')
if (cb) {
const subscription = ChannelEventEmitter.addListener(ChannelModule.Event.ON_PROFILE_CHANGED, (data) => {
cb(data.key, data.value);
});
replaceSubscriber(ChannelModule.Event.ON_PROFILE_CHANGED, subscription);
} else {
replaceSubscriber(ChannelModule.Event.ON_PROFILE_CHANGED, null);
}
console.warn("'onChangeProfile' is deprecated. Please use 'onFollowUpChanged'.")
},

/**
* @deprecated
* 'onProfileChanged' is deprecated. Please use 'onFollowUpChanged'.
*/
onProfileChanged: (cb) => {
console.warn("'onProfileChanged' is deprecated. Please use 'onFollowUpChanged'.")
},

/**
* Event listener that triggers when guest profile is updated
* @param {Function} cb a callback function that takes a key, value
* @param {Function} cb a callback function that takes a map
*/
onProfileChanged: (cb) => {
onFollowUpChanged: (cb) => {
if (cb) {
const subscription = ChannelEventEmitter.addListener(ChannelModule.Event.ON_PROFILE_CHANGED, (data) => {
cb(data.key, data.value);
const subscription = ChannelEventEmitter.addListener(ChannelModule.Event.ON_FOLLOW_UP_CHANGED, (data) => {
cb(data);
});
replaceSubscriber(ChannelModule.Event.ON_PROFILE_CHANGED, subscription);
replaceSubscriber(ChannelModule.Event.ON_FOLLOW_UP_CHANGED, subscription);
} else {
replaceSubscriber(ChannelModule.Event.ON_PROFILE_CHANGED, null);
replaceSubscriber(ChannelModule.Event.ON_FOLLOW_UP_CHANGED, null);
}
},

Expand Down
4 changes: 3 additions & 1 deletion ios/RCTConvert+ChannelIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import <Foundation/Foundation.h>
#import <React/RCTConvert.h>
#import <ChannelIOFront/ChannelIOFront-Swift.h>
#import <ChannelIOFront/ChannelIOFront-swift.h>

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -50,6 +50,8 @@ static NSString * const KEY_MEMBER_HASH = @"memberHash";
static NSString * const KEY_HIDE_POPUP = @"hidePopup";
static NSString * const KEY_TRACK_DEFAULT_EVENT = @"trackDefaultEvent";
static NSString * const KEY_CHANNEL_BUTTON_OPTION = @"channelButtonOption";
static NSString * const KEY_UNSUBSCRIBE_EMAIL = @"unsubscribeEmail";
static NSString * const KEY_UNSUBSCRIBE_TEXTING = @"unsubscribeTexting";

static NSString * const KEY_MEMBER_ID = @"memberId";
static NSString * const KEY_LANGUAGE = @"language";
Expand Down
4 changes: 3 additions & 1 deletion ios/RCTConvert+ChannelIO.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ + (BootConfig *)bootConfig:(id)json {
? [RCTConvert BOOL:json[KEY_HIDE_POPUP]] : [RCTConvert BOOL:json[KEY_HIDE_DEFAULT_IN_APP_PUSH]];
config.trackDefaultEvent = json[KEY_TRACK_DEFAULT_EVENT] != nil
? [RCTConvert BOOL:json[KEY_TRACK_DEFAULT_EVENT]] : [RCTConvert BOOL:json[KEY_ENABLED_TRACK_DEFAULT_EVENT]];

config.unsubscribeEmail = [RCTConvert BOOL:json[KEY_UNSUBSCRIBE_EMAIL]];
config.unsubscribeTexting = [RCTConvert BOOL:json[KEY_UNSUBSCRIBE_TEXTING]];

if (json[KEY_LAUNCHER_CONFIG] == nil && json[KEY_CHANNEL_BUTTON_OPTION] != nil) {
config.channelButtonOption = [RCTConvert channelButtonOption:json[KEY_CHANNEL_BUTTON_OPTION]];
} else if (json[KEY_LAUNCHER_CONFIG] != nil && json[KEY_CHANNEL_BUTTON_OPTION] == nil) {
Expand Down
8 changes: 3 additions & 5 deletions ios/RNChannelIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>
#import <ChannelIOFront/ChannelIOFront-Swift.h>
#import <ChannelIOFront/ChannelIOFront-swift.h>

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -20,7 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
static NSString * const EVENT = @"Event";

static NSString * const KEY_EVENT_ON_BADGE_CHANGED = @"ON_BADGE_CHANGED";
static NSString * const KEY_EVENT_ON_PROFILE_CHANGED = @"ON_PROFILE_CHANGED";
static NSString * const KEY_EVENT_ON_FOLLOW_UP_CHANGED = @"ON_FOLLOW_UP_CHANGED";
static NSString * const KEY_EVENT_ON_POPUP_DATA_RECEIVED = @"ON_POPUP_DATA_RECEIVED";
static NSString * const KEY_EVENT_ON_SHOW_MESSENGER = @"ON_SHOW_MESSENGER";
static NSString * const KEY_EVENT_ON_HIDE_MESSENGER = @"ON_HIDE_MESSENGER";
Expand All @@ -29,7 +29,7 @@ static NSString * const KEY_EVENT_ON_PRE_URL_CLICKED = @"ON_PRE_URL_CLICKED";
static NSString * const KEY_EVENT_ON_URL_CLICKED = @"ON_URL_CLICKED";

static NSString * const EVENT_ON_BADGE_CHANGED = @"ChannelIO:Event:OnBadgeChanged";
static NSString * const EVENT_ON_PROFILE_CHANGED = @"ChannelIO:Event:OnProfileChanged";
static NSString * const EVENT_ON_FOLLOW_UP_CHANGED = @"ChannelIO:Event:OnFollowUpChanged";
static NSString * const EVENT_ON_POPUP_DATA_RECEIVED = @"ChannelIO:Event:OnPopupDataReceive";
static NSString * const EVENT_ON_SHOW_MESSENGER = @"ChannelIO:Event:OnShowMessenger";
static NSString * const EVENT_ON_HIDE_MESSENGER = @"ChannelIO:Event:OnHideMessenger";
Expand Down Expand Up @@ -69,8 +69,6 @@ static NSString * const KEY_COUNT = @"count";
static NSString * const KEY_URL = @"url";
static NSString * const KEY_POPUP = @"popup";
static NSString * const KEY_PROFILE_ONCE = @"profileOnce";
static NSString * const KEY_PROFILE_KEY = @"key";
static NSString * const KEY_PROFILE_VALUE = @"value";
static NSString * const KEY_USER = @"user";
static NSString * const KEY_ERROR = @"error";
static NSString * const KEY_TAGS = @"tags";
Expand Down
24 changes: 5 additions & 19 deletions ios/RNChannelIO.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ - (NSDictionary *)constantsToExport {
return @{
EVENT: @{
KEY_EVENT_ON_BADGE_CHANGED: EVENT_ON_BADGE_CHANGED,
KEY_EVENT_ON_PROFILE_CHANGED: EVENT_ON_PROFILE_CHANGED,
KEY_EVENT_ON_FOLLOW_UP_CHANGED: EVENT_ON_FOLLOW_UP_CHANGED,
KEY_EVENT_ON_POPUP_DATA_RECEIVED: EVENT_ON_POPUP_DATA_RECEIVED,
KEY_EVENT_ON_SHOW_MESSENGER: EVENT_ON_SHOW_MESSENGER,
KEY_EVENT_ON_HIDE_MESSENGER: EVENT_ON_HIDE_MESSENGER,
Expand All @@ -85,20 +85,6 @@ - (NSDictionary *)constantsToExport {
CHANNEL_BUTTON_POSITION: @{
KEY_CHANNEL_BUTTON_OPTION_POSITION_RIGHT: @(ChannelButtonPositionRight),
KEY_CHANNEL_BUTTON_OPTION_POSITION_LEFT: @(ChannelButtonPositionLeft)
},
CHANNEL_PLUGIN_COMPLETION_STATUS: @{
KEY_BOOT_STATUS_SUCCESS: @(ChannelPluginCompletionStatusSuccess),
KEY_BOOT_STATUS_NOT_INITIALIZED: @(ChannelPluginCompletionStatusNotInitialized),
KEY_BOOT_STATUS_NETWORK_TIMEOUT: @(ChannelPluginCompletionStatusNetworkTimeout),
KEY_BOOT_STATUS_NOT_AVAILABLE_VERSION: @(ChannelPluginCompletionStatusNotAvailableVersion),
KEY_BOOT_STATUS_SERVICE_UNDER_CONSTRUCTION: @(ChannelPluginCompletionStatusServiceUnderConstruction),
KEY_BOOT_STATUS_REQUIRE_PAYMENT: @(ChannelPluginCompletionStatusRequirePayment),
KEY_BOOT_STATUS_ACCESS_DENIED: @(ChannelPluginCompletionStatusAccessDenied),
KEY_BOOT_STATUS_UNKNOWN_ERROR: @(ChannelPluginCompletionStatusUnknown)
},
LAUNCHER_POSITION: @{
KEY_CHANNEL_BUTTON_OPTION_POSITION_RIGHT: @(LauncherPositionRight),
KEY_CHANNEL_BUTTON_OPTION_POSITION_LEFT: @(LauncherPositionLeft)
}
};
}
Expand All @@ -111,7 +97,7 @@ - (NSDictionary *)constantsToExport {
EVENT_ON_SHOW_MESSENGER,
EVENT_ON_PRE_URL_CLICKED,
EVENT_ON_URL_CLICKED,
EVENT_ON_PROFILE_CHANGED,
EVENT_ON_FOLLOW_UP_CHANGED,
EVENT_ON_POPUP_DATA_RECEIVED
];
}
Expand All @@ -120,6 +106,7 @@ - (NSDictionary *)constantsToExport {
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {
BootConfig * config = [RCTConvert bootConfig:bootConfig];

[ChannelIO bootWith:config completion:^(BootStatus status, User *user) {
NSString * stringStatus = BOOT_STATUS_UNKNOWN_ERROR;
switch (status) {
Expand Down Expand Up @@ -394,10 +381,9 @@ - (BOOL)onUrlClickedWithUrl:(NSURL *)url {
return true;
}

- (void)onProfileChangedWithKey:(NSString *)key value:(id)value {
- (void)onFollowUpChangedWithData:(NSDictionary<NSString *,id> *)data {
if (hasListeners) {
[self sendEventWithName:EVENT_ON_PROFILE_CHANGED
body: @{KEY_PROFILE_KEY: key, KEY_PROFILE_VALUE: value}];
[self sendEventWithName:EVENT_ON_FOLLOW_UP_CHANGED body:data];
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-channel-plugin",
"version": "0.6.9",
"version": "0.7.0",
"description": "react native module for channel io",
"main": "index.js",
"scripts": {
Expand Down