Search in sources :

Example 1 with TextSecureDirectory

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

the class PushReceivedJob method handle.

public void handle(SignalServiceEnvelope envelope, boolean sendExplicitReceipt) {
    if (!isActiveNumber(context, envelope.getSource())) {
        TextSecureDirectory directory = TextSecureDirectory.getInstance(context);
        ContactTokenDetails contactTokenDetails = new ContactTokenDetails();
        contactTokenDetails.setNumber(envelope.getSource());
        directory.setNumber(contactTokenDetails, true);
        Recipients recipients = RecipientFactory.getRecipientsFromString(context, envelope.getSource(), false);
        ApplicationContext.getInstance(context).getJobManager().add(new DirectoryRefreshJob(context, KeyCachingService.getMasterSecret(context), recipients));
    }
    if (envelope.isReceipt()) {
        handleReceipt(envelope);
    } else if (envelope.isPreKeySignalMessage() || envelope.isSignalMessage()) {
        handleMessage(envelope, sendExplicitReceipt);
    } else {
        Log.w(TAG, "Received envelope of unknown type: " + envelope.getType());
    }
}
Also used : Recipients(org.thoughtcrime.securesms.recipients.Recipients) ContactTokenDetails(org.whispersystems.signalservice.api.push.ContactTokenDetails) TextSecureDirectory(org.thoughtcrime.securesms.database.TextSecureDirectory)

Example 2 with TextSecureDirectory

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

the class DirectoryHelper method refreshDirectory.

@NonNull
public static RefreshResult refreshDirectory(@NonNull Context context, @NonNull SignalServiceAccountManager accountManager, @NonNull String localNumber) throws IOException {
    TextSecureDirectory directory = TextSecureDirectory.getInstance(context);
    Set<String> eligibleContactNumbers = directory.getPushEligibleContactNumbers(localNumber);
    List<ContactTokenDetails> activeTokens = accountManager.getContacts(eligibleContactNumbers);
    if (activeTokens != null) {
        for (ContactTokenDetails activeToken : activeTokens) {
            eligibleContactNumbers.remove(activeToken.getNumber());
            activeToken.setNumber(activeToken.getNumber());
        }
        directory.setNumbers(activeTokens, eligibleContactNumbers);
        return updateContactsDatabase(context, localNumber, activeTokens, true);
    }
    return new RefreshResult(new LinkedList<String>(), false);
}
Also used : ContactTokenDetails(org.whispersystems.signalservice.api.push.ContactTokenDetails) TextSecureDirectory(org.thoughtcrime.securesms.database.TextSecureDirectory) NonNull(android.support.annotation.NonNull)

Example 3 with TextSecureDirectory

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

the class DirectoryHelper method refreshDirectoryFor.

public static UserCapabilities refreshDirectoryFor(@NonNull Context context, @Nullable MasterSecret masterSecret, @NonNull Recipients recipients, @NonNull String localNumber) throws IOException {
    try {
        TextSecureDirectory directory = TextSecureDirectory.getInstance(context);
        SignalServiceAccountManager accountManager = AccountManagerFactory.createManager(context);
        String number = Util.canonicalizeNumber(context, recipients.getPrimaryRecipient().getNumber());
        Optional<ContactTokenDetails> details = accountManager.getContact(number);
        if (details.isPresent()) {
            directory.setNumber(details.get(), true);
            RefreshResult result = updateContactsDatabase(context, localNumber, details.get());
            if (!result.getNewUsers().isEmpty() && TextSecurePreferences.isMultiDevice(context)) {
                ApplicationContext.getInstance(context).getJobManager().add(new MultiDeviceContactUpdateJob(context));
            }
            if (!result.isFresh()) {
                notifyNewUsers(context, masterSecret, result.getNewUsers());
            }
            return new UserCapabilities(Capability.SUPPORTED, details.get().isVoice() ? Capability.SUPPORTED : Capability.UNSUPPORTED, details.get().isVideo() ? Capability.SUPPORTED : Capability.UNSUPPORTED);
        } else {
            ContactTokenDetails absent = new ContactTokenDetails();
            absent.setNumber(number);
            directory.setNumber(absent, false);
            return UserCapabilities.UNSUPPORTED;
        }
    } catch (InvalidNumberException e) {
        Log.w(TAG, e);
        return UserCapabilities.UNSUPPORTED;
    }
}
Also used : MultiDeviceContactUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) SignalServiceAccountManager(org.whispersystems.signalservice.api.SignalServiceAccountManager) ContactTokenDetails(org.whispersystems.signalservice.api.push.ContactTokenDetails) TextSecureDirectory(org.thoughtcrime.securesms.database.TextSecureDirectory)

Aggregations

TextSecureDirectory (org.thoughtcrime.securesms.database.TextSecureDirectory)3 ContactTokenDetails (org.whispersystems.signalservice.api.push.ContactTokenDetails)3 NonNull (android.support.annotation.NonNull)1 MultiDeviceContactUpdateJob (org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob)1 Recipients (org.thoughtcrime.securesms.recipients.Recipients)1 SignalServiceAccountManager (org.whispersystems.signalservice.api.SignalServiceAccountManager)1 InvalidNumberException (org.whispersystems.signalservice.api.util.InvalidNumberException)1