Search in sources :

Example 71 with RecipientDatabase

use of org.thoughtcrime.securesms.database.RecipientDatabase in project Signal-Android by signalapp.

the class RetrieveProfileJob method setUnidentifiedAccessMode.

private void setUnidentifiedAccessMode(Recipient recipient, String unidentifiedAccessVerifier, boolean unrestrictedUnidentifiedAccess) {
    RecipientDatabase recipientDatabase = SignalDatabase.recipients();
    ProfileKey profileKey = ProfileKeyUtil.profileKeyOrNull(recipient.getProfileKey());
    if (unrestrictedUnidentifiedAccess && unidentifiedAccessVerifier != null) {
        if (recipient.getUnidentifiedAccessMode() != UnidentifiedAccessMode.UNRESTRICTED) {
            Log.i(TAG, "Marking recipient UD status as unrestricted.");
            recipientDatabase.setUnidentifiedAccessMode(recipient.getId(), UnidentifiedAccessMode.UNRESTRICTED);
        }
    } else if (profileKey == null || unidentifiedAccessVerifier == null) {
        if (recipient.getUnidentifiedAccessMode() != UnidentifiedAccessMode.DISABLED) {
            Log.i(TAG, "Marking recipient UD status as disabled.");
            recipientDatabase.setUnidentifiedAccessMode(recipient.getId(), UnidentifiedAccessMode.DISABLED);
        }
    } else {
        ProfileCipher profileCipher = new ProfileCipher(profileKey);
        boolean verifiedUnidentifiedAccess;
        try {
            verifiedUnidentifiedAccess = profileCipher.verifyUnidentifiedAccess(Base64.decode(unidentifiedAccessVerifier));
        } catch (IOException e) {
            Log.w(TAG, e);
            verifiedUnidentifiedAccess = false;
        }
        UnidentifiedAccessMode mode = verifiedUnidentifiedAccess ? UnidentifiedAccessMode.ENABLED : UnidentifiedAccessMode.DISABLED;
        if (recipient.getUnidentifiedAccessMode() != mode) {
            Log.i(TAG, "Marking recipient UD status as " + mode.name() + " after verification.");
            recipientDatabase.setUnidentifiedAccessMode(recipient.getId(), mode);
        }
    }
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) ProfileCipher(org.whispersystems.signalservice.api.crypto.ProfileCipher) IOException(java.io.IOException) UnidentifiedAccessMode(org.thoughtcrime.securesms.database.RecipientDatabase.UnidentifiedAccessMode) ProfileKey(org.signal.zkgroup.profiles.ProfileKey)

Example 72 with RecipientDatabase

use of org.thoughtcrime.securesms.database.RecipientDatabase in project Signal-Android by signalapp.

the class RefreshOwnProfileJob method setProfileKeyCredential.

private void setProfileKeyCredential(@NonNull Recipient recipient, @NonNull ProfileKey recipientProfileKey, @NonNull ProfileKeyCredential credential) {
    RecipientDatabase recipientDatabase = SignalDatabase.recipients();
    recipientDatabase.setProfileKeyCredential(recipient.getId(), recipientProfileKey, credential);
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase)

Aggregations

RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)72 Recipient (org.thoughtcrime.securesms.recipients.Recipient)32 WorkerThread (androidx.annotation.WorkerThread)30 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)20 NonNull (androidx.annotation.NonNull)18 IOException (java.io.IOException)14 Nullable (androidx.annotation.Nullable)10 ArrayList (java.util.ArrayList)10 Log (org.signal.core.util.logging.Log)10 SignalDatabase (org.thoughtcrime.securesms.database.SignalDatabase)10 ACI (org.whispersystems.signalservice.api.push.ACI)10 Context (android.content.Context)8 Stream (com.annimon.stream.Stream)8 Collections (java.util.Collections)8 List (java.util.List)8 TimeUnit (java.util.concurrent.TimeUnit)8 ProfileKey (org.signal.zkgroup.profiles.ProfileKey)8 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)8 Optional (org.whispersystems.libsignal.util.guava.Optional)8 HashSet (java.util.HashSet)7