From c8238df8ffae640cb0c70503940a1710dc625c2f Mon Sep 17 00:00:00 2001 From: Mikunj Date: Wed, 16 Oct 2019 14:32:10 +1100 Subject: [PATCH] Update checks to isFromUnkownContact. --- .../securesms/util/AttachmentUtil.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/org/thoughtcrime/securesms/util/AttachmentUtil.java b/src/org/thoughtcrime/securesms/util/AttachmentUtil.java index 81c338b370..84ea6cf386 100644 --- a/src/org/thoughtcrime/securesms/util/AttachmentUtil.java +++ b/src/org/thoughtcrime/securesms/util/AttachmentUtil.java @@ -15,6 +15,7 @@ import org.thoughtcrime.securesms.attachments.DatabaseAttachment; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.model.MessageRecord; import org.thoughtcrime.securesms.logging.Log; +import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus; import java.util.Collections; import java.util.Set; @@ -106,14 +107,16 @@ public class AttachmentUtil { @WorkerThread private static boolean isFromUnknownContact(@NonNull Context context, @NonNull DatabaseAttachment attachment) { + MessageRecord message; try (Cursor messageCursor = DatabaseFactory.getMmsDatabase(context).getMessage(attachment.getMmsId())) { - final MessageRecord message = DatabaseFactory.getMmsDatabase(context).readerFor(messageCursor).getNext(); - - if (message == null || (!message.getRecipient().isSystemContact() && !message.isOutgoing() && !Util.isOwnNumber(context, message.getRecipient().getAddress()))) { - return true; - } + message = DatabaseFactory.getMmsDatabase(context).readerFor(messageCursor).getNext(); } - return false; + if (message == null) { return true; } + + // check to see if we're friends with the person + long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdIfExistsFor(message.getRecipient()); + boolean isFriend = threadId >= 0 && DatabaseFactory.getLokiThreadDatabase(context).getFriendRequestStatus(threadId) == LokiThreadFriendRequestStatus.FRIENDS; + return (!isFriend && !message.isOutgoing() && !Util.isOwnNumber(context, message.getRecipient().getAddress())); } }