Search in sources :

Example 1 with IdentityRecordList

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

the class ConversationActivity method initializeIdentityRecords.

private ListenableFuture<Boolean> initializeIdentityRecords() {
    final SettableFuture<Boolean> future = new SettableFuture<>();
    new AsyncTask<Recipient, Void, Pair<IdentityRecordList, String>>() {

        @Override
        @NonNull
        protected Pair<IdentityRecordList, String> doInBackground(Recipient... params) {
            IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(ConversationActivity.this);
            IdentityRecordList identityRecordList = new IdentityRecordList();
            List<Recipient> recipients = new LinkedList<>();
            if (params[0].isGroupRecipient()) {
                recipients.addAll(DatabaseFactory.getGroupDatabase(ConversationActivity.this).getGroupMembers(params[0].getAddress().toGroupString(), false));
            } else {
                recipients.add(params[0]);
            }
            for (Recipient recipient : recipients) {
                Log.w(TAG, "Loading identity for: " + recipient.getAddress());
                identityRecordList.add(identityDatabase.getIdentity(recipient.getAddress()));
            }
            String message = null;
            if (identityRecordList.isUnverified()) {
                message = IdentityUtil.getUnverifiedBannerDescription(ConversationActivity.this, identityRecordList.getUnverifiedRecipients(ConversationActivity.this));
            }
            return new Pair<>(identityRecordList, message);
        }

        @Override
        protected void onPostExecute(@NonNull Pair<IdentityRecordList, String> result) {
            Log.w(TAG, "Got identity records: " + result.first.isUnverified());
            identityRecords.replaceWith(result.first);
            if (result.second != null) {
                Log.w(TAG, "Replacing banner...");
                unverifiedBannerView.get().display(result.second, result.first.getUnverifiedRecords(), new UnverifiedClickedListener(), new UnverifiedDismissedListener());
            } else if (unverifiedBannerView.resolved()) {
                Log.w(TAG, "Clearing banner...");
                unverifiedBannerView.get().hide();
            }
            titleView.setVerified(isSecureText && identityRecords.isVerified());
            future.set(true);
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, recipient);
    return future;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ByteString(com.google.protobuf.ByteString) IdentityDatabase(org.thoughtcrime.securesms.database.IdentityDatabase) IdentityRecordList(org.thoughtcrime.securesms.database.identity.IdentityRecordList) NonNull(android.support.annotation.NonNull) IdentityRecordList(org.thoughtcrime.securesms.database.identity.IdentityRecordList) List(java.util.List) LinkedList(java.util.LinkedList) Pair(android.util.Pair)

Example 2 with IdentityRecordList

use of org.thoughtcrime.securesms.database.identity.IdentityRecordList in project Signal-Android by WhisperSystems.

the class ConversationParentFragment method initializeIdentityRecords.

private ListenableFuture<Boolean> initializeIdentityRecords() {
    final SettableFuture<Boolean> future = new SettableFuture<>();
    final Context context = requireContext().getApplicationContext();
    if (SignalStore.account().getAci() == null || SignalStore.account().getPni() == null) {
        Log.w(TAG, "Not registered! Skipping initializeIdentityRecords()");
        future.set(false);
        return future;
    }
    new AsyncTask<Recipient, Void, Pair<IdentityRecordList, String>>() {

        @Override
        @NonNull
        protected Pair<IdentityRecordList, String> doInBackground(Recipient... params) {
            List<Recipient> recipients;
            if (params[0].isGroup()) {
                recipients = SignalDatabase.groups().getGroupMembers(params[0].requireGroupId(), GroupDatabase.MemberSet.FULL_MEMBERS_EXCLUDING_SELF);
            } else {
                recipients = Collections.singletonList(params[0]);
            }
            long startTime = System.currentTimeMillis();
            IdentityRecordList identityRecordList = ApplicationDependencies.getProtocolStore().aci().identities().getIdentityRecords(recipients);
            Log.i(TAG, String.format(Locale.US, "Loaded %d identities in %d ms", recipients.size(), System.currentTimeMillis() - startTime));
            String message = null;
            if (identityRecordList.isUnverified()) {
                message = IdentityUtil.getUnverifiedBannerDescription(context, identityRecordList.getUnverifiedRecipients());
            }
            return new Pair<>(identityRecordList, message);
        }

        @Override
        protected void onPostExecute(@NonNull Pair<IdentityRecordList, String> result) {
            Log.i(TAG, "Got identity records: " + result.first().isUnverified());
            identityRecords = result.first();
            if (result.second() != null) {
                Log.d(TAG, "Replacing banner...");
                unverifiedBannerView.get().display(result.second(), result.first().getUnverifiedRecords(), new UnverifiedClickedListener(), new UnverifiedDismissedListener());
            } else if (unverifiedBannerView.resolved()) {
                Log.d(TAG, "Clearing banner...");
                unverifiedBannerView.get().hide();
            }
            titleView.setVerified(isSecureText && identityRecords.isVerified());
            future.set(true);
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, recipient.get());
    return future;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) Context(android.content.Context) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SpannableString(android.text.SpannableString) IdentityRecordList(org.thoughtcrime.securesms.database.identity.IdentityRecordList) NonNull(androidx.annotation.NonNull) ArrayList(java.util.ArrayList) IdentityRecordList(org.thoughtcrime.securesms.database.identity.IdentityRecordList) List(java.util.List) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Pair(org.whispersystems.libsignal.util.Pair)

Example 3 with IdentityRecordList

use of org.thoughtcrime.securesms.database.identity.IdentityRecordList in project Signal-Android by WhisperSystems.

the class SignalBaseIdentityKeyStore method getIdentityRecords.

@NonNull
public IdentityRecordList getIdentityRecords(@NonNull List<Recipient> recipients) {
    List<String> addressNames = recipients.stream().filter(Recipient::hasServiceId).map(Recipient::requireServiceId).map(ServiceId::toString).collect(Collectors.toList());
    if (addressNames.isEmpty()) {
        return IdentityRecordList.EMPTY;
    }
    List<IdentityRecord> records = new ArrayList<>(recipients.size());
    for (Recipient recipient : recipients) {
        if (recipient.hasServiceId()) {
            IdentityStoreRecord record = cache.get(recipient.requireServiceId().toString());
            if (record != null) {
                records.add(record.toIdentityRecord(recipient.getId()));
            }
        } else {
            Log.w(TAG, "[getIdentityRecords] No serviceId for " + recipient.getId());
        }
    }
    return new IdentityRecordList(records);
}
Also used : IdentityRecordList(org.thoughtcrime.securesms.database.identity.IdentityRecordList) ArrayList(java.util.ArrayList) IdentityRecord(org.thoughtcrime.securesms.database.model.IdentityRecord) Recipient(org.thoughtcrime.securesms.recipients.Recipient) IdentityStoreRecord(org.thoughtcrime.securesms.database.model.IdentityStoreRecord) NonNull(androidx.annotation.NonNull)

Example 4 with IdentityRecordList

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

the class SignalBaseIdentityKeyStore method getIdentityRecords.

@NonNull
public IdentityRecordList getIdentityRecords(@NonNull List<Recipient> recipients) {
    List<String> addressNames = recipients.stream().filter(Recipient::hasServiceId).map(Recipient::requireServiceId).map(ServiceId::toString).collect(Collectors.toList());
    if (addressNames.isEmpty()) {
        return IdentityRecordList.EMPTY;
    }
    List<IdentityRecord> records = new ArrayList<>(recipients.size());
    for (Recipient recipient : recipients) {
        if (recipient.hasServiceId()) {
            IdentityStoreRecord record = cache.get(recipient.requireServiceId().toString());
            if (record != null) {
                records.add(record.toIdentityRecord(recipient.getId()));
            }
        } else {
            Log.w(TAG, "[getIdentityRecords] No serviceId for " + recipient.getId());
        }
    }
    return new IdentityRecordList(records);
}
Also used : IdentityRecordList(org.thoughtcrime.securesms.database.identity.IdentityRecordList) ArrayList(java.util.ArrayList) IdentityRecord(org.thoughtcrime.securesms.database.model.IdentityRecord) Recipient(org.thoughtcrime.securesms.recipients.Recipient) IdentityStoreRecord(org.thoughtcrime.securesms.database.model.IdentityStoreRecord) NonNull(androidx.annotation.NonNull)

Example 5 with IdentityRecordList

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

the class ConversationParentFragment method initializeIdentityRecords.

private ListenableFuture<Boolean> initializeIdentityRecords() {
    final SettableFuture<Boolean> future = new SettableFuture<>();
    final Context context = requireContext().getApplicationContext();
    if (SignalStore.account().getAci() == null || SignalStore.account().getPni() == null) {
        Log.w(TAG, "Not registered! Skipping initializeIdentityRecords()");
        future.set(false);
        return future;
    }
    new AsyncTask<Recipient, Void, Pair<IdentityRecordList, String>>() {

        @Override
        @NonNull
        protected Pair<IdentityRecordList, String> doInBackground(Recipient... params) {
            List<Recipient> recipients;
            if (params[0].isGroup()) {
                recipients = SignalDatabase.groups().getGroupMembers(params[0].requireGroupId(), GroupDatabase.MemberSet.FULL_MEMBERS_EXCLUDING_SELF);
            } else {
                recipients = Collections.singletonList(params[0]);
            }
            long startTime = System.currentTimeMillis();
            IdentityRecordList identityRecordList = ApplicationDependencies.getProtocolStore().aci().identities().getIdentityRecords(recipients);
            Log.i(TAG, String.format(Locale.US, "Loaded %d identities in %d ms", recipients.size(), System.currentTimeMillis() - startTime));
            String message = null;
            if (identityRecordList.isUnverified()) {
                message = IdentityUtil.getUnverifiedBannerDescription(context, identityRecordList.getUnverifiedRecipients());
            }
            return new Pair<>(identityRecordList, message);
        }

        @Override
        protected void onPostExecute(@NonNull Pair<IdentityRecordList, String> result) {
            Log.i(TAG, "Got identity records: " + result.first().isUnverified());
            identityRecords = result.first();
            if (result.second() != null) {
                Log.d(TAG, "Replacing banner...");
                unverifiedBannerView.get().display(result.second(), result.first().getUnverifiedRecords(), new UnverifiedClickedListener(), new UnverifiedDismissedListener());
            } else if (unverifiedBannerView.resolved()) {
                Log.d(TAG, "Clearing banner...");
                unverifiedBannerView.get().hide();
            }
            titleView.setVerified(isSecureText && identityRecords.isVerified());
            future.set(true);
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, recipient.get());
    return future;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) Context(android.content.Context) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SpannableString(android.text.SpannableString) IdentityRecordList(org.thoughtcrime.securesms.database.identity.IdentityRecordList) NonNull(androidx.annotation.NonNull) ArrayList(java.util.ArrayList) IdentityRecordList(org.thoughtcrime.securesms.database.identity.IdentityRecordList) List(java.util.List) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Pair(org.whispersystems.libsignal.util.Pair)

Aggregations

IdentityRecordList (org.thoughtcrime.securesms.database.identity.IdentityRecordList)5 Recipient (org.thoughtcrime.securesms.recipients.Recipient)5 NonNull (androidx.annotation.NonNull)4 ArrayList (java.util.ArrayList)4 List (java.util.List)3 SettableFuture (org.thoughtcrime.securesms.util.concurrent.SettableFuture)3 Context (android.content.Context)2 SpannableString (android.text.SpannableString)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 IdentityRecord (org.thoughtcrime.securesms.database.model.IdentityRecord)2 IdentityStoreRecord (org.thoughtcrime.securesms.database.model.IdentityStoreRecord)2 LiveRecipient (org.thoughtcrime.securesms.recipients.LiveRecipient)2 Pair (org.whispersystems.libsignal.util.Pair)2 NonNull (android.support.annotation.NonNull)1 Pair (android.util.Pair)1 ByteString (com.google.protobuf.ByteString)1 LinkedList (java.util.LinkedList)1 IdentityDatabase (org.thoughtcrime.securesms.database.IdentityDatabase)1