Skip to content

Commit e83e986

Browse files
authored
Merge pull request #105 from channel-io/develop
0.7.11
2 parents e8ba248 + 3d0cf33 commit e83e986

File tree

7 files changed

+103
-4
lines changed

7 files changed

+103
-4
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ local.properties
4545
.classpath
4646
.vscode
4747

48+
# JetBrains Fleet
49+
.fleet
50+
4851
# BUCK
4952
buck-out/
5053
\.buckd/

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 0.7.11
2+
3+
## Update
4+
* support android channel-io 10.0.8
5+
16
# 0.7.10
27

38
## Update

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ repositories {
5555

5656
dependencies {
5757
implementation 'com.facebook.react:react-native'
58-
api 'io.channel:plugin-android:10.0.7'
58+
api 'io.channel:plugin-android:10.0.8'
5959
}

android/src/main/java/com/zoyi/channel/rn/Const.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ public class Const {
88

99
public static final String MODULE_NAME = "RNChannelIO";
1010

11+
public static final String USER = "user";
12+
1113
public static final String KEY_PLUGIN_KEY = "pluginKey";
1214
public static final String KEY_MEMBER_ID = "memberId";
1315
public static final String KEY_MEMBER_HASH = "memberHash";
@@ -59,6 +61,7 @@ public class Const {
5961
// Event
6062
public static final String KEY_EVENT = "Event";
6163

64+
public static final String KEY_EVENT_USER_ID = "userId";
6265
public static final String KEY_EVENT_CHAT_ID = "chatId";
6366
public static final String KEY_EVENT_COUNT = "count";
6467
public static final String KEY_EVENT_URL = "url";
@@ -72,6 +75,7 @@ public class Const {
7275
public static final String KEY_ON_CHAT_CREATED = "ON_CHAT_CREATED";
7376
public static final String KEY_ON_URL_CLICKED = "ON_URL_CLICKED";
7477
public static final String KEY_ON_PRE_URL_CLICKED = "ON_PRE_URL_CLICKED";
78+
public static final String KEY_ON_PUSH_NOTIFICATION_CLICKED = "ON_PUSH_NOTIFICATION_CLICKED";
7579

7680
public static final String EVENT_ON_BADGE_CHANGED = "ChannelIO:Event:OnBadgeChanged";
7781
public static final String EVENT_ON_FOLLOW_UP_CHANGED = "ChannelIO:Event:OnFollowUpChanged";
@@ -81,4 +85,10 @@ public class Const {
8185
public static final String EVENT_ON_CHAT_CREATED = "ChannelIO:Event:OnChatCreated";
8286
public static final String EVENT_ON_URL_CLICKED = "ChannelIO:Event:OnUrlClicked";
8387
public static final String EVENT_ON_PRE_URL_CLICKED = "ChannelIO:Event:OnPreUrlClicked";
88+
public static final String EVENT_ON_PUSH_NOTIFICATION_CLICKED = "ChannelIO:Event:OnPushNotificationClicked";
89+
90+
// Extra
91+
public static final String EXTRA_CHAT_ID = "chatId";
92+
public static final String EXTRA_PERSON_TYPE = "personType";
93+
public static final String EXTRA_PERSON_ID = "personId";
8494
}

android/src/main/java/com/zoyi/channel/rn/RNChannelIO.java

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
import android.app.Activity;
44
import android.content.Context;
5+
import android.content.Intent;
56

67
import androidx.annotation.Nullable;
78

89
import com.facebook.react.bridge.*;
910
import com.zoyi.channel.plugin.android.ChannelIO;
11+
import com.zoyi.channel.plugin.android.global.PrefSupervisor;
1012
import com.zoyi.channel.plugin.android.open.callback.BootCallback;
1113
import com.zoyi.channel.plugin.android.open.callback.UserUpdateCallback;
1214
import com.zoyi.channel.plugin.android.open.enumerate.BootStatus;
@@ -22,6 +24,8 @@ public class RNChannelIO extends ReactContextBaseJavaModule implements ChannelPl
2224

2325
private ReactContext reactContext;
2426

27+
private boolean hasPushNotificationClickSubscriber = false;
28+
2529
public RNChannelIO(ReactApplicationContext reactContext) {
2630
super(reactContext);
2731
this.reactContext = reactContext;
@@ -46,6 +50,7 @@ public Map<String, Object> getConstants() {
4650
eventMap.put(Const.KEY_ON_FOLLOW_UP_CHANGED, Const.EVENT_ON_FOLLOW_UP_CHANGED);
4751
eventMap.put(Const.KEY_ON_URL_CLICKED, Const.EVENT_ON_URL_CLICKED);
4852
eventMap.put(Const.KEY_ON_PRE_URL_CLICKED, Const.EVENT_ON_PRE_URL_CLICKED);
53+
eventMap.put(Const.KEY_ON_PUSH_NOTIFICATION_CLICKED, Const.EVENT_ON_PUSH_NOTIFICATION_CLICKED);
4954

5055
constants.put(Const.KEY_EVENT, eventMap);
5156

@@ -240,9 +245,29 @@ public boolean onUrlClicked(String url) {
240245
return true;
241246
}
242247

248+
@ReactMethod
249+
public void notifyPushNotificationClickSubscriberExistence(boolean hasPushNotificationClickSubscriber) {
250+
this.hasPushNotificationClickSubscriber = hasPushNotificationClickSubscriber;
251+
}
252+
243253
@Override
244-
public boolean onPushNotificationClicked(String chatId) {
245-
return false;
254+
public boolean onPushNotificationClicked(final String chatId) {
255+
if (!hasPushNotificationClickSubscriber) { return false; }
256+
257+
// `PrefSupervisor` is an internal class that does not provide compatibility promise between SDK versions
258+
// -- avoid using it in third party libraries whenever possible as it may break at any time
259+
final String userId = PrefSupervisor.getLatestPushUserId(getCurrentActivity());
260+
if (userId == null) { return false; }
261+
262+
Utils.sendEvent(
263+
reactContext,
264+
Const.EVENT_ON_PUSH_NOTIFICATION_CLICKED,
265+
ParseUtils.toWritableMap(new HashMap<String, Object>() {{
266+
put(Const.KEY_USER_ID, userId);
267+
put(Const.KEY_CHAT_ID, chatId);
268+
}})
269+
);
270+
return true; // defer push notification click handling -- the JavaScript code will call `performDefaultPushNotificationClickAction` if needed.
246271
}
247272

248273
@Override
@@ -259,6 +284,37 @@ public void handleUrlClicked(@Nullable String url) {
259284
}
260285
}
261286

287+
@ReactMethod
288+
public void performDefaultPushNotificationClickAction(String userId, String chatId) {
289+
if (reactContext == null) { return; }
290+
final Context context = reactContext.getApplicationContext();
291+
292+
final Intent intent = reconstructHostAppIntent(userId, chatId);
293+
if (intent == null) { return; }
294+
295+
context.startActivity(intent);
296+
}
297+
298+
private Intent reconstructHostAppIntent(String userId, String chatId) {
299+
// Channel Android SDK does not provide listeners a host app intent that the SDK prepared to
300+
// launch when onPushNotificationClicked() returns false. So "reconstruct" a new one to
301+
// emulate the default handling behavior of onPushNotificationClicked().
302+
303+
if (reactContext == null) { return null; }
304+
Context context = reactContext.getApplicationContext();
305+
306+
Intent intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
307+
if (intent == null) { return null; }
308+
309+
intent.addCategory(Intent.CATEGORY_LAUNCHER);
310+
// EXTRA_CHANNEL_ID is deliberately omitted because it is not used.
311+
intent.putExtra(Const.EXTRA_PERSON_TYPE, Const.USER);
312+
intent.putExtra(Const.EXTRA_PERSON_ID, userId);
313+
intent.putExtra(Const.EXTRA_CHAT_ID, chatId);
314+
315+
return intent;
316+
}
317+
262318
@ReactMethod
263319
public void setPage(@Nullable String page) {
264320
ChannelIO.setPage(page);

index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,31 @@ export const ChannelIO = {
369369
}
370370
},
371371

372+
/**
373+
* Event listener that triggers when user clicks a system push notification.
374+
* Note that the callback only works on Android. A call to this method on an iOS
375+
* environment will be silently ignored.
376+
*
377+
* @param {Function} cb a callback function
378+
*/
379+
onPushNotificationClicked: (cb) => {
380+
if (Platform.OS !== 'android') { return }
381+
382+
if (cb) {
383+
const subscription = ChannelEventEmitter.addListener(ChannelModule.Event.ON_PUSH_NOTIFICATION_CLICKED, data => {
384+
const next = () => ChannelModule.performDefaultPushNotificationClickAction(data.userId, data.chatId);
385+
386+
cb(data.chatId, next);
387+
});
388+
389+
ChannelModule.notifyPushNotificationClickSubscriberExistence(true);
390+
replaceSubscriber(ChannelModule.Event.ON_PUSH_NOTIFICATION_CLICKED, subscription);
391+
} else {
392+
ChannelModule.notifyPushNotificationClickSubscriberExistence(false);
393+
replaceSubscriber(ChannelModule.Event.ON_PUSH_NOTIFICATION_CLICKED, null);
394+
}
395+
},
396+
372397
/**
373398
* @deprecated
374399
* Event listener that triggers when `ChannelIO` messenger is about to display

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-channel-plugin",
3-
"version": "0.7.10",
3+
"version": "0.7.11",
44
"description": "react native module for channel io",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)