Search in sources :

Example 6 with RegisteredState

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

the class RecipientDetails method forIndividual.

@NonNull
public static RecipientDetails forIndividual(@NonNull Context context, @NonNull RecipientRecord settings) {
    boolean systemContact = !settings.getSystemProfileName().isEmpty();
    boolean isSelf = (settings.getE164() != null && settings.getE164().equals(SignalStore.account().getE164())) || (settings.getServiceId() != null && settings.getServiceId().equals(SignalStore.account().getAci()));
    boolean isReleaseChannel = settings.getId().equals(SignalStore.releaseChannelValues().getReleaseChannelRecipientId());
    RegisteredState registeredState = settings.getRegistered();
    if (isSelf) {
        if (SignalStore.account().isRegistered() && !TextSecurePreferences.isUnauthorizedRecieved(context)) {
            registeredState = RegisteredState.REGISTERED;
        } else {
            registeredState = RegisteredState.NOT_REGISTERED;
        }
    }
    return new RecipientDetails(null, settings.getSystemDisplayName(), Optional.absent(), systemContact, isSelf, registeredState, settings, null, isReleaseChannel);
}
Also used : RegisteredState(org.thoughtcrime.securesms.database.RecipientDatabase.RegisteredState) NonNull(androidx.annotation.NonNull)

Example 7 with RegisteredState

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

the class ConversationParentFragment method initializeSecurity.

private ListenableFuture<Boolean> initializeSecurity(final boolean currentSecureText, final boolean currentIsDefaultSms) {
    final SettableFuture<Boolean> future = new SettableFuture<>();
    final Context context = requireContext().getApplicationContext();
    handleSecurityChange(currentSecureText || isPushGroupConversation(), currentIsDefaultSms);
    new AsyncTask<Recipient, Void, boolean[]>() {

        @Override
        protected boolean[] doInBackground(Recipient... params) {
            Recipient recipient = params[0].resolve();
            Log.i(TAG, "Resolving registered state...");
            RegisteredState registeredState;
            if (recipient.isPushGroup()) {
                Log.i(TAG, "Push group recipient...");
                registeredState = RegisteredState.REGISTERED;
            } else {
                Log.i(TAG, "Checking through resolved recipient");
                registeredState = recipient.resolve().getRegistered();
            }
            Log.i(TAG, "Resolved registered state: " + registeredState);
            boolean signalEnabled = Recipient.self().isRegistered();
            if (registeredState == RegisteredState.UNKNOWN) {
                try {
                    Log.i(TAG, "Refreshing directory for user: " + recipient.getId().serialize());
                    registeredState = DirectoryHelper.refreshDirectoryFor(context, recipient, false);
                } catch (IOException e) {
                    Log.w(TAG, e);
                }
            }
            Log.i(TAG, "Returning registered state...");
            return new boolean[] { registeredState == RegisteredState.REGISTERED && signalEnabled, Util.isDefaultSmsProvider(context) };
        }

        @Override
        protected void onPostExecute(boolean[] result) {
            if (result[0] != currentSecureText || result[1] != currentIsDefaultSms) {
                Log.i(TAG, "onPostExecute() handleSecurityChange: " + result[0] + " , " + result[1]);
                handleSecurityChange(result[0], result[1]);
            }
            future.set(true);
            onSecurityUpdated();
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, recipient.get());
    return future;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) Context(android.content.Context) RegisteredState(org.thoughtcrime.securesms.database.RecipientDatabase.RegisteredState) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) Recipient(org.thoughtcrime.securesms.recipients.Recipient) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 8 with RegisteredState

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

the class RecipientUtil method toSignalServiceAddress.

/**
 * This method will do it's best to craft a fully-populated {@link SignalServiceAddress} based on
 * the provided recipient. This includes performing a possible network request if no UUID is
 * available. If the request to get a UUID fails or the user is not registered, an IOException is thrown.
 */
@WorkerThread
@NonNull
public static SignalServiceAddress toSignalServiceAddress(@NonNull Context context, @NonNull Recipient recipient) throws IOException {
    recipient = recipient.resolve();
    if (!recipient.getServiceId().isPresent() && !recipient.getE164().isPresent()) {
        throw new AssertionError(recipient.getId() + " - No UUID or phone number!");
    }
    if (!recipient.getServiceId().isPresent()) {
        Log.i(TAG, recipient.getId() + " is missing a UUID...");
        RegisteredState state = DirectoryHelper.refreshDirectoryFor(context, recipient, false);
        recipient = Recipient.resolved(recipient.getId());
        Log.i(TAG, "Successfully performed a UUID fetch for " + recipient.getId() + ". Registered: " + state);
    }
    if (recipient.hasServiceId()) {
        return new SignalServiceAddress(recipient.requireServiceId(), Optional.fromNullable(recipient.resolve().getE164().orNull()));
    } else {
        throw new NotFoundException(recipient.getId() + " is not registered!");
    }
}
Also used : RegisteredState(org.thoughtcrime.securesms.database.RecipientDatabase.RegisteredState) NotFoundException(org.whispersystems.signalservice.api.push.exceptions.NotFoundException) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Aggregations

RegisteredState (org.thoughtcrime.securesms.database.RecipientDatabase.RegisteredState)8 NonNull (androidx.annotation.NonNull)4 WorkerThread (androidx.annotation.WorkerThread)4 Context (android.content.Context)2 IOException (java.io.IOException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)2 MultiDeviceContactUpdateJob (org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob)2 StorageSyncJob (org.thoughtcrime.securesms.jobs.StorageSyncJob)2 LiveRecipient (org.thoughtcrime.securesms.recipients.LiveRecipient)2 Recipient (org.thoughtcrime.securesms.recipients.Recipient)2 Stopwatch (org.thoughtcrime.securesms.util.Stopwatch)2 SettableFuture (org.thoughtcrime.securesms.util.concurrent.SettableFuture)2 ACI (org.whispersystems.signalservice.api.push.ACI)2 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)2 NotFoundException (org.whispersystems.signalservice.api.push.exceptions.NotFoundException)2