Skip to content

Commit

Permalink
Allow auto-downloads from groups you've accepted.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed Jul 23, 2020
1 parent 5bf15b0 commit dadb2f9
Showing 1 changed file with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
import org.thoughtcrime.securesms.attachments.AttachmentId;
import org.thoughtcrime.securesms.attachments.DatabaseAttachment;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.NoSuchMessageException;
import org.thoughtcrime.securesms.database.model.MessageRecord;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.recipients.Recipient;

import java.util.Collections;
import java.util.Set;
Expand All @@ -30,7 +32,7 @@ public static boolean isAutoDownloadPermitted(@NonNull Context context, @Nullabl
return true;
}

if (isFromUnknownContact(context, attachment)) {
if (!isFromTrustedConversation(context, attachment)) {
return false;
}

Expand Down Expand Up @@ -105,18 +107,28 @@ private static boolean isConnectedRoaming(@NonNull Context context) {
}

@WorkerThread
private static boolean isFromUnknownContact(@NonNull Context context, @NonNull DatabaseAttachment attachment) {
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.getRecipient().isProfileSharing() &&
!message.isOutgoing() &&
!message.getRecipient().isLocalNumber())) {
return true;
private static boolean isFromTrustedConversation(@NonNull Context context, @NonNull DatabaseAttachment attachment) {
try {
MessageRecord message = DatabaseFactory.getMmsDatabase(context).getMessageRecord(attachment.getMmsId());

Recipient individualRecipient = message.getRecipient();
Recipient threadRecipient = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(message.getThreadId());

if (threadRecipient != null && threadRecipient.isGroup()) {
return threadRecipient.isProfileSharing() || isTrustedIndividual(individualRecipient, message);
} else {
return isTrustedIndividual(individualRecipient, message);
}
} catch (NoSuchMessageException e) {
Log.w(TAG, "Message could not be found! Assuming not a trusted contact.");
return false;
}
}

return false;
private static boolean isTrustedIndividual(@NonNull Recipient recipient, @NonNull MessageRecord message) {
return recipient.isSystemContact() ||
recipient.isProfileSharing() ||
message.isOutgoing() ||
recipient.isLocalNumber();
}
}
}

0 comments on commit dadb2f9

Please sign in to comment.