Allow auto-downloads from groups you've accepted.
parent
5bf15b0587
commit
dadb2f9d37
|
@ -13,8 +13,10 @@ import android.text.TextUtils;
|
|||
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;
|
||||
|
@ -30,7 +32,7 @@ public class AttachmentUtil {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (isFromUnknownContact(context, attachment)) {
|
||||
if (!isFromTrustedConversation(context, attachment)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -105,18 +107,28 @@ public class AttachmentUtil {
|
|||
}
|
||||
|
||||
@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();
|
||||
private static boolean isFromTrustedConversation(@NonNull Context context, @NonNull DatabaseAttachment attachment) {
|
||||
try {
|
||||
MessageRecord message = DatabaseFactory.getMmsDatabase(context).getMessageRecord(attachment.getMmsId());
|
||||
|
||||
if (message == null || (!message.getRecipient().isSystemContact() &&
|
||||
!message.getRecipient().isProfileSharing() &&
|
||||
!message.isOutgoing() &&
|
||||
!message.getRecipient().isLocalNumber())) {
|
||||
return true;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isTrustedIndividual(@NonNull Recipient recipient, @NonNull MessageRecord message) {
|
||||
return recipient.isSystemContact() ||
|
||||
recipient.isProfileSharing() ||
|
||||
message.isOutgoing() ||
|
||||
recipient.isLocalNumber();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue