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.4.0
## Updates
* Updated channeltalk plugin v7.0

# 0.3.7
## Updates
* Updated ios target to 10.0 from 9.1
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 'com.zoyi.channel:plugin-android:6.1.+'
api 'com.zoyi.channel:plugin-android:7.0.+'
}
2 changes: 1 addition & 1 deletion android/src/main/java/com/zoyi/channel/rn/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Const {

// Boot
public static final String KEY_PLUGIN_KEY = "pluginKey";
public static final String KEY_USER_ID = "userId";
public static final String KEY_MEMBER_ID = "memberId";
public static final String KEY_LOCALE = "locale";
public static final String KEY_DEBUG_MODE = "debugMode";
public static final String KEY_ENABLED_TRACK_DEFAULT_EVENT = "enabledTrackDefaultEvent";
Expand Down
40 changes: 14 additions & 26 deletions android/src/main/java/com/zoyi/channel/rn/ParseUtils.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@

package com.zoyi.channel.rn;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReadableArray;
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.zoyi.channel.plugin.android.model.etc.*;
import com.facebook.react.bridge.*;
import com.zoyi.channel.plugin.android.*;
import com.zoyi.channel.plugin.android.model.etc.PushEvent;
import com.zoyi.channel.react.android.Const;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.*;

/**
* Created by jerry on 2018. 10. 11..
Expand Down Expand Up @@ -228,7 +216,7 @@ public static Profile toProfile(ReadableMap profileMap) {

public static ChannelPluginSettings toChannelPluginSettings(ReadableMap settingsMap) {
String pluginKey = Utils.getString(settingsMap, Const.KEY_PLUGIN_KEY);
String userId = Utils.getString(settingsMap, Const.KEY_USER_ID);
String userId = Utils.getString(settingsMap, Const.KEY_MEMBER_ID);
String locale = Utils.getString(settingsMap, Const.KEY_LOCALE);

boolean debugMode = Utils.getBoolean(settingsMap, Const.KEY_DEBUG_MODE, false);
Expand All @@ -239,7 +227,7 @@ public static ChannelPluginSettings toChannelPluginSettings(ReadableMap settings
ReadableMap profile = Utils.getReadableMap(settingsMap, Const.KEY_PROFILE);

return new ChannelPluginSettings(pluginKey)
.setUserId(userId)
.setMemberId(userId)
.setLocale(CHLocale.fromString(locale))
.setDebugMode(debugMode)
.setEnabledTrackDefaultEvent(enabledTrackDefaultEvent)
Expand Down Expand Up @@ -268,33 +256,33 @@ public static Map<String, String> toPushNotification(ReadableMap pushNotificatio
public static WritableMap getBootResult(
ChannelPluginListener listener,
ChannelPluginCompletionStatus status,
Guest guest) {
User user) {

WritableMap result = Arguments.createMap();

if (status == ChannelPluginCompletionStatus.SUCCESS) {
ChannelIO.setChannelPluginListener(listener);
result.putMap(Const.KEY_GUEST, ParseUtils.guestToWritableMap(guest));
result.putMap(Const.KEY_GUEST, ParseUtils.guestToWritableMap(user));
}

result.putString(Const.KEY_STATUS, status.toString());

return result;
}

public static WritableMap guestToWritableMap(Guest guest) {
public static WritableMap guestToWritableMap(User user) {
WritableMap guestMap = Arguments.createMap();

if (guest == null) {
if (user == null) {
return guestMap;
}

guestMap.putString(Const.KEY_ID, guest.getId());
guestMap.putString(Const.KEY_NAME, guest.getName());
guestMap.putString(Const.KEY_AVATAR_URL, guest.getAvatarUrl());
guestMap.putInt(Const.KEY_ALERT, guest.getAlert());
guestMap.putString(Const.KEY_ID, user.getId());
guestMap.putString(Const.KEY_NAME, user.getName());
guestMap.putString(Const.KEY_AVATAR_URL, user.getAvatarUrl());
guestMap.putInt(Const.KEY_ALERT, user.getAlert());

Map<String, Object> profile = guest.getProfile();
Map<String, Object> profile = user.getProfile();
if (profile != null) {
guestMap.putMap(Const.KEY_PROFILE, toWritableMap(profile));
}
Expand Down
30 changes: 10 additions & 20 deletions android/src/main/java/com/zoyi/channel/rn/RNChannelIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@

import android.app.Activity;
import android.content.Context;
import android.widget.Toast;

import com.facebook.react.bridge.*;
import com.zoyi.channel.plugin.android.*;
import com.zoyi.channel.plugin.android.global.*;

import com.facebook.react.bridge.ReadableMap;
import com.zoyi.channel.plugin.android.global.PrefSupervisor;
import com.zoyi.channel.plugin.android.model.etc.PushEvent;
import com.zoyi.channel.react.android.*;
import com.zoyi.channel.react.android.Const;

import java.util.HashMap;
Expand Down Expand Up @@ -81,8 +77,8 @@ public void boot(ReadableMap settings, final Promise promise) {
ParseUtils.toProfile(Utils.getReadableMap(settings, Const.KEY_PROFILE)),
new OnBootListener() {
@Override
public void onCompletion(ChannelPluginCompletionStatus status, Guest guest) {
promise.resolve(ParseUtils.getBootResult(RNChannelIO.this, status, guest));
public void onCompletion(ChannelPluginCompletionStatus status, User user) {
promise.resolve(ParseUtils.getBootResult(RNChannelIO.this, status, user));
}
});
}
Expand Down Expand Up @@ -121,7 +117,7 @@ public void openChat(String chatId, boolean animated) {
public void initPushToken(String tokenData) {
Context context = getCurrentActivity();

if (context != null){
if (context != null) {
PrefSupervisor.setDeviceToken(context, tokenData);
}
}
Expand All @@ -130,7 +126,7 @@ public void initPushToken(String tokenData) {
public void handlePushNotification(ReadableMap userInfo, Promise promise) {
Context context = getCurrentActivity();

if (context != null){
if (context != null) {
ChannelIO.showPushNotification(context, ParseUtils.toPushNotification(userInfo));
}

Expand All @@ -141,7 +137,7 @@ public void handlePushNotification(ReadableMap userInfo, Promise promise) {
public void handlePush() {
Activity activity = getCurrentActivity();

if (activity != null){
if (activity != null) {
ChannelIO.handlePushNotification(activity);
}
}
Expand Down Expand Up @@ -196,18 +192,12 @@ public boolean onClickChatLink(String url) {
return handleChatLink;
}

@Override
public boolean onClickRedirectUrl(String url) {
Utils.sendEvent(reactContext, Const.EVENT_ON_CLICK_REDIRECT_LINK, ParseUtils.createSingleMap(Const.KEY_EVENT_LINK, url));
return handleRedirectLink;
}

@Override
public void onChangeProfile(String key, Object value) {
Utils.sendEvent(
reactContext,
Const.EVENT_ON_CHANGE_PROFILE,
ParseUtils.createKeyValueMap(Const.KEY_PROFILE_KEY, key, Const.KEY_PROFILE_VALUE, value)
reactContext,
Const.EVENT_ON_CHANGE_PROFILE,
ParseUtils.createKeyValueMap(Const.KEY_PROFILE_KEY, key, Const.KEY_PROFILE_VALUE, value)
);
}
}
}
21 changes: 3 additions & 18 deletions android/src/main/java/com/zoyi/channel/rn/Utils.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@

package com.zoyi.channel.rn;

import android.content.Context;
import android.util.Log;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReadableArray;
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.zoyi.channel.plugin.android.model.entity.Guest;
import com.zoyi.channel.plugin.android.*;
import com.zoyi.channel.plugin.android.global.*;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import com.facebook.react.bridge.*;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.zoyi.channel.plugin.android.global.PrefSupervisor;

/**
* Created by mika on 2018. 9. 18..
Expand Down
17 changes: 1 addition & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,6 @@ export const ChannelIO = {
replaceListener(ChannelModule.Event.ON_CLICK_CHAT_LINK, subscription);
},

/**
* Event listener that triggers when a redirect on push bot link has been clicked by a user
* @param {Boolean} handle True if you want to handle a link, otherwise false
* @param {Function} cb a callback function that takes a string link as parameter
*/
onClickRedirectLink: (handle, cb) => {
let subscription = ChannelModule.setRedirectLinkHandle(handle);
ChannelEventEmitter.addListener(ChannelModule.Event.ON_CLICK_REDIRECT_LINK, (data) => {
cb(data.link);
});

replaceListener(ChannelModule.Event.ON_CLICK_REDIRECT_LINK, subscription);
},

/**
* Event listener that triggers when guest profile is updated
* @param {Function} cb a callback function that takes a key, value
Expand Down Expand Up @@ -198,9 +184,8 @@ export const ChannelIO = {
ON_CHANGE_BADGE: ChannelModule.Event.ON_CHANGE_BADGE,
ON_RECEIVE_PUSH: ChannelModule.Event.ON_RECEIVE_PUSH,
ON_CLICK_CHAT_LINK: ChannelModule.Event.ON_CLICK_CHAT_LINK,
ON_CLICK_REDIRECT_LINK: ChannelModule.Event.ON_CLICK_REDIRECT_LINK,
ON_CHANGE_PROFILE: ChannelModule.Event.ON_CHANGE_PROFILE,
WILL_SHOW_MESSENGER: ChannelModule.Event.WILL_SHOW_MESSENGER,
WILL_HIDE_MESSENGER: ChannelModule.Event.WILL_HIDE_MESSENGER
}
}
}
18 changes: 9 additions & 9 deletions ios/RCTConvert+ChannelIO.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ + (ChannelPluginSettings *)settings:(id)json {
settings.debugMode = [RCTConvert BOOL:json[@"debugMode"]];
settings.hideDefaultInAppPush = [RCTConvert BOOL:json[@"hideDefaultInAppPush"]];
settings.launcherConfig = [RCTConvert launcherConfig:json[@"launcherConfig"]];
settings.userId = [RCTConvert NSString:json[@"userId"]];
settings.memberId = [RCTConvert NSString:json[@"memberId"]];

NSString *locale = [RCTConvert NSString:json[@"locale"]];
if ([locale isEqualToString:@"ko"]) {
settings.locale = CHLocaleKorean;
} else if ([locale isEqualToString:@"ja"]) {
settings.locale = CHLocaleJapanese;
} else if ([locale isEqualToString:@"en"]) {
settings.locale = CHLocaleEnglish;
NSString *language = [RCTConvert NSString:json[@"language"]];
if ([language isEqualToString:@"ko"]) {
settings.language = CHLocaleKorean;
} else if ([language isEqualToString:@"ja"]) {
settings.language = CHLocaleJapanese;
} else if ([language isEqualToString:@"en"]) {
settings.language = CHLocaleEnglish;
} else {
settings.locale = CHLocaleDevice;
settings.language = CHLocaleDevice;
}
return settings;
}
Expand Down
1 change: 0 additions & 1 deletion ios/RNChannelIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ static NSString * const ON_RECEIVE_PUSH = @"ChannelIO:Event:OnReceivePush";
static NSString * const WILL_SHOW_MESSENGER = @"ChannelIO:Event:WillShowMessenger";
static NSString * const WILL_HIDE_MESSENGER = @"ChannelIO:Event:WillHideMessenger";
static NSString * const ON_CLICK_CHAT_LINK = @"ChannelIO:Event:OnClickChatLink";
static NSString * const ON_CLICK_REDIRECT_LINK = @"ChannelIO:Event:OnClickRedirectLink";
static NSString * const ON_CHANGE_PROFILE = @"ChannelIO:Event:OnChangeProfile";

NS_ASSUME_NONNULL_END
Expand Down
23 changes: 4 additions & 19 deletions ios/RNChannelIO.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ @implementation RNChannelIO
{
BOOL hasListeners;
BOOL handleChatLink;
BOOL handleRedirectLink;
}

RCT_EXPORT_MODULE()
Expand Down Expand Up @@ -62,8 +61,7 @@ - (NSDictionary *)constantsToExport {
@"ON_RECEIVE_PUSH": ON_RECEIVE_PUSH,
@"WILL_SHOW_MESSENGER": WILL_SHOW_MESSENGER,
@"WILL_HIDE_MESSENGER": WILL_HIDE_MESSENGER,
@"ON_CLICK_CHAT_LINK": ON_CLICK_CHAT_LINK,
@"ON_CLICK_REDIRECT_LINK": ON_CLICK_REDIRECT_LINK
@"ON_CLICK_CHAT_LINK": ON_CLICK_CHAT_LINK
},
@"Locale": @{
@"korean": @(CHLocaleKorean),
Expand Down Expand Up @@ -92,8 +90,7 @@ - (NSDictionary *)constantsToExport {
ON_RECEIVE_PUSH,
WILL_SHOW_MESSENGER,
WILL_HIDE_MESSENGER,
ON_CLICK_CHAT_LINK,
ON_CLICK_REDIRECT_LINK
ON_CLICK_CHAT_LINK
];
}

Expand All @@ -103,8 +100,8 @@ - (NSDictionary *)constantsToExport {
rejecter:(RCTPromiseRejectBlock)reject) {
ChannelPluginSettings * pluginSettings = [RCTConvert settings:settings];
Profile *userProfile = [RCTConvert profile:settings[@"profile"]];
[ChannelIO bootWith:pluginSettings profile:userProfile completion:^(ChannelPluginCompletionStatus status, Guest *guest) {
resolve(@{@"status": @(status), @"guest": guest != nil ? guest.toJson : NSNull.null });
[ChannelIO bootWith:pluginSettings profile:userProfile completion:^(ChannelPluginCompletionStatus status, User *user) {
resolve(@{@"status": @(status), @"user": user != nil ? user.toJson : NSNull.null });
}];
}

Expand Down Expand Up @@ -168,10 +165,6 @@ - (NSDictionary *)constantsToExport {
handleChatLink = handle;
}

RCT_EXPORT_METHOD(setRedirectLinkHandle:(BOOL)handle) {
handleRedirectLink = handle;
}

#pragma mark ChannelPluginDelegate

- (void)onChangeBadgeWithCount:(NSInteger)count {
Expand All @@ -194,14 +187,6 @@ - (BOOL)onClickChatLinkWithUrl:(NSURL *)url {
return handleChatLink;
}

- (BOOL)onClickRedirectWithUrl:(NSURL *)url {
if (hasListeners) {
[self sendEventWithName:ON_CLICK_REDIRECT_LINK body:@{@"link": url.absoluteString}];
return handleRedirectLink;
}
return handleRedirectLink;
}

- (void)onChangeProfileWithKey:(NSString *)key value:(id)value {
if (hasListeners) {
[self sendEventWithName:ON_CHANGE_PROFILE body: @{@"key": key, @"value": value}];
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.3.9",
"version": "0.4.0",
"description": "react native module for channel io",
"main": "index.js",
"scripts": {
Expand Down