Search in sources :

Example 1 with SignalServiceMessageSender

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

Example 2 with SignalServiceMessageSender

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();
    }
}
Also used : DeviceContact(org.whispersystems.signalservice.api.messages.multidevice.DeviceContact) DeviceContactsOutputStream(org.whispersystems.signalservice.api.messages.multidevice.DeviceContactsOutputStream) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) FileOutputStream(java.io.FileOutputStream) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) Recipient(org.thoughtcrime.securesms.recipients.Recipient) File(java.io.File)

Example 3 with SignalServiceMessageSender

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();
    }
}
Also used : DeviceContact(org.whispersystems.signalservice.api.messages.multidevice.DeviceContact) DeviceContactsOutputStream(org.whispersystems.signalservice.api.messages.multidevice.DeviceContactsOutputStream) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) FileOutputStream(java.io.FileOutputStream) ContactData(org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) File(java.io.File) Uri(android.net.Uri)

Example 4 with SignalServiceMessageSender

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();
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) DeviceGroup(org.whispersystems.signalservice.api.messages.multidevice.DeviceGroup) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) File(java.io.File) DeviceGroupsOutputStream(org.whispersystems.signalservice.api.messages.multidevice.DeviceGroupsOutputStream)

Example 5 with SignalServiceMessageSender

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));
}
Also used : ReadMessage(org.whispersystems.signalservice.api.messages.multidevice.ReadMessage) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) LinkedList(java.util.LinkedList)

Aggregations

SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)13 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)8 SignalServiceDataMessage (org.whispersystems.signalservice.api.messages.SignalServiceDataMessage)5 InvalidNumberException (org.whispersystems.signalservice.api.util.InvalidNumberException)5 File (java.io.File)3 FileOutputStream (java.io.FileOutputStream)3 IOException (java.io.IOException)3 SignalServiceAttachment (org.whispersystems.signalservice.api.messages.SignalServiceAttachment)3 SignalServiceGroup (org.whispersystems.signalservice.api.messages.SignalServiceGroup)3 ObjectGraph (dagger.ObjectGraph)2 LinkedList (java.util.LinkedList)2 Test (org.junit.Test)2 BaseUnitTest (org.thoughtcrime.securesms.BaseUnitTest)2 Attachment (org.thoughtcrime.securesms.attachments.Attachment)2 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)2 Recipients (org.thoughtcrime.securesms.recipients.Recipients)2 InsecureFallbackApprovalException (org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)2 RetryLaterException (org.thoughtcrime.securesms.transport.RetryLaterException)2 DeviceContact (org.whispersystems.signalservice.api.messages.multidevice.DeviceContact)2 DeviceContactsOutputStream (org.whispersystems.signalservice.api.messages.multidevice.DeviceContactsOutputStream)2