From 5ae96905bb8bbdf148ca74e29b236eeea96c4a62 Mon Sep 17 00:00:00 2001 From: Alan Evans Date: Wed, 23 Sep 2020 13:00:25 -0300 Subject: [PATCH] Do not allow replying on reactions and messages without visible content. --- .../notifications/DefaultMessageNotifier.java | 11 ++++++++--- .../securesms/notifications/NotificationItem.java | 9 ++++++++- .../securesms/notifications/NotificationState.java | 3 +++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java index 3ffed3d04f..1a57ceb04f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java @@ -383,7 +383,7 @@ public class DefaultMessageNotifier implements MessageNotifier { notificationState.getQuickReplyIntent(context, notifications.get(0).getRecipient()), notificationState.getRemoteReplyIntent(context, notifications.get(0).getRecipient(), replyMethod), replyMethod, - !isSingleNotificationContactJoined); + !isSingleNotificationContactJoined && notificationState.canReply()); builder.addAndroidAutoAction(notificationState.getAndroidAutoReplyIntent(context, notifications.get(0).getRecipient()), notificationState.getAndroidAutoHeardIntent(context, notificationId), notifications.get(0).getTimestamp()); @@ -533,6 +533,8 @@ public class DefaultMessageNotifier implements MessageNotifier { } if (isUnreadMessage) { + boolean canReply = false; + if (KeyCachingService.isLocked(context)) { body = SpanUtil.italic(context.getString(R.string.MessageNotifier_locked_message)); } else if (record.isMms() && !((MmsMessageRecord) record).getSharedContacts().isEmpty()) { @@ -545,6 +547,9 @@ public class DefaultMessageNotifier implements MessageNotifier { } else if (record.isMms() && !record.isMmsNotification() && !((MmsMessageRecord) record).getSlideDeck().getSlides().isEmpty()) { body = ThreadBodyUtil.getFormattedBodyFor(context, record); slideDeck = ((MmsMessageRecord) record).getSlideDeck(); + canReply = true; + } else { + canReply = true; } boolean includeMessage = true; @@ -555,7 +560,7 @@ public class DefaultMessageNotifier implements MessageNotifier { } if (threadRecipients == null || includeMessage) { - notificationState.addNotification(new NotificationItem(id, mms, recipient, conversationRecipient, threadRecipients, threadId, body, timestamp, receivedTimestamp, slideDeck, false, record.isJoined())); + notificationState.addNotification(new NotificationItem(id, mms, recipient, conversationRecipient, threadRecipients, threadId, body, timestamp, receivedTimestamp, slideDeck, false, record.isJoined(), canReply)); } } @@ -590,7 +595,7 @@ public class DefaultMessageNotifier implements MessageNotifier { } if (threadRecipients == null || !threadRecipients.isMuted()) { - notificationState.addNotification(new NotificationItem(id, mms, reactionSender, conversationRecipient, threadRecipients, threadId, body, reaction.getDateReceived(), receivedTimestamp, null, true, record.isJoined())); + notificationState.addNotification(new NotificationItem(id, mms, reactionSender, conversationRecipient, threadRecipients, threadId, body, reaction.getDateReceived(), receivedTimestamp, null, true, record.isJoined(), false)); } } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationItem.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationItem.java index e8e417c604..7cbb786e73 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationItem.java +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationItem.java @@ -28,6 +28,7 @@ public class NotificationItem { @Nullable private final SlideDeck slideDeck; private final boolean jumpToMessage; private final boolean isJoin; + private final boolean canReply; public NotificationItem(long id, boolean mms, @@ -40,7 +41,8 @@ public class NotificationItem { long messageReceivedTimestamp, @Nullable SlideDeck slideDeck, boolean jumpToMessage, - boolean isJoin) + boolean isJoin, + boolean canReply) { this.id = id; this.mms = mms; @@ -54,6 +56,7 @@ public class NotificationItem { this.slideDeck = slideDeck; this.jumpToMessage = jumpToMessage; this.isJoin = isJoin; + this.canReply = canReply; } public @NonNull Recipient getRecipient() { @@ -112,4 +115,8 @@ public class NotificationItem { private static void makeIntentUniqueToPreventMerging(@NonNull Intent intent) { intent.setData((Uri.parse("custom://"+System.currentTimeMillis()))); } + + public boolean canReply() { + return canReply; + } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationState.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationState.java index 5a20ab0102..8650ecfbf0 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationState.java +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationState.java @@ -208,5 +208,8 @@ public class NotificationState { return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); } + public boolean canReply() { + return notifications.size() == 1 && notifications.get(0).canReply(); + } }