Search in sources :

Example 36 with RecipientDatabase

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());
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase)

Example 37 with RecipientDatabase

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);
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) Recipient(org.thoughtcrime.securesms.recipients.Recipient) WorkerThread(androidx.annotation.WorkerThread) TargetApi(android.annotation.TargetApi)

Example 38 with RecipientDatabase

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);
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) ACI(org.whispersystems.signalservice.api.push.ACI) SignalServiceAccountManager(org.whispersystems.signalservice.api.SignalServiceAccountManager) PNI(org.whispersystems.signalservice.api.push.PNI) SignalServiceAccountDataStoreImpl(org.thoughtcrime.securesms.crypto.storage.SignalServiceAccountDataStoreImpl) WorkerThread(androidx.annotation.WorkerThread)

Example 39 with RecipientDatabase

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<>();
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) Address(org.thoughtcrime.securesms.database.Address) ContactTokenDetails(org.whispersystems.signalservice.api.push.ContactTokenDetails) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) NonNull(android.support.annotation.NonNull)

Example 40 with RecipientDatabase

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;
    }
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) MultiDeviceContactUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob) SignalServiceAccountManager(org.whispersystems.signalservice.api.SignalServiceAccountManager) ContactTokenDetails(org.whispersystems.signalservice.api.push.ContactTokenDetails)

Aggregations

RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)72 Recipient (org.thoughtcrime.securesms.recipients.Recipient)32 WorkerThread (androidx.annotation.WorkerThread)30 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)20 NonNull (androidx.annotation.NonNull)18 IOException (java.io.IOException)14 Nullable (androidx.annotation.Nullable)10 ArrayList (java.util.ArrayList)10 Log (org.signal.core.util.logging.Log)10 SignalDatabase (org.thoughtcrime.securesms.database.SignalDatabase)10 ACI (org.whispersystems.signalservice.api.push.ACI)10 Context (android.content.Context)8 Stream (com.annimon.stream.Stream)8 Collections (java.util.Collections)8 List (java.util.List)8 TimeUnit (java.util.concurrent.TimeUnit)8 ProfileKey (org.signal.zkgroup.profiles.ProfileKey)8 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)8 Optional (org.whispersystems.libsignal.util.guava.Optional)8 HashSet (java.util.HashSet)7