Search in sources :

Example 1 with RecipientReader

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

the class MultiDeviceBlockedUpdateJob method onRun.

@Override
public void onRun() throws IOException, UntrustedIdentityException {
    if (!Recipient.self().isRegistered()) {
        throw new NotPushRegisteredException();
    }
    if (!TextSecurePreferences.isMultiDevice(context)) {
        Log.i(TAG, "Not multi device, aborting...");
        return;
    }
    RecipientDatabase database = SignalDatabase.recipients();
    try (RecipientReader reader = database.readerForBlocked(database.getBlocked())) {
        List<SignalServiceAddress> blockedIndividuals = new LinkedList<>();
        List<byte[]> blockedGroups = new LinkedList<>();
        Recipient recipient;
        while ((recipient = reader.getNext()) != null) {
            if (recipient.isPushGroup()) {
                blockedGroups.add(recipient.requireGroupId().getDecodedId());
            } else if (recipient.isMaybeRegistered() && (recipient.hasServiceId() || recipient.hasE164())) {
                blockedIndividuals.add(RecipientUtil.toSignalServiceAddress(context, recipient));
            }
        }
        SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
        messageSender.sendSyncMessage(SignalServiceSyncMessage.forBlocked(new BlockedListMessage(blockedIndividuals, blockedGroups)), UnidentifiedAccessUtil.getAccessForSync(context));
    }
}
Also used : RecipientReader(org.thoughtcrime.securesms.database.RecipientDatabase.RecipientReader) RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) Recipient(org.thoughtcrime.securesms.recipients.Recipient) BlockedListMessage(org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)1 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)1 RecipientReader (org.thoughtcrime.securesms.database.RecipientDatabase.RecipientReader)1 NotPushRegisteredException (org.thoughtcrime.securesms.net.NotPushRegisteredException)1 Recipient (org.thoughtcrime.securesms.recipients.Recipient)1 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)1 BlockedListMessage (org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage)1 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)1