clear notifications on message read

Signed-off-by: Michele Balistreri <michele@bitgamma.com>
This commit is contained in:
Michele Balistreri 2021-08-19 13:36:25 +03:00
parent a569687161
commit 8c493510a4
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
7 changed files with 36 additions and 9 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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])}]})

View File

@ -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)]}]))}))

View File

@ -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)))))

View File

@ -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

View File

@ -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]