session-android/src/org/thoughtcrime/securesms/mms/IncomingMediaMessage.java

116 lines
3.6 KiB
Java
Raw Normal View History

package org.thoughtcrime.securesms.mms;
import org.thoughtcrime.securesms.attachments.Attachment;
import org.thoughtcrime.securesms.attachments.PointerAttachment;
import org.thoughtcrime.securesms.crypto.MasterSecretUnion;
import org.thoughtcrime.securesms.database.MmsAddresses;
2014-11-04 23:01:32 +00:00
import org.thoughtcrime.securesms.util.GroupUtil;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
import java.util.LinkedList;
import java.util.List;
public class IncomingMediaMessage {
private final String from;
private final String body;
private final String groupId;
private final boolean push;
private final long sentTimeMillis;
private final int subscriptionId;
private final long expiresIn;
private final boolean expirationUpdate;
private final List<String> to = new LinkedList<>();
private final List<String> cc = new LinkedList<>();
private final List<Attachment> attachments = new LinkedList<>();
public IncomingMediaMessage(String from, List<String> to, List<String> cc,
String body, long sentTimeMillis,
List<Attachment> attachments, int subscriptionId,
long expiresIn, boolean expirationUpdate)
{
this.from = from;
this.sentTimeMillis = sentTimeMillis;
this.body = body;
this.groupId = null;
this.push = false;
this.subscriptionId = subscriptionId;
this.expiresIn = expiresIn;
this.expirationUpdate = expirationUpdate;
this.to.addAll(to);
this.cc.addAll(cc);
this.attachments.addAll(attachments);
}
public IncomingMediaMessage(MasterSecretUnion masterSecret,
String from,
String to,
long sentTimeMillis,
int subscriptionId,
long expiresIn,
boolean expirationUpdate,
Optional<String> relay,
Optional<String> body,
Optional<SignalServiceGroup> group,
Optional<List<SignalServiceAttachment>> attachments)
{
this.push = true;
this.from = from;
this.sentTimeMillis = sentTimeMillis;
this.body = body.orNull();
this.subscriptionId = subscriptionId;
this.expiresIn = expiresIn;
this.expirationUpdate = expirationUpdate;
if (group.isPresent()) this.groupId = GroupUtil.getEncodedId(group.get().getGroupId());
else this.groupId = null;
this.to.add(to);
this.attachments.addAll(PointerAttachment.forPointers(masterSecret, attachments));
}
public int getSubscriptionId() {
return subscriptionId;
}
public String getBody() {
return body;
}
public MmsAddresses getAddresses() {
return new MmsAddresses(from, to, cc, new LinkedList<String>());
}
public List<Attachment> getAttachments() {
return attachments;
}
2014-01-14 08:26:43 +00:00
public String getGroupId() {
return groupId;
}
public boolean isPushMessage() {
return push;
}
public boolean isExpirationUpdate() {
return expirationUpdate;
}
public long getSentTimeMillis() {
return sentTimeMillis;
}
public long getExpiresIn() {
return expiresIn;
}
public boolean isGroupMessage() {
return groupId != null || to.size() > 1 || cc.size() > 0;
}
}