Use attachment stream builders.
// FREEBIE
This commit is contained in:
parent
c2e5f4e80a
commit
59772504e3
3 changed files with 38 additions and 17 deletions
|
@ -20,6 +20,7 @@ import org.whispersystems.jobqueue.requirements.NetworkRequirement;
|
||||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||||
import org.whispersystems.textsecure.api.TextSecureMessageSender;
|
import org.whispersystems.textsecure.api.TextSecureMessageSender;
|
||||||
import org.whispersystems.textsecure.api.crypto.UntrustedIdentityException;
|
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.TextSecureAttachmentStream;
|
||||||
import org.whispersystems.textsecure.api.messages.multidevice.DeviceContact;
|
import org.whispersystems.textsecure.api.messages.multidevice.DeviceContact;
|
||||||
import org.whispersystems.textsecure.api.messages.multidevice.DeviceContactsOutputStream;
|
import org.whispersystems.textsecure.api.messages.multidevice.DeviceContactsOutputStream;
|
||||||
|
@ -101,10 +102,11 @@ public class MultiDeviceContactUpdateJob extends MasterSecretJob implements Inje
|
||||||
throws IOException, UntrustedIdentityException, NetworkException
|
throws IOException, UntrustedIdentityException, NetworkException
|
||||||
{
|
{
|
||||||
FileInputStream contactsFileStream = new FileInputStream(contactsFile);
|
FileInputStream contactsFileStream = new FileInputStream(contactsFile);
|
||||||
TextSecureAttachmentStream attachmentStream = new TextSecureAttachmentStream(contactsFileStream,
|
TextSecureAttachmentStream attachmentStream = TextSecureAttachment.newStreamBuilder()
|
||||||
"application/octet-stream",
|
.withStream(contactsFileStream)
|
||||||
contactsFile.length(),
|
.withContentType("application/octet-stream")
|
||||||
null);
|
.withLength(contactsFile.length())
|
||||||
|
.build();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
messageSender.sendMessage(TextSecureSyncMessage.forContacts(attachmentStream));
|
messageSender.sendMessage(TextSecureSyncMessage.forContacts(attachmentStream));
|
||||||
|
@ -118,7 +120,12 @@ public class MultiDeviceContactUpdateJob extends MasterSecretJob implements Inje
|
||||||
try {
|
try {
|
||||||
Uri displayPhotoUri = Uri.withAppendedPath(uri, ContactsContract.Contacts.Photo.DISPLAY_PHOTO);
|
Uri displayPhotoUri = Uri.withAppendedPath(uri, ContactsContract.Contacts.Photo.DISPLAY_PHOTO);
|
||||||
AssetFileDescriptor fd = context.getContentResolver().openAssetFileDescriptor(displayPhotoUri, "r");
|
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) {
|
} catch (IOException e) {
|
||||||
Log.w(TAG, e);
|
Log.w(TAG, e);
|
||||||
}
|
}
|
||||||
|
@ -141,7 +148,11 @@ public class MultiDeviceContactUpdateJob extends MasterSecretJob implements Inje
|
||||||
byte[] data = cursor.getBlob(0);
|
byte[] data = cursor.getBlob(0);
|
||||||
|
|
||||||
if (data != null) {
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ import org.whispersystems.jobqueue.requirements.NetworkRequirement;
|
||||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||||
import org.whispersystems.textsecure.api.TextSecureMessageSender;
|
import org.whispersystems.textsecure.api.TextSecureMessageSender;
|
||||||
import org.whispersystems.textsecure.api.crypto.UntrustedIdentityException;
|
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.TextSecureAttachmentStream;
|
||||||
import org.whispersystems.textsecure.api.messages.multidevice.DeviceGroup;
|
import org.whispersystems.textsecure.api.messages.multidevice.DeviceGroup;
|
||||||
import org.whispersystems.textsecure.api.messages.multidevice.DeviceGroupsOutputStream;
|
import org.whispersystems.textsecure.api.messages.multidevice.DeviceGroupsOutputStream;
|
||||||
|
@ -93,10 +94,11 @@ public class MultiDeviceGroupUpdateJob extends MasterSecretJob implements Inject
|
||||||
throws IOException, UntrustedIdentityException
|
throws IOException, UntrustedIdentityException
|
||||||
{
|
{
|
||||||
FileInputStream contactsFileStream = new FileInputStream(contactsFile);
|
FileInputStream contactsFileStream = new FileInputStream(contactsFile);
|
||||||
TextSecureAttachmentStream attachmentStream = new TextSecureAttachmentStream(contactsFileStream,
|
TextSecureAttachmentStream attachmentStream = TextSecureAttachment.newStreamBuilder()
|
||||||
"application/octet-stream",
|
.withStream(contactsFileStream)
|
||||||
contactsFile.length(),
|
.withContentType("application/octet-stream")
|
||||||
null);
|
.withLength(contactsFile.length())
|
||||||
|
.build();
|
||||||
|
|
||||||
messageSender.sendMessage(TextSecureSyncMessage.forGroups(attachmentStream));
|
messageSender.sendMessage(TextSecureSyncMessage.forGroups(attachmentStream));
|
||||||
}
|
}
|
||||||
|
@ -105,8 +107,11 @@ public class MultiDeviceGroupUpdateJob extends MasterSecretJob implements Inject
|
||||||
private Optional<TextSecureAttachmentStream> getAvatar(@Nullable byte[] avatar) {
|
private Optional<TextSecureAttachmentStream> getAvatar(@Nullable byte[] avatar) {
|
||||||
if (avatar == null) return Optional.absent();
|
if (avatar == null) return Optional.absent();
|
||||||
|
|
||||||
return Optional.of(new TextSecureAttachmentStream(new ByteArrayInputStream(avatar),
|
return Optional.of(TextSecureAttachment.newStreamBuilder()
|
||||||
"image/*", avatar.length, null));
|
.withStream(new ByteArrayInputStream(avatar))
|
||||||
|
.withContentType("image/*")
|
||||||
|
.withLength(avatar.length)
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private File createTempFile(String prefix) throws IOException {
|
private File createTempFile(String prefix) throws IOException {
|
||||||
|
|
|
@ -67,11 +67,16 @@ public abstract class PushSendJob extends SendJob {
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
InputStream is = PartAuthority.getPartStream(context, masterSecret, part.getDataUri());
|
InputStream is = PartAuthority.getPartStream(context, masterSecret, part.getDataUri());
|
||||||
attachments.add(new TextSecureAttachmentStream(is, contentType, part.getDataSize(), new ProgressListener() {
|
attachments.add(TextSecureAttachment.newStreamBuilder()
|
||||||
@Override public void onAttachmentProgress(long total, long progress) {
|
.withStream(is)
|
||||||
EventBus.getDefault().postSticky(new PartProgressEvent(part.getPartId(), total, progress));
|
.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) {
|
} catch (IOException ioe) {
|
||||||
Log.w(TAG, "Couldn't open attachment", ioe);
|
Log.w(TAG, "Couldn't open attachment", ioe);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue