Convert OutgoingMediaMessage and it's couterparts to kotlin.

This commit is contained in:
Cody Henthorne
2022-12-09 09:48:16 -05:00
parent 8cd9a3cabe
commit c56e63d62f
33 changed files with 544 additions and 1029 deletions

View File

@@ -463,7 +463,7 @@ public class AttachmentManager {
.setTitle(context.getString(R.string.AttachmentManager__not_activated_payments, recipient.getShortDisplayName(context)))
.setMessage(context.getString(R.string.AttachmentManager__request_to_activate_payments))
.setPositiveButton(context.getString(R.string.AttachmentManager__send_request), (dialog, which) -> {
OutgoingRequestToActivatePaymentMessages outgoingMessage = new OutgoingRequestToActivatePaymentMessages(recipient, System.currentTimeMillis(), 0);
OutgoingMediaMessage outgoingMessage = OutgoingMediaMessage.requestToActivatePaymentsMessage(recipient, System.currentTimeMillis(), 0);
MessageSender.send(context, outgoingMessage, SignalDatabase.threads().getOrCreateThreadIdFor(recipient), false, null, null);
})
.setNegativeButton(context.getString(R.string.AttachmentManager__cancel), null)

View File

@@ -1,39 +0,0 @@
package org.thoughtcrime.securesms.mms;
import org.thoughtcrime.securesms.database.ThreadTable;
import org.thoughtcrime.securesms.database.model.StoryType;
import org.thoughtcrime.securesms.recipients.Recipient;
import java.util.Collections;
import java.util.LinkedList;
public class OutgoingExpirationUpdateMessage extends OutgoingSecureMediaMessage {
public OutgoingExpirationUpdateMessage(Recipient recipient, long sentTimeMillis, long expiresIn) {
super(recipient,
"",
new LinkedList<>(),
sentTimeMillis,
ThreadTable.DistributionTypes.CONVERSATION,
expiresIn,
false,
StoryType.NONE,
null,
false,
null,
Collections.emptyList(),
Collections.emptyList(),
Collections.emptyList(),
null);
}
@Override
public boolean isExpirationUpdate() {
return true;
}
@Override
public boolean isUrgent() {
return false;
}
}

View File

@@ -1,104 +0,0 @@
package org.thoughtcrime.securesms.mms;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.thoughtcrime.securesms.attachments.Attachment;
import org.thoughtcrime.securesms.contactshare.Contact;
import org.thoughtcrime.securesms.database.ThreadTable;
import org.thoughtcrime.securesms.database.model.Mention;
import org.thoughtcrime.securesms.database.model.StoryType;
import org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context;
import org.thoughtcrime.securesms.linkpreview.LinkPreview;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.sms.GroupV2UpdateMessageUtil;
import org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext;
import java.util.Collections;
import java.util.List;
public final class OutgoingGroupUpdateMessage extends OutgoingSecureMediaMessage {
private final MessageGroupContext messageGroupContext;
public OutgoingGroupUpdateMessage(@NonNull Recipient recipient,
@NonNull MessageGroupContext groupContext,
@NonNull List<Attachment> avatar,
long sentTimeMillis,
long expiresIn,
boolean viewOnce,
@Nullable QuoteModel quote,
@NonNull List<Contact> contacts,
@NonNull List<LinkPreview> previews,
@NonNull List<Mention> mentions)
{
super(recipient,
groupContext.getEncodedGroupContext(),
avatar,
sentTimeMillis,
ThreadTable.DistributionTypes.CONVERSATION,
expiresIn,
viewOnce,
StoryType.NONE,
null,
false,
quote,
contacts,
previews,
mentions,
null);
this.messageGroupContext = groupContext;
}
public OutgoingGroupUpdateMessage(@NonNull Recipient recipient,
@NonNull GroupContext group,
@Nullable final Attachment avatar,
long sentTimeMillis,
long expireIn,
boolean viewOnce,
@Nullable QuoteModel quote,
@NonNull List<Contact> contacts,
@NonNull List<LinkPreview> previews,
@NonNull List<Mention> mentions)
{
this(recipient, new MessageGroupContext(group), getAttachments(avatar), sentTimeMillis, expireIn, viewOnce, quote, contacts, previews, mentions);
}
public OutgoingGroupUpdateMessage(@NonNull Recipient recipient,
@NonNull DecryptedGroupV2Context group,
long sentTimeMillis)
{
this(recipient, new MessageGroupContext(group), Collections.emptyList(), sentTimeMillis, 0, false, null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
}
@Override
public boolean isGroup() {
return true;
}
public boolean isV2Group() {
return GroupV2UpdateMessageUtil.isGroupV2(messageGroupContext);
}
public boolean isJustAGroupLeave() {
return GroupV2UpdateMessageUtil.isJustAGroupLeave(messageGroupContext);
}
public @NonNull MessageGroupContext.GroupV1Properties requireGroupV1Properties() {
return messageGroupContext.requireGroupV1Properties();
}
public @NonNull MessageGroupContext.GroupV2Properties requireGroupV2Properties() {
return messageGroupContext.requireGroupV2Properties();
}
@Override
public boolean isUrgent() {
return false;
}
private static List<Attachment> getAttachments(@Nullable Attachment avatar) {
return avatar == null ? Collections.emptyList() : Collections.singletonList(avatar);
}
}

View File

@@ -1,277 +0,0 @@
package org.thoughtcrime.securesms.mms;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.thoughtcrime.securesms.attachments.Attachment;
import org.thoughtcrime.securesms.contactshare.Contact;
import org.thoughtcrime.securesms.database.documents.IdentityKeyMismatch;
import org.thoughtcrime.securesms.database.documents.NetworkFailure;
import org.thoughtcrime.securesms.database.model.Mention;
import org.thoughtcrime.securesms.database.model.ParentStoryId;
import org.thoughtcrime.securesms.database.model.StoryType;
import org.thoughtcrime.securesms.database.model.databaseprotos.GiftBadge;
import org.thoughtcrime.securesms.linkpreview.LinkPreview;
import org.thoughtcrime.securesms.recipients.Recipient;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
public class OutgoingMediaMessage {
private final Recipient recipient;
protected final String body;
protected final List<Attachment> attachments;
private final long sentTimeMillis;
private final int distributionType;
private final int subscriptionId;
private final long expiresIn;
private final boolean viewOnce;
private final QuoteModel outgoingQuote;
private final StoryType storyType;
private final ParentStoryId parentStoryId;
private final boolean isStoryReaction;
private final GiftBadge giftBadge;
private final Set<NetworkFailure> networkFailures = new HashSet<>();
private final Set<IdentityKeyMismatch> identityKeyMismatches = new HashSet<>();
private final List<Contact> contacts = new LinkedList<>();
private final List<LinkPreview> linkPreviews = new LinkedList<>();
private final List<Mention> mentions = new LinkedList<>();
public OutgoingMediaMessage(Recipient recipient,
String message,
List<Attachment> attachments,
long sentTimeMillis,
int subscriptionId,
long expiresIn,
boolean viewOnce,
int distributionType,
@NonNull StoryType storyType,
@Nullable ParentStoryId parentStoryId,
boolean isStoryReaction,
@Nullable QuoteModel outgoingQuote,
@NonNull List<Contact> contacts,
@NonNull List<LinkPreview> linkPreviews,
@NonNull List<Mention> mentions,
@NonNull Set<NetworkFailure> networkFailures,
@NonNull Set<IdentityKeyMismatch> identityKeyMismatches,
@Nullable GiftBadge giftBadge)
{
this.recipient = recipient;
this.body = message;
this.sentTimeMillis = sentTimeMillis;
this.distributionType = distributionType;
this.attachments = attachments;
this.subscriptionId = subscriptionId;
this.expiresIn = expiresIn;
this.viewOnce = viewOnce;
this.outgoingQuote = outgoingQuote;
this.storyType = storyType;
this.parentStoryId = parentStoryId;
this.isStoryReaction = isStoryReaction;
this.giftBadge = giftBadge;
this.contacts.addAll(contacts);
this.linkPreviews.addAll(linkPreviews);
this.mentions.addAll(mentions);
this.networkFailures.addAll(networkFailures);
this.identityKeyMismatches.addAll(identityKeyMismatches);
}
public OutgoingMediaMessage(Recipient recipient,
SlideDeck slideDeck,
String message,
long sentTimeMillis,
int subscriptionId,
long expiresIn,
boolean viewOnce,
int distributionType,
@NonNull StoryType storyType,
@Nullable ParentStoryId parentStoryId,
boolean isStoryReaction,
@Nullable QuoteModel outgoingQuote,
@NonNull List<Contact> contacts,
@NonNull List<LinkPreview> linkPreviews,
@NonNull List<Mention> mentions,
@Nullable GiftBadge giftBadge)
{
this(recipient,
buildMessage(slideDeck, message),
slideDeck.asAttachments(),
sentTimeMillis,
subscriptionId,
expiresIn,
viewOnce,
distributionType,
storyType,
parentStoryId,
isStoryReaction,
outgoingQuote,
contacts,
linkPreviews,
mentions,
new HashSet<>(),
new HashSet<>(),
giftBadge);
}
public OutgoingMediaMessage(OutgoingMediaMessage that) {
this.recipient = that.getRecipient();
this.body = that.body;
this.distributionType = that.distributionType;
this.attachments = that.attachments;
this.sentTimeMillis = that.sentTimeMillis;
this.subscriptionId = that.subscriptionId;
this.expiresIn = that.expiresIn;
this.viewOnce = that.viewOnce;
this.outgoingQuote = that.outgoingQuote;
this.storyType = that.storyType;
this.parentStoryId = that.parentStoryId;
this.isStoryReaction = that.isStoryReaction;
this.giftBadge = that.giftBadge;
this.identityKeyMismatches.addAll(that.identityKeyMismatches);
this.networkFailures.addAll(that.networkFailures);
this.contacts.addAll(that.contacts);
this.linkPreviews.addAll(that.linkPreviews);
this.mentions.addAll(that.mentions);
}
public @NonNull OutgoingMediaMessage withExpiry(long expiresIn) {
return new OutgoingMediaMessage(
getRecipient(),
body,
attachments,
sentTimeMillis,
subscriptionId,
expiresIn,
viewOnce,
distributionType,
storyType,
parentStoryId,
isStoryReaction,
outgoingQuote,
contacts,
linkPreviews,
mentions,
networkFailures,
identityKeyMismatches,
giftBadge
);
}
public Recipient getRecipient() {
return recipient;
}
public String getBody() {
return body;
}
public List<Attachment> getAttachments() {
return attachments;
}
public int getDistributionType() {
return distributionType;
}
public boolean isSecure() {
return false;
}
public boolean isGroup() {
return false;
}
public boolean isExpirationUpdate() {
return false;
}
public boolean isPaymentsNotification() {
return false;
}
public boolean isRequestToActivatePayments() {
return false;
}
public boolean isPaymentsActivated() {
return false;
}
public long getSentTimeMillis() {
return sentTimeMillis;
}
public int getSubscriptionId() {
return subscriptionId;
}
public long getExpiresIn() {
return expiresIn;
}
public boolean isViewOnce() {
return viewOnce;
}
public @NonNull StoryType getStoryType() {
return storyType;
}
public @Nullable ParentStoryId getParentStoryId() {
return parentStoryId;
}
public boolean isStoryReaction() {
return isStoryReaction;
}
public @Nullable QuoteModel getOutgoingQuote() {
return outgoingQuote;
}
public @NonNull List<Contact> getSharedContacts() {
return contacts;
}
public @NonNull List<LinkPreview> getLinkPreviews() {
return linkPreviews;
}
public @NonNull List<Mention> getMentions() {
return mentions;
}
public @NonNull Set<NetworkFailure> getNetworkFailures() {
return networkFailures;
}
public @NonNull Set<IdentityKeyMismatch> getIdentityKeyMismatches() {
return identityKeyMismatches;
}
public @Nullable GiftBadge getGiftBadge() {
return giftBadge;
}
public boolean isUrgent() {
return true;
}
private static String buildMessage(SlideDeck slideDeck, String message) {
if (!TextUtils.isEmpty(message) && !TextUtils.isEmpty(slideDeck.getBody())) {
return slideDeck.getBody() + "\n\n" + message;
} else if (!TextUtils.isEmpty(message)) {
return message;
} else {
return slideDeck.getBody();
}
}
}

View File

@@ -0,0 +1,293 @@
package org.thoughtcrime.securesms.mms
import org.thoughtcrime.securesms.attachments.Attachment
import org.thoughtcrime.securesms.contactshare.Contact
import org.thoughtcrime.securesms.database.ThreadTable
import org.thoughtcrime.securesms.database.documents.IdentityKeyMismatch
import org.thoughtcrime.securesms.database.documents.NetworkFailure
import org.thoughtcrime.securesms.database.model.Mention
import org.thoughtcrime.securesms.database.model.ParentStoryId
import org.thoughtcrime.securesms.database.model.StoryType
import org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context
import org.thoughtcrime.securesms.database.model.databaseprotos.GiftBadge
import org.thoughtcrime.securesms.linkpreview.LinkPreview
import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.sms.GroupV2UpdateMessageUtil
/**
* Outgoing media message for all outgoing media messages (push/mms, group updates, expiration updates, payments, etc.)
*/
data class OutgoingMediaMessage(
val recipient: Recipient,
val sentTimeMillis: Long,
val body: String = "",
val distributionType: Int = ThreadTable.DistributionTypes.DEFAULT,
val subscriptionId: Int = -1,
val expiresIn: Long = 0L,
val isViewOnce: Boolean = false,
val outgoingQuote: QuoteModel? = null,
val storyType: StoryType = StoryType.NONE,
val parentStoryId: ParentStoryId? = null,
val isStoryReaction: Boolean = false,
val giftBadge: GiftBadge? = null,
val isSecure: Boolean = false,
val attachments: List<Attachment> = emptyList(),
val sharedContacts: List<Contact> = emptyList(),
val linkPreviews: List<LinkPreview> = emptyList(),
val mentions: List<Mention> = emptyList(),
val isGroup: Boolean = false,
val isGroupUpdate: Boolean = false,
val messageGroupContext: MessageGroupContext? = null,
val isExpirationUpdate: Boolean = false,
val isPaymentsNotification: Boolean = false,
val isRequestToActivatePayments: Boolean = false,
val isPaymentsActivated: Boolean = false,
val isUrgent: Boolean = true,
val networkFailures: Set<NetworkFailure> = emptySet(),
val identityKeyMismatches: Set<IdentityKeyMismatch> = emptySet(),
) {
val isV2Group: Boolean = messageGroupContext != null && GroupV2UpdateMessageUtil.isGroupV2(messageGroupContext)
val isJustAGroupLeave: Boolean = messageGroupContext != null && GroupV2UpdateMessageUtil.isJustAGroupLeave(messageGroupContext)
/**
* Smaller constructor for calling from Java and legacy code using the original interface.
*/
constructor(
recipient: Recipient,
body: String? = "",
attachments: List<Attachment> = emptyList(),
timestamp: Long,
subscriptionId: Int = -1,
expiresIn: Long = 0L,
viewOnce: Boolean = false,
distributionType: Int = ThreadTable.DistributionTypes.DEFAULT,
storyType: StoryType = StoryType.NONE,
parentStoryId: ParentStoryId? = null,
isStoryReaction: Boolean = false,
quote: QuoteModel? = null,
contacts: List<Contact> = emptyList(),
previews: List<LinkPreview> = emptyList(),
mentions: List<Mention> = emptyList(),
networkFailures: Set<NetworkFailure> = emptySet(),
mismatches: Set<IdentityKeyMismatch> = emptySet(),
giftBadge: GiftBadge? = null,
isSecure: Boolean = false
) : this(
recipient = recipient,
body = body ?: "",
attachments = attachments,
sentTimeMillis = timestamp,
subscriptionId = subscriptionId,
expiresIn = expiresIn,
isViewOnce = viewOnce,
distributionType = distributionType,
storyType = storyType,
parentStoryId = parentStoryId,
isStoryReaction = isStoryReaction,
outgoingQuote = quote,
sharedContacts = contacts,
linkPreviews = previews,
mentions = mentions,
networkFailures = networkFailures,
identityKeyMismatches = mismatches,
giftBadge = giftBadge,
isSecure = isSecure
)
/**
* Allow construction of attachments/body via a [SlideDeck] instead of passing in attachments list.
*/
constructor(
recipient: Recipient,
slideDeck: SlideDeck,
body: String? = "",
timestamp: Long,
subscriptionId: Int = -1,
expiresIn: Long = 0L,
viewOnce: Boolean = false,
storyType: StoryType = StoryType.NONE,
linkPreviews: List<LinkPreview> = emptyList(),
mentions: List<Mention> = emptyList(),
isSecure: Boolean = false
) : this(
recipient = recipient,
body = buildMessage(slideDeck, body ?: ""),
attachments = slideDeck.asAttachments(),
sentTimeMillis = timestamp,
subscriptionId = subscriptionId,
expiresIn = expiresIn,
isViewOnce = viewOnce,
storyType = storyType,
linkPreviews = linkPreviews,
mentions = mentions,
isSecure = isSecure
)
fun withExpiry(expiresIn: Long): OutgoingMediaMessage {
return copy(expiresIn = expiresIn)
}
fun stripAttachments(): OutgoingMediaMessage {
return copy(attachments = emptyList())
}
fun makeSecure(): OutgoingMediaMessage {
return copy(isSecure = true)
}
fun requireGroupV1Properties(): MessageGroupContext.GroupV1Properties {
return messageGroupContext!!.requireGroupV1Properties()
}
fun requireGroupV2Properties(): MessageGroupContext.GroupV2Properties {
return messageGroupContext!!.requireGroupV2Properties()
}
companion object {
/**
* Helper for creating a group update message when a state change occurs and needs to be sent to others.
*/
@JvmStatic
fun groupUpdateMessage(recipient: Recipient, group: DecryptedGroupV2Context, sentTimeMillis: Long): OutgoingMediaMessage {
val groupContext = MessageGroupContext(group)
return OutgoingMediaMessage(
recipient = recipient,
body = groupContext.encodedGroupContext,
sentTimeMillis = sentTimeMillis,
messageGroupContext = groupContext,
isGroup = true,
isGroupUpdate = true,
isSecure = true
)
}
/**
* Helper for creating a group update message when a state change occurs and needs to be sent to others.
*/
@JvmStatic
fun groupUpdateMessage(
recipient: Recipient,
groupContext: MessageGroupContext,
avatar: List<Attachment> = emptyList(),
sentTimeMillis: Long,
expiresIn: Long = 0L,
viewOnce: Boolean = false,
quote: QuoteModel? = null,
contacts: List<Contact> = emptyList(),
previews: List<LinkPreview> = emptyList(),
mentions: List<Mention> = emptyList()
): OutgoingMediaMessage {
return OutgoingMediaMessage(
recipient = recipient,
body = groupContext.encodedGroupContext,
isGroup = true,
isGroupUpdate = true,
messageGroupContext = groupContext,
attachments = avatar,
sentTimeMillis = sentTimeMillis,
expiresIn = expiresIn,
isViewOnce = viewOnce,
outgoingQuote = quote,
sharedContacts = contacts,
linkPreviews = previews,
mentions = mentions,
isSecure = true
)
}
/**
* Helper for creating a text story message.
*/
@JvmStatic
fun textStoryMessage(
recipient: Recipient,
body: String,
sentTimeMillis: Long,
storyType: StoryType,
linkPreviews: List<LinkPreview>
): OutgoingMediaMessage {
return OutgoingMediaMessage(
recipient = recipient,
body = body,
sentTimeMillis = sentTimeMillis,
storyType = storyType,
linkPreviews = linkPreviews,
isSecure = true
)
}
/**
* Specialized message sent to request someone activate payments.
*/
@JvmStatic
fun requestToActivatePaymentsMessage(recipient: Recipient, sentTimeMillis: Long, expiresIn: Long): OutgoingMediaMessage {
return OutgoingMediaMessage(
recipient = recipient,
sentTimeMillis = sentTimeMillis,
expiresIn = expiresIn,
isRequestToActivatePayments = true,
isUrgent = false,
isSecure = true
)
}
/**
* Specialized message sent to indicate you activated payments. Intended to only
* be sent to those that sent requests prior to activation.
*/
@JvmStatic
fun paymentsActivatedMessage(recipient: Recipient, sentTimeMillis: Long, expiresIn: Long): OutgoingMediaMessage {
return OutgoingMediaMessage(
recipient = recipient,
sentTimeMillis = sentTimeMillis,
expiresIn = expiresIn,
isPaymentsActivated = true,
isUrgent = false,
isSecure = true
)
}
/**
* Type of message sent when sending a payment to another Signal contact.
*/
@JvmStatic
fun paymentNotificationMessage(recipient: Recipient, paymentUuid: String, sentTimeMillis: Long, expiresIn: Long): OutgoingMediaMessage {
return OutgoingMediaMessage(
recipient = recipient,
body = paymentUuid,
sentTimeMillis = sentTimeMillis,
expiresIn = expiresIn,
isPaymentsNotification = true,
isSecure = true
)
}
/**
* Helper for creating expiration update messages.
*/
@JvmStatic
fun expirationUpdateMessage(recipient: Recipient, sentTimeMillis: Long, expiresIn: Long): OutgoingMediaMessage {
return OutgoingMediaMessage(
recipient = recipient,
sentTimeMillis = sentTimeMillis,
expiresIn = expiresIn,
isExpirationUpdate = true,
isUrgent = false,
isSecure = true
)
}
@JvmStatic
fun buildMessage(slideDeck: SlideDeck, message: String): String {
return if (message.isNotEmpty() && slideDeck.body.isNotEmpty()) {
"${slideDeck.body}\n\n$message"
} else if (message.isNotEmpty()) {
message
} else {
slideDeck.body
}
}
}
}

View File

@@ -1,88 +0,0 @@
package org.thoughtcrime.securesms.mms
import org.thoughtcrime.securesms.database.ThreadTable
import org.thoughtcrime.securesms.database.model.StoryType
import org.thoughtcrime.securesms.recipients.Recipient
import java.util.LinkedList
/**
* Specialized message sent to request someone activate payments.
*/
class OutgoingRequestToActivatePaymentMessages(
recipient: Recipient,
sentTimeMillis: Long,
expiresIn: Long
) : OutgoingSecureMediaMessage(
recipient,
"",
LinkedList(),
sentTimeMillis,
ThreadTable.DistributionTypes.CONVERSATION,
expiresIn,
false,
StoryType.NONE,
null,
false,
null,
emptyList(),
emptyList(),
emptyList(),
null
) {
override fun isRequestToActivatePayments(): Boolean = true
override fun isUrgent(): Boolean = false
}
/**
* Specialized message sent to indicate you activated payments. Intended to only
* be sent to those that sent requests prior to activation.
*/
class OutgoingPaymentsActivatedMessages(
recipient: Recipient,
sentTimeMillis: Long,
expiresIn: Long
) : OutgoingSecureMediaMessage(
recipient,
"",
LinkedList(),
sentTimeMillis,
ThreadTable.DistributionTypes.CONVERSATION,
expiresIn,
false,
StoryType.NONE,
null,
false,
null,
emptyList(),
emptyList(),
emptyList(),
null
) {
override fun isPaymentsActivated(): Boolean = true
override fun isUrgent(): Boolean = false
}
class OutgoingPaymentsNotificationMessage(
recipient: Recipient,
paymentUuid: String,
sentTimeMillis: Long,
expiresIn: Long
) : OutgoingSecureMediaMessage(
recipient,
paymentUuid,
LinkedList(),
sentTimeMillis,
ThreadTable.DistributionTypes.CONVERSATION,
expiresIn,
false,
StoryType.NONE,
null,
false,
null,
emptyList(),
emptyList(),
emptyList(),
null
) {
override fun isPaymentsNotification(): Boolean = true
}

View File

@@ -1,102 +0,0 @@
package org.thoughtcrime.securesms.mms;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.thoughtcrime.securesms.attachments.Attachment;
import org.thoughtcrime.securesms.contactshare.Contact;
import org.thoughtcrime.securesms.database.model.Mention;
import org.thoughtcrime.securesms.database.model.ParentStoryId;
import org.thoughtcrime.securesms.database.model.StoryType;
import org.thoughtcrime.securesms.database.model.databaseprotos.GiftBadge;
import org.thoughtcrime.securesms.linkpreview.LinkPreview;
import org.thoughtcrime.securesms.recipients.Recipient;
import java.util.Collections;
import java.util.List;
public class OutgoingSecureMediaMessage extends OutgoingMediaMessage {
public OutgoingSecureMediaMessage(Recipient recipient,
String body,
List<Attachment> attachments,
long sentTimeMillis,
int distributionType,
long expiresIn,
boolean viewOnce,
@NonNull StoryType storyType,
@Nullable ParentStoryId parentStoryId,
boolean isStoryReaction,
@Nullable QuoteModel quote,
@NonNull List<Contact> contacts,
@NonNull List<LinkPreview> previews,
@NonNull List<Mention> mentions,
@Nullable GiftBadge giftBadge)
{
super(recipient, body, attachments, sentTimeMillis, -1, expiresIn, viewOnce, distributionType, storyType, parentStoryId, isStoryReaction, quote, contacts, previews, mentions, Collections.emptySet(), Collections.emptySet(), giftBadge);
}
public OutgoingSecureMediaMessage(OutgoingMediaMessage base) {
super(base);
}
@Override
public boolean isSecure() {
return true;
}
@Override
public @NonNull OutgoingMediaMessage withExpiry(long expiresIn) {
return new OutgoingSecureMediaMessage(getRecipient(),
getBody(),
getAttachments(),
getSentTimeMillis(),
getDistributionType(),
expiresIn,
isViewOnce(),
getStoryType(),
getParentStoryId(),
isStoryReaction(),
getOutgoingQuote(),
getSharedContacts(),
getLinkPreviews(),
getMentions(),
getGiftBadge());
}
public @NonNull OutgoingSecureMediaMessage withSentTimestamp(long sentTimestamp) {
return new OutgoingSecureMediaMessage(getRecipient(),
getBody(),
getAttachments(),
sentTimestamp,
getDistributionType(),
getExpiresIn(),
isViewOnce(),
getStoryType(),
getParentStoryId(),
isStoryReaction(),
getOutgoingQuote(),
getSharedContacts(),
getLinkPreviews(),
getMentions(),
getGiftBadge());
}
public @NonNull OutgoingSecureMediaMessage stripAttachments() {
return new OutgoingSecureMediaMessage(getRecipient(),
getBody(),
Collections.emptyList(),
getSentTimeMillis(),
getDistributionType(),
getExpiresIn(),
isViewOnce(),
getStoryType(),
getParentStoryId(),
isStoryReaction(),
getOutgoingQuote(),
Collections.emptyList(),
getLinkPreviews(),
getMentions(),
getGiftBadge());
}
}