manually remove summary-notification; this is needed when we cancel the other notifications from within the app

This commit is contained in:
B. Petersen 2020-06-13 16:01:01 +02:00
parent 974364fc4d
commit 2caaa1e097
No known key found for this signature in database
GPG key ID: 3B88E92DEA8E9AFC
3 changed files with 23 additions and 11 deletions

View file

@ -285,7 +285,8 @@
android:enabled="true" android:enabled="true"
android:exported="false"> android:exported="false">
<intent-filter> <intent-filter>
<action android:name="org.thoughtcrime.securesms.notifications.CLEAR"/> <action android:name="org.thoughtcrime.securesms.notifications.MARK_NOTICED"/>
<action android:name="org.thoughtcrime.securesms.notifications.CANCEL"/>
</intent-filter> </intent-filter>
</receiver> </receiver>

View file

@ -11,13 +11,14 @@ import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.util.Util; import org.thoughtcrime.securesms.util.Util;
public class MarkReadReceiver extends BroadcastReceiver { public class MarkReadReceiver extends BroadcastReceiver {
public static final String MARK_NOTICED_ACTION = "org.thoughtcrime.securesms.notifications.MARK_NOTICED";
public static final String CLEAR_ACTION = "org.thoughtcrime.securesms.notifications.CLEAR"; public static final String CANCEL_ACTION = "org.thoughtcrime.securesms.notifications.CANCEL";
public static final String CHAT_ID_EXTRA = "chat_id"; public static final String CHAT_ID_EXTRA = "chat_id";
@Override @Override
public void onReceive(final Context context, Intent intent) { 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; return;
} }
@ -30,7 +31,9 @@ public class MarkReadReceiver extends BroadcastReceiver {
Util.runOnAnyBackgroundThread(() -> { Util.runOnAnyBackgroundThread(() -> {
dcContext.notificationCenter.removeNotifications(chatId); dcContext.notificationCenter.removeNotifications(chatId);
dcContext.marknoticedChat(chatId); if (markNoticed) {
dcContext.marknoticedChat(chatId);
}
}); });
} }
} }

View file

@ -116,8 +116,8 @@ public class NotificationCenter {
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
} }
private PendingIntent getMarkAsReadIntent(int chatId) { private PendingIntent getMarkAsReadIntent(int chatId, boolean markNoticed) {
Intent intent = new Intent(MarkReadReceiver.CLEAR_ACTION); Intent intent = new Intent(markNoticed? MarkReadReceiver.MARK_NOTICED_ACTION : MarkReadReceiver.CANCEL_ACTION);
intent.setClass(context, MarkReadReceiver.class); intent.setClass(context, MarkReadReceiver.class);
intent.setData((Uri.parse("custom://"+System.currentTimeMillis()))); intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
intent.putExtra(MarkReadReceiver.CHAT_ID_EXTRA, chatId); intent.putExtra(MarkReadReceiver.CHAT_ID_EXTRA, chatId);
@ -351,7 +351,7 @@ public class NotificationCenter {
.setGroup(GRP_MSG) .setGroup(GRP_MSG)
.setOnlyAlertOnce(!signal) .setOnlyAlertOnce(!signal)
.setContentText(line) .setContentText(line)
.setDeleteIntent(getDeleteIntent()) .setDeleteIntent(getMarkAsReadIntent(chatId, false))
.setContentIntent(getOpenChatIntent(chatId)); .setContentIntent(getOpenChatIntent(chatId));
if (privacy.isDisplayContact()) { if (privacy.isDisplayContact()) {
builder.setContentTitle(dcChat.getName()); builder.setContentTitle(dcChat.getName());
@ -417,7 +417,7 @@ public class NotificationCenter {
&& !Prefs.isScreenLockEnabled(context)) { && !Prefs.isScreenLockEnabled(context)) {
try { try {
PendingIntent inNotificationReplyIntent = getRemoteReplyIntent(chatId); PendingIntent inNotificationReplyIntent = getRemoteReplyIntent(chatId);
PendingIntent markReadIntent = getMarkAsReadIntent(chatId); PendingIntent markReadIntent = getMarkAsReadIntent(chatId, true);
NotificationCompat.Action markAsReadAction = new NotificationCompat.Action(R.drawable.check, NotificationCompat.Action markAsReadAction = new NotificationCompat.Action(R.drawable.check,
context.getString(R.string.notify_mark_read), context.getString(R.string.notify_mark_read),
@ -492,11 +492,19 @@ public class NotificationCenter {
} }
public void removeNotifications(int chatId) { public void removeNotifications(int chatId) {
boolean removeSummary = false;
synchronized (inboxes) { synchronized (inboxes) {
inboxes.remove(chatId); 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() { public void removeAllNotifiations() {