use of org.whispersystems.signalservice.api.SignalServiceMessageSender 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)));
}
use of org.whispersystems.signalservice.api.SignalServiceMessageSender in project Signal-Android by WhisperSystems.
the class MultiDeviceContactUpdateJob method generateSingleContactUpdate.
private void generateSingleContactUpdate(long recipientId) throws IOException, UntrustedIdentityException, NetworkException {
SignalServiceMessageSender messageSender = messageSenderFactory.create();
File contactDataFile = createTempFile("multidevice-contact-update");
try {
DeviceContactsOutputStream out = new DeviceContactsOutputStream(new FileOutputStream(contactDataFile));
Recipient recipient = RecipientFactory.getRecipientForId(context, recipientId, false);
out.write(new DeviceContact(Util.canonicalizeNumber(context, recipient.getNumber()), Optional.fromNullable(recipient.getName()), getAvatar(recipient.getContactUri()), Optional.fromNullable(recipient.getColor().serialize())));
out.close();
sendUpdate(messageSender, contactDataFile);
} catch (InvalidNumberException e) {
Log.w(TAG, e);
} finally {
if (contactDataFile != null)
contactDataFile.delete();
}
}
use of org.whispersystems.signalservice.api.SignalServiceMessageSender in project Signal-Android by WhisperSystems.
the class MultiDeviceContactUpdateJob method generateFullContactUpdate.
private void generateFullContactUpdate() throws IOException, UntrustedIdentityException, NetworkException {
SignalServiceMessageSender messageSender = messageSenderFactory.create();
File contactDataFile = createTempFile("multidevice-contact-update");
try {
DeviceContactsOutputStream out = new DeviceContactsOutputStream(new FileOutputStream(contactDataFile));
Collection<ContactData> contacts = ContactAccessor.getInstance().getContactsWithPush(context);
for (ContactData contactData : contacts) {
Uri contactUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactData.id));
String number = Util.canonicalizeNumber(context, contactData.numbers.get(0).number);
Optional<String> name = Optional.fromNullable(contactData.name);
Optional<String> color = getColor(number);
out.write(new DeviceContact(number, name, getAvatar(contactUri), color));
}
out.close();
sendUpdate(messageSender, contactDataFile);
} catch (InvalidNumberException e) {
Log.w(TAG, e);
} finally {
if (contactDataFile != null)
contactDataFile.delete();
}
}
use of org.whispersystems.signalservice.api.SignalServiceMessageSender in project Signal-Android by WhisperSystems.
the class MultiDeviceGroupUpdateJob method onRun.
@Override
public void onRun(MasterSecret masterSecret) throws Exception {
SignalServiceMessageSender messageSender = messageSenderFactory.create();
File contactDataFile = createTempFile("multidevice-contact-update");
GroupDatabase.Reader reader = null;
GroupDatabase.GroupRecord record;
try {
DeviceGroupsOutputStream out = new DeviceGroupsOutputStream(new FileOutputStream(contactDataFile));
reader = DatabaseFactory.getGroupDatabase(context).getGroups();
while ((record = reader.getNext()) != null) {
out.write(new DeviceGroup(record.getId(), Optional.fromNullable(record.getTitle()), record.getMembers(), getAvatar(record.getAvatar()), record.isActive()));
}
out.close();
if (contactDataFile.exists() && contactDataFile.length() > 0) {
sendUpdate(messageSender, contactDataFile);
} else {
Log.w(TAG, "No groups present for sync message...");
}
} finally {
if (contactDataFile != null)
contactDataFile.delete();
if (reader != null)
reader.close();
}
}
use of org.whispersystems.signalservice.api.SignalServiceMessageSender in project Signal-Android by WhisperSystems.
the class MultiDeviceReadUpdateJob method onRun.
@Override
public void onRun(MasterSecret masterSecret) throws IOException, UntrustedIdentityException {
if (!TextSecurePreferences.isMultiDevice(context)) {
Log.w(TAG, "Not multi device...");
return;
}
List<ReadMessage> readMessages = new LinkedList<>();
for (SerializableSyncMessageId messageId : messageIds) {
readMessages.add(new ReadMessage(messageId.sender, messageId.timestamp));
}
SignalServiceMessageSender messageSender = messageSenderFactory.create();
messageSender.sendMessage(SignalServiceSyncMessage.forRead(readMessages));
}
Aggregations