Signal-Android/app/src/main/java/org/thoughtcrime/securesms/mms/IncomingMediaMessage.java

162 lines
5.0 KiB
Java
Raw Normal View History

package org.thoughtcrime.securesms.mms;
import androidx.annotation.NonNull;
import org.thoughtcrime.securesms.attachments.Attachment;
import org.thoughtcrime.securesms.attachments.PointerAttachment;
import org.thoughtcrime.securesms.contactshare.Contact;
2020-03-26 15:00:17 +01:00
import org.thoughtcrime.securesms.groups.GroupId;
2019-01-15 09:41:05 +01:00
import org.thoughtcrime.securesms.linkpreview.LinkPreview;
import org.thoughtcrime.securesms.recipients.RecipientId;
2020-03-27 19:12:10 +01:00
import org.thoughtcrime.securesms.util.GroupUtil;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
2020-03-27 19:12:10 +01:00
import org.whispersystems.signalservice.api.messages.SignalServiceGroupContext;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
public class IncomingMediaMessage {
private final RecipientId from;
2020-03-26 15:00:17 +01:00
private final GroupId groupId;
private final String body;
private final boolean push;
private final long sentTimeMillis;
private final int subscriptionId;
private final long expiresIn;
private final boolean expirationUpdate;
private final QuoteModel quote;
private final boolean unidentified;
private final boolean viewOnce;
2019-01-15 09:41:05 +01:00
private final List<Attachment> attachments = new LinkedList<>();
private final List<Contact> sharedContacts = new LinkedList<>();
private final List<LinkPreview> linkPreviews = new LinkedList<>();
public IncomingMediaMessage(@NonNull RecipientId from,
2020-03-26 15:00:17 +01:00
Optional<GroupId> groupId,
String body,
long sentTimeMillis,
List<Attachment> attachments,
int subscriptionId,
long expiresIn,
2018-05-22 11:13:10 +02:00
boolean expirationUpdate,
2019-08-01 01:33:56 +02:00
boolean viewOnce,
2018-05-22 11:13:10 +02:00
boolean unidentified)
{
this.from = from;
this.groupId = groupId.orNull();
this.sentTimeMillis = sentTimeMillis;
this.body = body;
this.push = false;
this.subscriptionId = subscriptionId;
this.expiresIn = expiresIn;
this.expirationUpdate = expirationUpdate;
2019-08-01 01:33:56 +02:00
this.viewOnce = viewOnce;
2018-02-07 23:01:37 +01:00
this.quote = null;
2018-05-22 11:13:10 +02:00
this.unidentified = unidentified;
this.attachments.addAll(attachments);
}
public IncomingMediaMessage(@NonNull RecipientId from,
long sentTimeMillis,
int subscriptionId,
long expiresIn,
boolean expirationUpdate,
2019-08-01 01:33:56 +02:00
boolean viewOnce,
2018-05-22 11:13:10 +02:00
boolean unidentified,
Optional<String> body,
2020-03-27 19:12:10 +01:00
Optional<SignalServiceGroupContext> group,
2018-02-07 23:01:37 +01:00
Optional<List<SignalServiceAttachment>> attachments,
Optional<QuoteModel> quote,
2019-01-15 09:41:05 +01:00
Optional<List<Contact>> sharedContacts,
Optional<List<LinkPreview>> linkPreviews,
Optional<Attachment> sticker)
{
this.push = true;
this.from = from;
this.sentTimeMillis = sentTimeMillis;
this.body = body.orNull();
this.subscriptionId = subscriptionId;
this.expiresIn = expiresIn;
this.expirationUpdate = expirationUpdate;
2019-08-01 01:33:56 +02:00
this.viewOnce = viewOnce;
2018-02-07 23:01:37 +01:00
this.quote = quote.orNull();
2018-05-22 11:13:10 +02:00
this.unidentified = unidentified;
2020-03-27 19:12:10 +01:00
if (group.isPresent()) this.groupId = GroupUtil.idFromGroupContext(group.get());
else this.groupId = null;
this.attachments.addAll(PointerAttachment.forPointers(attachments));
this.sharedContacts.addAll(sharedContacts.or(Collections.emptyList()));
2019-01-15 09:41:05 +01:00
this.linkPreviews.addAll(linkPreviews.or(Collections.emptyList()));
if (sticker.isPresent()) {
this.attachments.add(sticker.get());
}
}
public int getSubscriptionId() {
return subscriptionId;
}
public String getBody() {
return body;
}
public List<Attachment> getAttachments() {
return attachments;
}
public @NonNull RecipientId getFrom() {
return from;
}
2020-03-26 15:00:17 +01:00
public GroupId getGroupId() {
2014-01-14 09:26:43 +01:00
return groupId;
}
public boolean isPushMessage() {
return push;
}
public boolean isExpirationUpdate() {
return expirationUpdate;
}
public long getSentTimeMillis() {
return sentTimeMillis;
}
public long getExpiresIn() {
return expiresIn;
}
2019-08-01 01:33:56 +02:00
public boolean isViewOnce() {
return viewOnce;
2019-06-11 08:18:45 +02:00
}
public boolean isGroupMessage() {
return groupId != null;
}
2018-02-07 23:01:37 +01:00
public QuoteModel getQuote() {
return quote;
}
public List<Contact> getSharedContacts() {
return sharedContacts;
}
2018-05-22 11:13:10 +02:00
2019-01-15 09:41:05 +01:00
public List<LinkPreview> getLinkPreviews() {
return linkPreviews;
}
2018-05-22 11:13:10 +02:00
public boolean isUnidentified() {
return unidentified;
}
}