From c121f665261bc83c4facaf528f7a99abd28a8f56 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Wed, 26 Jun 2019 04:59:07 -0400 Subject: [PATCH] MM-16463 Fix replying from push notification to a message in a thread (#2927) --- .../rnbeta/InitializationModule.java | 3 --- .../mattermost/rnbeta/MainApplication.java | 1 - .../NotificationReplyBroadcastReceiver.java | 6 ++++- app/mattermost.js | 5 ++--- .../push_notifications.android.js | 22 +------------------ 5 files changed, 8 insertions(+), 29 deletions(-) diff --git a/android/app/src/main/java/com/mattermost/rnbeta/InitializationModule.java b/android/app/src/main/java/com/mattermost/rnbeta/InitializationModule.java index 6ec2e082e..cf8a489dc 100644 --- a/android/app/src/main/java/com/mattermost/rnbeta/InitializationModule.java +++ b/android/app/src/main/java/com/mattermost/rnbeta/InitializationModule.java @@ -57,7 +57,6 @@ public class InitializationModule extends ReactContextBaseJavaModule { * * Miscellaneous: * MattermostManaged.Config - * replyFromPushNotification */ MainApplication app = (MainApplication) mApplication; @@ -138,8 +137,6 @@ public class InitializationModule extends ReactContextBaseJavaModule { } constants.put("managedConfig", config[0]); - constants.put("replyFromPushNotification", app.replyFromPushNotification); - app.replyFromPushNotification = false; return constants; } diff --git a/android/app/src/main/java/com/mattermost/rnbeta/MainApplication.java b/android/app/src/main/java/com/mattermost/rnbeta/MainApplication.java index 0fabde91c..967d9cd3b 100644 --- a/android/app/src/main/java/com/mattermost/rnbeta/MainApplication.java +++ b/android/app/src/main/java/com/mattermost/rnbeta/MainApplication.java @@ -60,7 +60,6 @@ import android.util.Log; public class MainApplication extends NavigationApplication implements INotificationsApplication, INotificationsDrawerApplication { public NotificationsLifecycleFacade notificationsLifecycleFacade; public Boolean sharedExtensionIsOpened = false; - public Boolean replyFromPushNotification = false; public long APP_START_TIME; diff --git a/android/app/src/main/java/com/mattermost/rnbeta/NotificationReplyBroadcastReceiver.java b/android/app/src/main/java/com/mattermost/rnbeta/NotificationReplyBroadcastReceiver.java index f5610431f..cc99e0316 100644 --- a/android/app/src/main/java/com/mattermost/rnbeta/NotificationReplyBroadcastReceiver.java +++ b/android/app/src/main/java/com/mattermost/rnbeta/NotificationReplyBroadcastReceiver.java @@ -79,7 +79,11 @@ public class NotificationReplyBroadcastReceiver extends BroadcastReceiver { protected void replyToMessage(final String serverUrl, final String token, final int notificationId, final CharSequence message) { final String channelId = bundle.getString("channel_id"); - final String rootId = bundle.getString("post_id"); + final String postId = bundle.getString("post_id"); + String rootId = bundle.getString("root_id"); + if (android.text.TextUtils.isEmpty(rootId)) { + rootId = postId; + } if (token == null || serverUrl == null) { onReplyFailed(notificationManager, notificationId, channelId); diff --git a/app/mattermost.js b/app/mattermost.js index 5f82d5d70..93338f7fe 100644 --- a/app/mattermost.js +++ b/app/mattermost.js @@ -511,9 +511,8 @@ const launchEntry = () => { configurePushNotifications(); const startedSharedExtension = Platform.OS === 'android' && MattermostShare.isOpened; -const fromPushNotification = Platform.OS === 'android' && Initialization.replyFromPushNotification; -if (startedSharedExtension || fromPushNotification) { +if (startedSharedExtension) { // Hold on launching Entry screen app.setAppStarted(true); } @@ -523,7 +522,7 @@ if (!app.appStarted) { } new NativeEventsReceiver().appLaunched(() => { - if (startedSharedExtension || fromPushNotification) { + if (startedSharedExtension) { app.setAppStarted(false); launchEntry(); } else if (app.token && app.url) { diff --git a/app/push_notifications/push_notifications.android.js b/app/push_notifications/push_notifications.android.js index 9e30212f1..2e3943a32 100644 --- a/app/push_notifications/push_notifications.android.js +++ b/app/push_notifications/push_notifications.android.js @@ -1,11 +1,8 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {AppRegistry, AppState, NativeModules} from 'react-native'; +import {AppState, NativeModules} from 'react-native'; import {NotificationsAndroid, PendingNotifications} from 'react-native-notifications'; -import Notification from 'react-native-notifications/notification.android'; - -import {emptyFunction} from 'app/utils/general'; const {NotificationPreferences} = NativeModules; @@ -37,23 +34,6 @@ class PushNotification { this.handleNotification(data, true); } }); - - AppRegistry.registerHeadlessTask('notificationReplied', () => async (deviceNotification) => { - const notification = new Notification(deviceNotification); - const data = notification.getData(); - const completed = emptyFunction; - - if (this.onReply) { - this.onReply(data, data.text, parseInt(data.badge, 10) - parseInt(data.msg_count, 10), completed); - } else { - this.deviceNotification = { - data, - text: data.text, - badge: parseInt(data.badge, 10) - parseInt(data.msg_count, 10), - completed, // used to identify that the notification belongs to a reply - }; - } - }); } handleNotification = (data, userInteraction) => {