diff --git a/AndroidManifest.xml b/AndroidManifest.xml index ad500c2e8..89a1c6008 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -285,7 +285,8 @@ android:enabled="true" android:exported="false"> - + + diff --git a/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java b/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java index add98df8b..71a199816 100644 --- a/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java +++ b/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java @@ -11,13 +11,14 @@ import org.thoughtcrime.securesms.connect.DcHelper; import org.thoughtcrime.securesms.util.Util; public class MarkReadReceiver extends BroadcastReceiver { - - public static final String CLEAR_ACTION = "org.thoughtcrime.securesms.notifications.CLEAR"; + public static final String MARK_NOTICED_ACTION = "org.thoughtcrime.securesms.notifications.MARK_NOTICED"; + public static final String CANCEL_ACTION = "org.thoughtcrime.securesms.notifications.CANCEL"; public static final String CHAT_ID_EXTRA = "chat_id"; @Override public void onReceive(final Context context, Intent intent) { - if (!CLEAR_ACTION.equals(intent.getAction())) { + boolean markNoticed = MARK_NOTICED_ACTION.equals(intent.getAction()); + if (!markNoticed && !CANCEL_ACTION.equals(intent.getAction())) { return; } @@ -30,7 +31,9 @@ public class MarkReadReceiver extends BroadcastReceiver { Util.runOnAnyBackgroundThread(() -> { dcContext.notificationCenter.removeNotifications(chatId); - dcContext.marknoticedChat(chatId); + if (markNoticed) { + dcContext.marknoticedChat(chatId); + } }); } } diff --git a/src/org/thoughtcrime/securesms/notifications/NotificationCenter.java b/src/org/thoughtcrime/securesms/notifications/NotificationCenter.java index c0d89f4bb..bb0f47825 100644 --- a/src/org/thoughtcrime/securesms/notifications/NotificationCenter.java +++ b/src/org/thoughtcrime/securesms/notifications/NotificationCenter.java @@ -116,8 +116,8 @@ public class NotificationCenter { return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); } - private PendingIntent getMarkAsReadIntent(int chatId) { - Intent intent = new Intent(MarkReadReceiver.CLEAR_ACTION); + private PendingIntent getMarkAsReadIntent(int chatId, boolean markNoticed) { + Intent intent = new Intent(markNoticed? MarkReadReceiver.MARK_NOTICED_ACTION : MarkReadReceiver.CANCEL_ACTION); intent.setClass(context, MarkReadReceiver.class); intent.setData((Uri.parse("custom://"+System.currentTimeMillis()))); intent.putExtra(MarkReadReceiver.CHAT_ID_EXTRA, chatId); @@ -351,7 +351,7 @@ public class NotificationCenter { .setGroup(GRP_MSG) .setOnlyAlertOnce(!signal) .setContentText(line) - .setDeleteIntent(getDeleteIntent()) + .setDeleteIntent(getMarkAsReadIntent(chatId, false)) .setContentIntent(getOpenChatIntent(chatId)); if (privacy.isDisplayContact()) { builder.setContentTitle(dcChat.getName()); @@ -417,7 +417,7 @@ public class NotificationCenter { && !Prefs.isScreenLockEnabled(context)) { try { PendingIntent inNotificationReplyIntent = getRemoteReplyIntent(chatId); - PendingIntent markReadIntent = getMarkAsReadIntent(chatId); + PendingIntent markReadIntent = getMarkAsReadIntent(chatId, true); NotificationCompat.Action markAsReadAction = new NotificationCompat.Action(R.drawable.check, context.getString(R.string.notify_mark_read), @@ -492,11 +492,19 @@ public class NotificationCenter { } public void removeNotifications(int chatId) { + boolean removeSummary = false; synchronized (inboxes) { inboxes.remove(chatId); + removeSummary = inboxes.isEmpty(); } - NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); - notificationManager.cancel(ID_MSG_OFFSET + chatId); + + try { + NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); + notificationManager.cancel(ID_MSG_OFFSET + chatId); + if (removeSummary) { + notificationManager.cancel(ID_MSG_SUMMARY); + } + } catch (Exception e) { Log.w(TAG, e); } } public void removeAllNotifiations() {