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