Search in sources :

Example 1 with DeviceGroup

use of org.whispersystems.signalservice.api.messages.multidevice.DeviceGroup 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 2 with DeviceGroup

use of org.whispersystems.signalservice.api.messages.multidevice.DeviceGroup in project Signal-Android by signalapp.

the class MultiDeviceGroupUpdateJob method onRun.

@Override
public void onRun(MasterSecret masterSecret) throws Exception {
    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) {
            if (!record.isMms()) {
                List<String> members = new LinkedList<>();
                for (Address member : record.getMembers()) {
                    members.add(member.serialize());
                }
                Recipient recipient = Recipient.from(context, Address.fromSerialized(GroupUtil.getEncodedId(record.getId(), record.isMms())), false);
                Optional<Integer> expirationTimer = recipient.getExpireMessages() > 0 ? Optional.of(recipient.getExpireMessages()) : Optional.absent();
                out.write(new DeviceGroup(record.getId(), Optional.fromNullable(record.getTitle()), members, getAvatar(record.getAvatar()), record.isActive(), expirationTimer));
            }
        }
        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 : Address(org.thoughtcrime.securesms.database.Address) DeviceGroup(org.whispersystems.signalservice.api.messages.multidevice.DeviceGroup) Recipient(org.thoughtcrime.securesms.recipients.Recipient) LinkedList(java.util.LinkedList) FileOutputStream(java.io.FileOutputStream) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) File(java.io.File) DeviceGroupsOutputStream(org.whispersystems.signalservice.api.messages.multidevice.DeviceGroupsOutputStream)

Aggregations

File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)2 DeviceGroup (org.whispersystems.signalservice.api.messages.multidevice.DeviceGroup)2 DeviceGroupsOutputStream (org.whispersystems.signalservice.api.messages.multidevice.DeviceGroupsOutputStream)2 LinkedList (java.util.LinkedList)1 Address (org.thoughtcrime.securesms.database.Address)1 Recipient (org.thoughtcrime.securesms.recipients.Recipient)1 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)1