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());
}
}
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);
}
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;
}
}
Aggregations