use of org.thoughtcrime.securesms.database.RecipientDatabase in project Signal-Android by signalapp.
the class InviteReminderRepository method setHasSeenSecondInviteReminder.
@Override
public void setHasSeenSecondInviteReminder(Recipient recipient) {
RecipientDatabase recipientDatabase = SignalDatabase.recipients();
recipientDatabase.setSeenSecondInviteReminder(recipient.getId());
}
use of org.thoughtcrime.securesms.database.RecipientDatabase in project Signal-Android by signalapp.
the class NotificationChannels method updateAllRecipientChannelLedColors.
@WorkerThread
@TargetApi(26)
private static void updateAllRecipientChannelLedColors(@NonNull Context context, @NonNull NotificationManager notificationManager, @NonNull String color) {
RecipientDatabase database = SignalDatabase.recipients();
try (RecipientDatabase.RecipientReader recipients = database.getRecipientsWithNotificationChannels()) {
Recipient recipient;
while ((recipient = recipients.getNext()) != null) {
assert recipient.getNotificationChannel() != null;
String newChannelId = generateChannelIdFor(recipient);
boolean success = updateExistingChannel(notificationManager, recipient.getNotificationChannel(), newChannelId, channel -> setLedPreference(channel, color));
database.setNotificationChannel(recipient.getId(), success ? newChannelId : null);
}
}
ensureCustomChannelConsistency(context);
}
use of org.thoughtcrime.securesms.database.RecipientDatabase in project Signal-Android by signalapp.
the class RegistrationRepository method registerAccountInternal.
@WorkerThread
private void registerAccountInternal(@NonNull RegistrationData registrationData, @NonNull VerifyAccountResponse response, @Nullable String pin, @Nullable KbsPinData kbsData) throws IOException {
ACI aci = ACI.parseOrThrow(response.getUuid());
PNI pni = PNI.parseOrThrow(response.getPni());
boolean hasPin = response.isStorageCapable();
SignalStore.account().setAci(aci);
SignalStore.account().setPni(pni);
ApplicationDependencies.getProtocolStore().aci().sessions().archiveAllSessions();
ApplicationDependencies.getProtocolStore().pni().sessions().archiveAllSessions();
SenderKeyUtil.clearAllState(context);
SignalServiceAccountManager accountManager = AccountManagerFactory.createAuthenticated(context, aci, pni, registrationData.getE164(), SignalServiceAddress.DEFAULT_DEVICE_ID, registrationData.getPassword());
SignalServiceAccountDataStoreImpl aciProtocolStore = ApplicationDependencies.getProtocolStore().aci();
SignalServiceAccountDataStoreImpl pniProtocolStore = ApplicationDependencies.getProtocolStore().pni();
generateAndRegisterPreKeys(ServiceIdType.ACI, accountManager, aciProtocolStore, SignalStore.account().aciPreKeys());
generateAndRegisterPreKeys(ServiceIdType.PNI, accountManager, pniProtocolStore, SignalStore.account().pniPreKeys());
if (registrationData.isFcm()) {
accountManager.setGcmId(Optional.fromNullable(registrationData.getFcmToken()));
}
RecipientDatabase recipientDatabase = SignalDatabase.recipients();
RecipientId selfId = Recipient.externalPush(aci, registrationData.getE164(), true).getId();
recipientDatabase.setProfileSharing(selfId, true);
recipientDatabase.markRegisteredOrThrow(selfId, aci);
recipientDatabase.setPni(selfId, pni);
recipientDatabase.setProfileKey(selfId, registrationData.getProfileKey());
ApplicationDependencies.getRecipientCache().clearSelf();
SignalStore.account().setE164(registrationData.getE164());
SignalStore.account().setFcmToken(registrationData.getFcmToken());
SignalStore.account().setFcmEnabled(registrationData.isFcm());
long now = System.currentTimeMillis();
saveOwnIdentityKey(selfId, aciProtocolStore, now);
saveOwnIdentityKey(selfId, pniProtocolStore, now);
SignalStore.account().setServicePassword(registrationData.getPassword());
SignalStore.account().setRegistered(true);
TextSecurePreferences.setPromptedPushRegistration(context, true);
TextSecurePreferences.setUnauthorizedReceived(context, false);
PinState.onRegistration(context, kbsData, pin, hasPin);
}
use of org.thoughtcrime.securesms.database.RecipientDatabase in project Signal-Android by signalapp.
the class DirectoryHelper method refreshDirectory.
@NonNull
private static List<Address> refreshDirectory(@NonNull Context context, @NonNull SignalServiceAccountManager accountManager) throws IOException {
if (TextUtils.isEmpty(TextSecurePreferences.getLocalNumber(context))) {
return new LinkedList<>();
}
if (!Permissions.hasAll(context, Manifest.permission.WRITE_CONTACTS)) {
return new LinkedList<>();
}
RecipientDatabase recipientDatabase = DatabaseFactory.getRecipientDatabase(context);
Stream<String> eligibleRecipientDatabaseContactNumbers = Stream.of(recipientDatabase.getAllAddresses()).filter(Address::isPhone).map(Address::toPhoneString);
Stream<String> eligibleSystemDatabaseContactNumbers = Stream.of(ContactAccessor.getInstance().getAllContactsWithNumbers(context)).map(Address::serialize);
Set<String> eligibleContactNumbers = Stream.concat(eligibleRecipientDatabaseContactNumbers, eligibleSystemDatabaseContactNumbers).collect(Collectors.toSet());
List<ContactTokenDetails> activeTokens = accountManager.getContacts(eligibleContactNumbers);
if (activeTokens != null) {
List<Address> activeAddresses = new LinkedList<>();
List<Address> inactiveAddresses = new LinkedList<>();
Set<String> inactiveContactNumbers = new HashSet<>(eligibleContactNumbers);
for (ContactTokenDetails activeToken : activeTokens) {
activeAddresses.add(Address.fromSerialized(activeToken.getNumber()));
inactiveContactNumbers.remove(activeToken.getNumber());
}
for (String inactiveContactNumber : inactiveContactNumbers) {
inactiveAddresses.add(Address.fromSerialized(inactiveContactNumber));
}
Set<Address> currentActiveAddresses = new HashSet<>(recipientDatabase.getRegistered());
Set<Address> contactAddresses = new HashSet<>(recipientDatabase.getSystemContacts());
List<Address> newlyActiveAddresses = Stream.of(activeAddresses).filter(address -> !currentActiveAddresses.contains(address)).filter(contactAddresses::contains).toList();
recipientDatabase.setRegistered(activeAddresses, inactiveAddresses);
updateContactsDatabase(context, activeAddresses, true);
if (TextSecurePreferences.hasSuccessfullyRetrievedDirectory(context)) {
return newlyActiveAddresses;
} else {
TextSecurePreferences.setHasSuccessfullyRetrievedDirectory(context, true);
return new LinkedList<>();
}
}
return new LinkedList<>();
}
use of org.thoughtcrime.securesms.database.RecipientDatabase in project Signal-Android by signalapp.
the class DirectoryHelper method refreshDirectoryFor.
public static RegisteredState refreshDirectoryFor(@NonNull Context context, @NonNull Recipient recipient) throws IOException {
RecipientDatabase recipientDatabase = DatabaseFactory.getRecipientDatabase(context);
SignalServiceAccountManager accountManager = AccountManagerFactory.createManager(context);
boolean activeUser = recipient.resolve().getRegistered() == RegisteredState.REGISTERED;
boolean systemContact = recipient.isSystemContact();
String number = recipient.getAddress().serialize();
Optional<ContactTokenDetails> details = accountManager.getContact(number);
if (details.isPresent()) {
recipientDatabase.setRegistered(recipient, RegisteredState.REGISTERED);
if (Permissions.hasAll(context, Manifest.permission.WRITE_CONTACTS)) {
updateContactsDatabase(context, Util.asList(recipient.getAddress()), false);
}
if (!activeUser && TextSecurePreferences.isMultiDevice(context)) {
ApplicationContext.getInstance(context).getJobManager().add(new MultiDeviceContactUpdateJob(context));
}
if (!activeUser && systemContact) {
notifyNewUsers(context, Collections.singletonList(recipient.getAddress()));
}
return RegisteredState.REGISTERED;
} else {
recipientDatabase.setRegistered(recipient, RegisteredState.NOT_REGISTERED);
return RegisteredState.NOT_REGISTERED;
}
}
Aggregations