mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-08 20:08:35 +00:00
Allow auto-downloads from groups you've accepted.
This commit is contained in:
parent
5bf15b0587
commit
dadb2f9d37
@ -13,8 +13,10 @@ import android.text.TextUtils;
|
|||||||
import org.thoughtcrime.securesms.attachments.AttachmentId;
|
import org.thoughtcrime.securesms.attachments.AttachmentId;
|
||||||
import org.thoughtcrime.securesms.attachments.DatabaseAttachment;
|
import org.thoughtcrime.securesms.attachments.DatabaseAttachment;
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
|
import org.thoughtcrime.securesms.database.NoSuchMessageException;
|
||||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||||
import org.thoughtcrime.securesms.logging.Log;
|
import org.thoughtcrime.securesms.logging.Log;
|
||||||
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -30,7 +32,7 @@ public class AttachmentUtil {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFromUnknownContact(context, attachment)) {
|
if (!isFromTrustedConversation(context, attachment)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,18 +107,28 @@ public class AttachmentUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
private static boolean isFromUnknownContact(@NonNull Context context, @NonNull DatabaseAttachment attachment) {
|
private static boolean isFromTrustedConversation(@NonNull Context context, @NonNull DatabaseAttachment attachment) {
|
||||||
try (Cursor messageCursor = DatabaseFactory.getMmsDatabase(context).getMessage(attachment.getMmsId())) {
|
try {
|
||||||
final MessageRecord message = DatabaseFactory.getMmsDatabase(context).readerFor(messageCursor).getNext();
|
MessageRecord message = DatabaseFactory.getMmsDatabase(context).getMessageRecord(attachment.getMmsId());
|
||||||
|
|
||||||
if (message == null || (!message.getRecipient().isSystemContact() &&
|
Recipient individualRecipient = message.getRecipient();
|
||||||
!message.getRecipient().isProfileSharing() &&
|
Recipient threadRecipient = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(message.getThreadId());
|
||||||
!message.isOutgoing() &&
|
|
||||||
!message.getRecipient().isLocalNumber())) {
|
if (threadRecipient != null && threadRecipient.isGroup()) {
|
||||||
return true;
|
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…
x
Reference in New Issue
Block a user