Search in sources :

Example 1 with BlockedReader

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

the class MultiDeviceBlockedUpdateJob method onRun.

@Override
public void onRun(MasterSecret masterSecret) throws IOException, UntrustedIdentityException {
    RecipientPreferenceDatabase database = DatabaseFactory.getRecipientPreferenceDatabase(context);
    SignalServiceMessageSender messageSender = messageSenderFactory.create();
    BlockedReader reader = database.readerForBlocked(database.getBlocked());
    List<String> blocked = new LinkedList<>();
    Recipients recipients;
    while ((recipients = reader.getNext()) != null) {
        if (recipients.isSingleRecipient()) {
            try {
                blocked.add(Util.canonicalizeNumber(context, recipients.getPrimaryRecipient().getNumber()));
            } catch (InvalidNumberException e) {
                Log.w(TAG, e);
            }
        }
    }
    messageSender.sendMessage(SignalServiceSyncMessage.forBlocked(new BlockedListMessage(blocked)));
}
Also used : RecipientPreferenceDatabase(org.thoughtcrime.securesms.database.RecipientPreferenceDatabase) Recipients(org.thoughtcrime.securesms.recipients.Recipients) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) BlockedReader(org.thoughtcrime.securesms.database.RecipientPreferenceDatabase.BlockedReader) BlockedListMessage(org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)1 RecipientPreferenceDatabase (org.thoughtcrime.securesms.database.RecipientPreferenceDatabase)1 BlockedReader (org.thoughtcrime.securesms.database.RecipientPreferenceDatabase.BlockedReader)1 Recipients (org.thoughtcrime.securesms.recipients.Recipients)1 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)1 BlockedListMessage (org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage)1 InvalidNumberException (org.whispersystems.signalservice.api.util.InvalidNumberException)1