2014-02-19 21:06:54 -08:00
|
|
|
package org.thoughtcrime.securesms.mms;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2014-11-12 11:15:05 -08:00
|
|
|
import android.text.TextUtils;
|
2014-02-19 21:06:54 -08:00
|
|
|
|
2015-05-18 15:16:27 -07:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterCipher;
|
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
|
|
|
import org.thoughtcrime.securesms.database.ThreadDatabase;
|
2014-02-19 21:06:54 -08:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
2015-05-18 15:16:27 -07:00
|
|
|
import org.thoughtcrime.securesms.util.Base64;
|
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
|
|
|
import org.whispersystems.textsecure.api.messages.TextSecureAttachment;
|
|
|
|
|
|
|
|
import java.util.List;
|
2014-02-19 21:06:54 -08:00
|
|
|
|
|
|
|
import ws.com.google.android.mms.pdu.PduBody;
|
2015-05-18 15:16:27 -07:00
|
|
|
import ws.com.google.android.mms.pdu.PduPart;
|
2014-02-19 21:06:54 -08:00
|
|
|
|
|
|
|
public class OutgoingMediaMessage {
|
|
|
|
|
|
|
|
private final Recipients recipients;
|
|
|
|
protected final PduBody body;
|
|
|
|
private final int distributionType;
|
|
|
|
|
|
|
|
public OutgoingMediaMessage(Context context, Recipients recipients, PduBody body,
|
|
|
|
String message, int distributionType)
|
|
|
|
{
|
|
|
|
this.recipients = recipients;
|
|
|
|
this.body = body;
|
|
|
|
this.distributionType = distributionType;
|
|
|
|
|
2014-11-12 11:15:05 -08:00
|
|
|
if (!TextUtils.isEmpty(message)) {
|
2014-02-19 21:06:54 -08:00
|
|
|
this.body.addPart(new TextSlide(context, message).getPart());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public OutgoingMediaMessage(Context context, Recipients recipients, SlideDeck slideDeck,
|
|
|
|
String message, int distributionType)
|
|
|
|
{
|
|
|
|
this(context, recipients, slideDeck.toPduBody(), message, distributionType);
|
|
|
|
}
|
|
|
|
|
2015-05-18 15:16:27 -07:00
|
|
|
public OutgoingMediaMessage(Context context, MasterSecret masterSecret,
|
|
|
|
Recipients recipients, List<TextSecureAttachment> attachments,
|
|
|
|
String message)
|
|
|
|
{
|
|
|
|
this(context, recipients, pduBodyFor(masterSecret, attachments), message,
|
|
|
|
ThreadDatabase.DistributionTypes.CONVERSATION);
|
|
|
|
}
|
|
|
|
|
2014-02-19 21:06:54 -08:00
|
|
|
public OutgoingMediaMessage(OutgoingMediaMessage that) {
|
|
|
|
this.recipients = that.getRecipients();
|
|
|
|
this.body = that.body;
|
|
|
|
this.distributionType = that.distributionType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Recipients getRecipients() {
|
|
|
|
return recipients;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PduBody getPduBody() {
|
|
|
|
return body;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getDistributionType() {
|
|
|
|
return distributionType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isSecure() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isGroup() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-05-18 15:16:27 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-02-19 21:06:54 -08:00
|
|
|
}
|