diff --git a/modules/react-native-status/android/src/main/java/im/status/ethereum/pushnotifications/PushNotification.java b/modules/react-native-status/android/src/main/java/im/status/ethereum/pushnotifications/PushNotification.java index ce7a2e71b8..4c3cef4f32 100644 --- a/modules/react-native-status/android/src/main/java/im/status/ethereum/pushnotifications/PushNotification.java +++ b/modules/react-native-status/android/src/main/java/im/status/ethereum/pushnotifications/PushNotification.java @@ -117,6 +117,13 @@ public class PushNotification extends ReactContextBaseJavaModule implements Acti pushNotificationHelper.sendToNotificationCentre(bundle); } + @ReactMethod + public void clearMessageNotifications(String conversationId) { + if (this.started) { + pushNotificationHelper.clearMessageNotifications(conversationId); + } + } + @ReactMethod public void enableNotifications() { this.started = true; diff --git a/modules/react-native-status/android/src/main/java/im/status/ethereum/pushnotifications/PushNotificationHelper.java b/modules/react-native-status/android/src/main/java/im/status/ethereum/pushnotifications/PushNotificationHelper.java index b564cbc81d..73774060f2 100644 --- a/modules/react-native-status/android/src/main/java/im/status/ethereum/pushnotifications/PushNotificationHelper.java +++ b/modules/react-native-status/android/src/main/java/im/status/ethereum/pushnotifications/PushNotificationHelper.java @@ -119,13 +119,9 @@ public class PushNotificationHelper { context.startActivity(getOpenAppIntent(deepLink)); } if (groupId != null) { - removeGroup(groupId); - // clean up the group notifications when there is no - // more unread chats - if (messageGroups.size() == 0) { - notificationManager.cancelAll(); - }} + cleanGroup(groupId); } + } if (intent.getAction() == ACTION_TAP_STOP) { stop(); System.exit(0); @@ -190,6 +186,11 @@ public class PushNotificationHelper { } } + public void clearMessageNotifications(String conversationId) { + notificationManager.cancel(conversationId.hashCode()); + cleanGroup(conversationId); + } + public void sendToNotificationCentreWithPicture(final Bundle bundle, Bitmap largeIconBitmap, Bitmap bigPictureBitmap) { try { @@ -823,6 +824,13 @@ public class PushNotificationHelper { this.messageGroups.remove(groupId); } + private void cleanGroup(String groupId) { + removeGroup(groupId); + if (messageGroups.size() == 0) { + notificationManager.cancelAll(); + } + } + public void start() { Log.e(LOG_TAG, "Starting Foreground Service"); Intent serviceIntent = new Intent(context, ForegroundService.class); diff --git a/src/status_im/chat/models/loading.cljs b/src/status_im/chat/models/loading.cljs index 1dad858cc7..df4acaa2d9 100644 --- a/src/status_im/chat/models/loading.cljs +++ b/src/status_im/chat/models/loading.cljs @@ -65,7 +65,8 @@ (fx/defn handle-mark-all-read {:events [:chat.ui/mark-all-read-pressed :chat/mark-all-as-read]} [_ chat-id] - {::json-rpc/call [{:method (json-rpc/call-ext-method "markAllRead") + {:clear-message-notifications chat-id + ::json-rpc/call [{:method (json-rpc/call-ext-method "markAllRead") :params [chat-id] :on-success #(re-frame/dispatch [::mark-all-read-successful chat-id])}]}) diff --git a/src/status_im/chat/models/message.cljs b/src/status_im/chat/models/message.cljs index cf1d0ae8c3..9adacd59da 100644 --- a/src/status_im/chat/models/message.cljs +++ b/src/status_im/chat/models/message.cljs @@ -129,8 +129,8 @@ {:db db :utils/dispatch-later (concat [{:ms 20 :dispatch [:process-response response-js]}] - (when-let [chat-id (:current-chat-id db)] - [{:ms 100 :dispatch [:chat/mark-all-as-read chat-id]}]) + (when (and (:current-chat-id db) (= "active" (:app-state db))) + [{:ms 100 :dispatch [:chat/mark-all-as-read (:current-chat-id db)]}]) (when (seq senders) [{:ms 100 :dispatch [:chat/add-senders-to-chat-users (vals senders)]}]))})) diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index 86e5933841..01ef46f914 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -146,6 +146,8 @@ (mailserver/process-next-messages-request) (wallet/restart-wallet-service-after-background app-in-background-since) (universal-links/process-stored-event) + #(when-let [chat-id (:current-chat-id db)] + {:dispatch [:chat/mark-all-as-read chat-id]}) #(when requires-bio-auth (biometric/authenticate % on-biometric-auth-result authentication-options))))) diff --git a/src/status_im/notifications/android.cljs b/src/status_im/notifications/android.cljs index 0c52f63a2b..94d6906b44 100644 --- a/src/status_im/notifications/android.cljs +++ b/src/status_im/notifications/android.cljs @@ -10,6 +10,9 @@ (defn present-local-notification [opts] (.presentLocalNotification ^js (pn-android) (clj->js opts))) +(defn clear-message-notifications [chat-id] + (.clearMessageNotifications ^js (pn-android) chat-id)) + (defn create-channel [{:keys [channel-id channel-name]}] (.createChannel ^js (pn-android) #js {:channelId channel-id diff --git a/src/status_im/notifications/core.cljs b/src/status_im/notifications/core.cljs index dc30180102..d38c45d28e 100644 --- a/src/status_im/notifications/core.cljs +++ b/src/status_im/notifications/core.cljs @@ -86,6 +86,12 @@ (pn-android/disable-notifications) (.abandonPermissions ^js pn-ios)))) +(re-frame/reg-fx + :clear-message-notifications + (fn [chat-id] + (when platform/android? + (pn-android/clear-message-notifications chat-id)))) + (fx/defn handle-enable-notifications-event {:events [::registered-for-push-notifications]} [cofx token]