2013-07-18 17:42:45 -07:00
|
|
|
package org.thoughtcrime.securesms.mms;
|
|
|
|
|
2015-10-12 18:25:05 -07:00
|
|
|
import org.thoughtcrime.securesms.attachments.Attachment;
|
|
|
|
import org.thoughtcrime.securesms.attachments.PointerAttachment;
|
2015-07-06 17:36:49 -07:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecretUnion;
|
2015-10-12 18:25:05 -07:00
|
|
|
import org.thoughtcrime.securesms.database.MmsAddresses;
|
2014-11-04 15:01:32 -08:00
|
|
|
import org.thoughtcrime.securesms.util.GroupUtil;
|
2014-11-03 15:16:04 -08:00
|
|
|
import org.whispersystems.libaxolotl.util.guava.Optional;
|
|
|
|
import org.whispersystems.textsecure.api.messages.TextSecureAttachment;
|
|
|
|
import org.whispersystems.textsecure.api.messages.TextSecureGroup;
|
|
|
|
|
2015-10-12 18:25:05 -07:00
|
|
|
import java.util.LinkedList;
|
2014-11-03 15:16:04 -08:00
|
|
|
import java.util.List;
|
2013-07-18 17:42:45 -07:00
|
|
|
|
|
|
|
public class IncomingMediaMessage {
|
|
|
|
|
2015-10-12 18:25:05 -07:00
|
|
|
private final String from;
|
|
|
|
private final String body;
|
|
|
|
private final String groupId;
|
|
|
|
private final boolean push;
|
|
|
|
private final long sentTimeMillis;
|
|
|
|
|
|
|
|
private final List<String> to = new LinkedList<>();
|
|
|
|
private final List<String> cc = new LinkedList<>();
|
|
|
|
private final List<Attachment> attachments = new LinkedList<>();
|
2013-07-18 17:42:45 -07:00
|
|
|
|
2015-10-12 18:25:05 -07:00
|
|
|
public IncomingMediaMessage(String from, List<String> to, List<String> cc,
|
|
|
|
String body, long sentTimeMillis,
|
|
|
|
List<Attachment> attachments)
|
|
|
|
{
|
|
|
|
this.from = from;
|
|
|
|
this.sentTimeMillis = sentTimeMillis;
|
|
|
|
this.body = body;
|
|
|
|
this.groupId = null;
|
|
|
|
this.push = false;
|
|
|
|
|
|
|
|
this.to.addAll(to);
|
|
|
|
this.cc.addAll(cc);
|
|
|
|
this.attachments.addAll(attachments);
|
2013-07-18 17:42:45 -07:00
|
|
|
}
|
|
|
|
|
2015-07-06 17:36:49 -07:00
|
|
|
public IncomingMediaMessage(MasterSecretUnion masterSecret,
|
2014-11-03 15:16:04 -08:00
|
|
|
String from,
|
|
|
|
String to,
|
|
|
|
long sentTimeMillis,
|
|
|
|
Optional<String> relay,
|
|
|
|
Optional<String> body,
|
|
|
|
Optional<TextSecureGroup> group,
|
|
|
|
Optional<List<TextSecureAttachment>> attachments)
|
2013-07-18 17:42:45 -07:00
|
|
|
{
|
2015-10-12 18:25:05 -07:00
|
|
|
this.push = true;
|
|
|
|
this.from = from;
|
|
|
|
this.sentTimeMillis = sentTimeMillis;
|
|
|
|
this.body = body.orNull();
|
|
|
|
|
|
|
|
if (group.isPresent()) this.groupId = GroupUtil.getEncodedId(group.get().getGroupId());
|
|
|
|
else this.groupId = null;
|
2013-07-18 17:42:45 -07:00
|
|
|
|
2015-10-12 18:25:05 -07:00
|
|
|
this.to.add(to);
|
|
|
|
this.attachments.addAll(PointerAttachment.forPointers(masterSecret, attachments));
|
2013-07-18 17:42:45 -07:00
|
|
|
}
|
|
|
|
|
2015-10-12 18:25:05 -07:00
|
|
|
public String getBody() {
|
2013-07-18 17:42:45 -07:00
|
|
|
return body;
|
|
|
|
}
|
|
|
|
|
2015-10-12 18:25:05 -07:00
|
|
|
public MmsAddresses getAddresses() {
|
|
|
|
return new MmsAddresses(from, to, cc, new LinkedList<String>());
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<Attachment> getAttachments() {
|
|
|
|
return attachments;
|
|
|
|
}
|
|
|
|
|
2014-01-14 00:26:43 -08:00
|
|
|
public String getGroupId() {
|
|
|
|
return groupId;
|
|
|
|
}
|
|
|
|
|
2014-02-20 23:00:38 -08:00
|
|
|
public boolean isPushMessage() {
|
|
|
|
return push;
|
|
|
|
}
|
|
|
|
|
2015-10-12 18:25:05 -07:00
|
|
|
public long getSentTimeMillis() {
|
|
|
|
return sentTimeMillis;
|
|
|
|
}
|
|
|
|
|
2013-07-18 17:42:45 -07:00
|
|
|
public boolean isGroupMessage() {
|
2015-10-12 18:25:05 -07:00
|
|
|
return groupId != null || to.size() > 1 || cc.size() > 0;
|
2013-07-18 17:42:45 -07:00
|
|
|
}
|
|
|
|
}
|