Reactively share profiles to those who should already have it.

This commit is contained in:
Greyson Parrelli
2021-05-06 10:07:23 -04:00
parent 7a02404f7b
commit 56ea11cdff
8 changed files with 122 additions and 21 deletions

View File

@@ -11,6 +11,7 @@ import com.annimon.stream.Stream;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.contacts.sync.DirectoryHelper;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.GroupDatabase;
import org.thoughtcrime.securesms.database.RecipientDatabase.RegisteredState;
import org.thoughtcrime.securesms.database.ThreadDatabase;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
@@ -265,6 +266,25 @@ public class RecipientUtil {
threadRecipient.isForceSmsSelection();
}
/**
* @return True if this recipient should already have your profile key, otherwise false.
*/
public static boolean shouldHaveProfileKey(@NonNull Context context, @NonNull Recipient recipient) {
if (recipient.isBlocked()) {
return false;
}
if (recipient.isProfileSharing()) {
return true;
} else {
GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context);
return groupDatabase.getPushGroupsContainingMember(recipient.getId())
.stream()
.anyMatch(GroupDatabase.GroupRecord::isV2Group);
}
}
@WorkerThread
private static boolean isMessageRequestAccepted(@NonNull Context context, long threadId, @NonNull Recipient threadRecipient) {
return threadRecipient.isSelf() ||