diff --git a/src/org/thoughtcrime/securesms/jobs/MultiDeviceContactUpdateJob.java b/src/org/thoughtcrime/securesms/jobs/MultiDeviceContactUpdateJob.java index 90b78b906d..23358a64bf 100644 --- a/src/org/thoughtcrime/securesms/jobs/MultiDeviceContactUpdateJob.java +++ b/src/org/thoughtcrime/securesms/jobs/MultiDeviceContactUpdateJob.java @@ -20,6 +20,7 @@ import org.whispersystems.jobqueue.requirements.NetworkRequirement; import org.whispersystems.libaxolotl.util.guava.Optional; import org.whispersystems.textsecure.api.TextSecureMessageSender; import org.whispersystems.textsecure.api.crypto.UntrustedIdentityException; +import org.whispersystems.textsecure.api.messages.TextSecureAttachment; import org.whispersystems.textsecure.api.messages.TextSecureAttachmentStream; import org.whispersystems.textsecure.api.messages.multidevice.DeviceContact; import org.whispersystems.textsecure.api.messages.multidevice.DeviceContactsOutputStream; @@ -101,10 +102,11 @@ public class MultiDeviceContactUpdateJob extends MasterSecretJob implements Inje throws IOException, UntrustedIdentityException, NetworkException { FileInputStream contactsFileStream = new FileInputStream(contactsFile); - TextSecureAttachmentStream attachmentStream = new TextSecureAttachmentStream(contactsFileStream, - "application/octet-stream", - contactsFile.length(), - null); + TextSecureAttachmentStream attachmentStream = TextSecureAttachment.newStreamBuilder() + .withStream(contactsFileStream) + .withContentType("application/octet-stream") + .withLength(contactsFile.length()) + .build(); try { messageSender.sendMessage(TextSecureSyncMessage.forContacts(attachmentStream)); @@ -118,7 +120,12 @@ public class MultiDeviceContactUpdateJob extends MasterSecretJob implements Inje try { Uri displayPhotoUri = Uri.withAppendedPath(uri, ContactsContract.Contacts.Photo.DISPLAY_PHOTO); AssetFileDescriptor fd = context.getContentResolver().openAssetFileDescriptor(displayPhotoUri, "r"); - return Optional.of(new TextSecureAttachmentStream(fd.createInputStream(), "image/*", fd.getLength(), null)); + + return Optional.of(TextSecureAttachment.newStreamBuilder() + .withStream(fd.createInputStream()) + .withContentType("image/*") + .withLength(fd.getLength()) + .build()); } catch (IOException e) { Log.w(TAG, e); } @@ -141,7 +148,11 @@ public class MultiDeviceContactUpdateJob extends MasterSecretJob implements Inje byte[] data = cursor.getBlob(0); if (data != null) { - return Optional.of(new TextSecureAttachmentStream(new ByteArrayInputStream(data), "image/*", data.length, null)); + return Optional.of(TextSecureAttachment.newStreamBuilder() + .withStream(new ByteArrayInputStream(data)) + .withContentType("image/*") + .withLength(data.length) + .build()); } } diff --git a/src/org/thoughtcrime/securesms/jobs/MultiDeviceGroupUpdateJob.java b/src/org/thoughtcrime/securesms/jobs/MultiDeviceGroupUpdateJob.java index 5fdaf13f92..60c937f4fe 100644 --- a/src/org/thoughtcrime/securesms/jobs/MultiDeviceGroupUpdateJob.java +++ b/src/org/thoughtcrime/securesms/jobs/MultiDeviceGroupUpdateJob.java @@ -14,6 +14,7 @@ import org.whispersystems.jobqueue.requirements.NetworkRequirement; import org.whispersystems.libaxolotl.util.guava.Optional; import org.whispersystems.textsecure.api.TextSecureMessageSender; import org.whispersystems.textsecure.api.crypto.UntrustedIdentityException; +import org.whispersystems.textsecure.api.messages.TextSecureAttachment; import org.whispersystems.textsecure.api.messages.TextSecureAttachmentStream; import org.whispersystems.textsecure.api.messages.multidevice.DeviceGroup; import org.whispersystems.textsecure.api.messages.multidevice.DeviceGroupsOutputStream; @@ -93,10 +94,11 @@ public class MultiDeviceGroupUpdateJob extends MasterSecretJob implements Inject throws IOException, UntrustedIdentityException { FileInputStream contactsFileStream = new FileInputStream(contactsFile); - TextSecureAttachmentStream attachmentStream = new TextSecureAttachmentStream(contactsFileStream, - "application/octet-stream", - contactsFile.length(), - null); + TextSecureAttachmentStream attachmentStream = TextSecureAttachment.newStreamBuilder() + .withStream(contactsFileStream) + .withContentType("application/octet-stream") + .withLength(contactsFile.length()) + .build(); messageSender.sendMessage(TextSecureSyncMessage.forGroups(attachmentStream)); } @@ -105,8 +107,11 @@ public class MultiDeviceGroupUpdateJob extends MasterSecretJob implements Inject private Optional getAvatar(@Nullable byte[] avatar) { if (avatar == null) return Optional.absent(); - return Optional.of(new TextSecureAttachmentStream(new ByteArrayInputStream(avatar), - "image/*", avatar.length, null)); + return Optional.of(TextSecureAttachment.newStreamBuilder() + .withStream(new ByteArrayInputStream(avatar)) + .withContentType("image/*") + .withLength(avatar.length) + .build()); } private File createTempFile(String prefix) throws IOException { diff --git a/src/org/thoughtcrime/securesms/jobs/PushSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushSendJob.java index bddae1c39d..72d0d82d4b 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushSendJob.java @@ -67,11 +67,16 @@ public abstract class PushSendJob extends SendJob { { try { InputStream is = PartAuthority.getPartStream(context, masterSecret, part.getDataUri()); - attachments.add(new TextSecureAttachmentStream(is, contentType, part.getDataSize(), new ProgressListener() { - @Override public void onAttachmentProgress(long total, long progress) { - EventBus.getDefault().postSticky(new PartProgressEvent(part.getPartId(), total, progress)); - } - })); + attachments.add(TextSecureAttachment.newStreamBuilder() + .withStream(is) + .withContentType(contentType) + .withLength(part.getDataSize()) + .withListener(new ProgressListener() { + @Override public void onAttachmentProgress(long total, long progress) { + EventBus.getDefault().postSticky(new PartProgressEvent(part.getPartId(), total, progress)); + } + }) + .build()); } catch (IOException ioe) { Log.w(TAG, "Couldn't open attachment", ioe); }