mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-24 01:21:09 +00:00
@@ -3,9 +3,18 @@ package org.thoughtcrime.securesms.mms;
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.thoughtcrime.securesms.crypto.MasterCipher;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.database.ThreadDatabase;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.thoughtcrime.securesms.util.Base64;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.textsecure.api.messages.TextSecureAttachment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ws.com.google.android.mms.pdu.PduBody;
|
||||
import ws.com.google.android.mms.pdu.PduPart;
|
||||
|
||||
public class OutgoingMediaMessage {
|
||||
|
||||
@@ -31,6 +40,14 @@ public class OutgoingMediaMessage {
|
||||
this(context, recipients, slideDeck.toPduBody(), message, distributionType);
|
||||
}
|
||||
|
||||
public OutgoingMediaMessage(Context context, MasterSecret masterSecret,
|
||||
Recipients recipients, List<TextSecureAttachment> attachments,
|
||||
String message)
|
||||
{
|
||||
this(context, recipients, pduBodyFor(masterSecret, attachments), message,
|
||||
ThreadDatabase.DistributionTypes.CONVERSATION);
|
||||
}
|
||||
|
||||
public OutgoingMediaMessage(OutgoingMediaMessage that) {
|
||||
this.recipients = that.getRecipients();
|
||||
this.body = that.body;
|
||||
@@ -57,4 +74,24 @@ public class OutgoingMediaMessage {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static PduBody pduBodyFor(MasterSecret masterSecret, List<TextSecureAttachment> attachments) {
|
||||
PduBody body = new PduBody();
|
||||
|
||||
for (TextSecureAttachment attachment : attachments) {
|
||||
if (attachment.isPointer()) {
|
||||
PduPart media = new PduPart();
|
||||
byte[] encryptedKey = new MasterCipher(masterSecret).encryptBytes(attachment.asPointer().getKey());
|
||||
|
||||
media.setContentType(Util.toIsoBytes(attachment.getContentType()));
|
||||
media.setContentLocation(Util.toIsoBytes(String.valueOf(attachment.asPointer().getId())));
|
||||
media.setContentDisposition(Util.toIsoBytes(Base64.encodeBytes(encryptedKey)));
|
||||
media.setPendingPush(true);
|
||||
|
||||
body.addPart(media);
|
||||
}
|
||||
}
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user