2013-07-19 02:42:45 +02:00
|
|
|
package org.thoughtcrime.securesms.mms;
|
|
|
|
|
2019-08-07 20:22:51 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
2015-10-13 03:25:05 +02:00
|
|
|
import org.thoughtcrime.securesms.attachments.Attachment;
|
|
|
|
import org.thoughtcrime.securesms.attachments.PointerAttachment;
|
2018-04-27 02:03:54 +02:00
|
|
|
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;
|
2019-08-07 20:22:51 +02:00
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientId;
|
2020-03-27 19:12:10 +01:00
|
|
|
import org.thoughtcrime.securesms.util.GroupUtil;
|
2016-03-23 18:34:41 +01:00
|
|
|
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;
|
2014-11-04 00:16:04 +01:00
|
|
|
|
2018-04-27 02:03:54 +02:00
|
|
|
import java.util.Collections;
|
2015-10-13 03:25:05 +02:00
|
|
|
import java.util.LinkedList;
|
2014-11-04 00:16:04 +01:00
|
|
|
import java.util.List;
|
2013-07-19 02:42:45 +02:00
|
|
|
|
|
|
|
public class IncomingMediaMessage {
|
|
|
|
|
2019-08-07 20:22:51 +02:00
|
|
|
private final RecipientId from;
|
2020-03-26 15:00:17 +01:00
|
|
|
private final GroupId groupId;
|
2019-08-07 20:22:51 +02:00
|
|
|
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;
|
2015-10-13 03:25:05 +02:00
|
|
|
|
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<>();
|
2013-07-19 02:42:45 +02:00
|
|
|
|
2019-08-07 20:22:51 +02:00
|
|
|
public IncomingMediaMessage(@NonNull RecipientId from,
|
2020-03-26 15:00:17 +01:00
|
|
|
Optional<GroupId> groupId,
|
2017-08-01 17:56:00 +02:00
|
|
|
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)
|
2015-10-13 03:25:05 +02:00
|
|
|
{
|
2017-08-01 17:56:00 +02:00
|
|
|
this.from = from;
|
|
|
|
this.groupId = groupId.orNull();
|
2016-08-16 05:23:56 +02:00
|
|
|
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;
|
2015-10-13 03:25:05 +02:00
|
|
|
|
|
|
|
this.attachments.addAll(attachments);
|
2013-07-19 02:42:45 +02:00
|
|
|
}
|
|
|
|
|
2019-08-07 20:22:51 +02:00
|
|
|
public IncomingMediaMessage(@NonNull RecipientId from,
|
2014-11-04 00:16:04 +01:00
|
|
|
long sentTimeMillis,
|
2016-02-06 01:10:33 +01:00
|
|
|
int subscriptionId,
|
2016-08-16 05:23:56 +02:00
|
|
|
long expiresIn,
|
|
|
|
boolean expirationUpdate,
|
2019-08-01 01:33:56 +02:00
|
|
|
boolean viewOnce,
|
2018-05-22 11:13:10 +02:00
|
|
|
boolean unidentified,
|
2014-11-04 00:16:04 +01:00
|
|
|
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,
|
2018-04-27 02:03:54 +02:00
|
|
|
Optional<QuoteModel> quote,
|
2019-01-15 09:41:05 +01:00
|
|
|
Optional<List<Contact>> sharedContacts,
|
2019-04-17 16:21:30 +02:00
|
|
|
Optional<List<LinkPreview>> linkPreviews,
|
|
|
|
Optional<Attachment> sticker)
|
2013-07-19 02:42:45 +02:00
|
|
|
{
|
2016-08-16 05:23:56 +02:00
|
|
|
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;
|
2015-10-13 03:25:05 +02:00
|
|
|
|
2020-03-27 19:12:10 +01:00
|
|
|
if (group.isPresent()) this.groupId = GroupUtil.idFromGroupContext(group.get());
|
2015-10-13 03:25:05 +02:00
|
|
|
else this.groupId = null;
|
2013-07-19 02:42:45 +02:00
|
|
|
|
2018-01-25 04:17:44 +01:00
|
|
|
this.attachments.addAll(PointerAttachment.forPointers(attachments));
|
2018-04-27 02:03:54 +02:00
|
|
|
this.sharedContacts.addAll(sharedContacts.or(Collections.emptyList()));
|
2019-01-15 09:41:05 +01:00
|
|
|
this.linkPreviews.addAll(linkPreviews.or(Collections.emptyList()));
|
2019-04-17 16:21:30 +02:00
|
|
|
|
|
|
|
if (sticker.isPresent()) {
|
|
|
|
this.attachments.add(sticker.get());
|
|
|
|
}
|
2013-07-19 02:42:45 +02:00
|
|
|
}
|
|
|
|
|
2016-02-06 01:10:33 +01:00
|
|
|
public int getSubscriptionId() {
|
|
|
|
return subscriptionId;
|
|
|
|
}
|
|
|
|
|
2015-10-13 03:25:05 +02:00
|
|
|
public String getBody() {
|
2013-07-19 02:42:45 +02:00
|
|
|
return body;
|
|
|
|
}
|
|
|
|
|
2015-10-13 03:25:05 +02:00
|
|
|
public List<Attachment> getAttachments() {
|
|
|
|
return attachments;
|
|
|
|
}
|
|
|
|
|
2019-08-07 20:22:51 +02:00
|
|
|
public @NonNull RecipientId getFrom() {
|
2017-08-01 17:56:00 +02:00
|
|
|
return from;
|
|
|
|
}
|
|
|
|
|
2020-03-26 15:00:17 +01:00
|
|
|
public GroupId getGroupId() {
|
2014-01-14 09:26:43 +01:00
|
|
|
return groupId;
|
|
|
|
}
|
|
|
|
|
2014-02-21 08:00:38 +01:00
|
|
|
public boolean isPushMessage() {
|
|
|
|
return push;
|
|
|
|
}
|
|
|
|
|
2016-08-16 05:23:56 +02:00
|
|
|
public boolean isExpirationUpdate() {
|
|
|
|
return expirationUpdate;
|
|
|
|
}
|
|
|
|
|
2015-10-13 03:25:05 +02:00
|
|
|
public long getSentTimeMillis() {
|
|
|
|
return sentTimeMillis;
|
|
|
|
}
|
|
|
|
|
2016-08-16 05:23:56 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-07-19 02:42:45 +02:00
|
|
|
public boolean isGroupMessage() {
|
2017-08-01 17:56:00 +02:00
|
|
|
return groupId != null;
|
2013-07-19 02:42:45 +02:00
|
|
|
}
|
2018-02-07 23:01:37 +01:00
|
|
|
|
|
|
|
public QuoteModel getQuote() {
|
|
|
|
return quote;
|
|
|
|
}
|
2018-04-27 02:03:54 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2013-07-19 02:42:45 +02:00
|
|
|
}
|