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

@@ -15,7 +15,6 @@ import org.thoughtcrime.securesms.contacts.paged.ContactSearchKey
import org.thoughtcrime.securesms.conversation.MessageSendType
import org.thoughtcrime.securesms.database.AttachmentTable.TransformProperties
import org.thoughtcrime.securesms.database.SignalDatabase
import org.thoughtcrime.securesms.database.ThreadTable
import org.thoughtcrime.securesms.database.model.Mention
import org.thoughtcrime.securesms.database.model.StoryType
import org.thoughtcrime.securesms.keyvalue.SignalStore
@@ -32,7 +31,6 @@ import org.thoughtcrime.securesms.mediasend.VideoEditorFragment
import org.thoughtcrime.securesms.mediasend.VideoTrimTransform
import org.thoughtcrime.securesms.mms.MediaConstraints
import org.thoughtcrime.securesms.mms.OutgoingMediaMessage
import org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage
import org.thoughtcrime.securesms.mms.SentMediaQuality
import org.thoughtcrime.securesms.mms.Slide
import org.thoughtcrime.securesms.providers.BlobProvider
@@ -231,9 +229,9 @@ class MediaSelectionRepository(context: Context) {
isViewOnce: Boolean,
storyClips: List<Media>
) {
val nonStoryMessages: MutableList<OutgoingSecureMediaMessage> = ArrayList(contacts.size)
val storyPreUploadMessages: MutableMap<PreUploadResult, MutableList<OutgoingSecureMediaMessage>> = mutableMapOf()
val storyClipMessages: MutableList<OutgoingSecureMediaMessage> = ArrayList()
val nonStoryMessages: MutableList<OutgoingMediaMessage> = ArrayList(contacts.size)
val storyPreUploadMessages: MutableMap<PreUploadResult, MutableList<OutgoingMediaMessage>> = mutableMapOf()
val storyClipMessages: MutableList<OutgoingMediaMessage> = ArrayList()
val distributionListPreUploadSentTimestamps: MutableMap<PreUploadResult, Long> = mutableMapOf()
val distributionListStoryClipsSentTimestamps: MutableMap<MediaKey, Long> = mutableMapOf()
@@ -252,38 +250,26 @@ class MediaSelectionRepository(context: Context) {
}
val message = OutgoingMediaMessage(
recipient,
body,
emptyList(),
if (recipient.isDistributionList) distributionListPreUploadSentTimestamps.getOrPut(preUploadResults.first()) { System.currentTimeMillis() } else System.currentTimeMillis(),
-1,
if (isStory) 0 else TimeUnit.SECONDS.toMillis(recipient.expiresInSeconds.toLong()),
isViewOnce,
ThreadTable.DistributionTypes.DEFAULT,
storyType,
null,
false,
null,
emptyList(),
emptyList(),
mentions,
mutableSetOf(),
mutableSetOf(),
null
recipient = recipient,
body = body,
sentTimeMillis = if (recipient.isDistributionList) distributionListPreUploadSentTimestamps.getOrPut(preUploadResults.first()) { System.currentTimeMillis() } else System.currentTimeMillis(),
expiresIn = if (isStory) 0 else TimeUnit.SECONDS.toMillis(recipient.expiresInSeconds.toLong()),
isViewOnce = isViewOnce,
storyType = storyType,
mentions = mentions,
isSecure = true
)
if (isStory) {
preUploadResults.filterNot { result -> storyClips.any { it.uri == result.media.uri } }.forEach {
val list = storyPreUploadMessages[it] ?: mutableListOf()
list.add(
OutgoingSecureMediaMessage(message).withSentTimestamp(
if (recipient.isDistributionList) {
distributionListPreUploadSentTimestamps.getOrPut(it) { System.currentTimeMillis() }
} else {
System.currentTimeMillis()
}
)
)
val timestamp = if (recipient.isDistributionList) {
distributionListPreUploadSentTimestamps.getOrPut(it) { System.currentTimeMillis() }
} else {
System.currentTimeMillis()
}
list.add(message.copy(sentTimeMillis = timestamp))
storyPreUploadMessages[it] = list
// XXX We must do this to avoid sending out messages to the same recipient with the same
@@ -293,27 +279,15 @@ class MediaSelectionRepository(context: Context) {
storyClips.forEach {
storyClipMessages.add(
OutgoingSecureMediaMessage(
OutgoingMediaMessage(
recipient,
body,
listOf(MediaUploadRepository.asAttachment(context, it)),
if (recipient.isDistributionList) distributionListStoryClipsSentTimestamps.getOrPut(it.asKey()) { System.currentTimeMillis() } else System.currentTimeMillis(),
-1,
0,
isViewOnce,
ThreadTable.DistributionTypes.DEFAULT,
storyType,
null,
false,
null,
emptyList(),
emptyList(),
mentions,
mutableSetOf(),
mutableSetOf(),
null
)
OutgoingMediaMessage(
recipient = recipient,
body = body,
attachments = listOf(MediaUploadRepository.asAttachment(context, it)),
sentTimeMillis = if (recipient.isDistributionList) distributionListStoryClipsSentTimestamps.getOrPut(it.asKey()) { System.currentTimeMillis() } else System.currentTimeMillis(),
isViewOnce = isViewOnce,
storyType = storyType,
mentions = mentions,
isSecure = true
)
)
@@ -322,7 +296,7 @@ class MediaSelectionRepository(context: Context) {
ThreadUtil.sleep(5)
}
} else {
nonStoryMessages.add(OutgoingSecureMediaMessage(message))
nonStoryMessages.add(message)
// XXX We must do this to avoid sending out messages to the same recipient with the same
// sentTimestamp. If we do this, they'll be considered dupes by the receiver.

View File

@@ -8,7 +8,6 @@ import org.signal.core.util.ThreadUtil
import org.signal.core.util.logging.Log
import org.thoughtcrime.securesms.contacts.paged.ContactSearchKey
import org.thoughtcrime.securesms.database.SignalDatabase
import org.thoughtcrime.securesms.database.ThreadTable
import org.thoughtcrime.securesms.database.model.StoryType
import org.thoughtcrime.securesms.database.model.databaseprotos.StoryTextPost
import org.thoughtcrime.securesms.fonts.TextFont
@@ -18,7 +17,6 @@ import org.thoughtcrime.securesms.linkpreview.LinkPreview
import org.thoughtcrime.securesms.mediasend.v2.UntrustedRecords
import org.thoughtcrime.securesms.mediasend.v2.text.TextStoryPostCreationState
import org.thoughtcrime.securesms.mms.OutgoingMediaMessage
import org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage
import org.thoughtcrime.securesms.providers.BlobProvider
import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.stories.Stories
@@ -61,7 +59,7 @@ class TextStoryPostSendRepository {
private fun performSend(contactSearchKey: Set<ContactSearchKey>, textStoryPostCreationState: TextStoryPostCreationState, linkPreview: LinkPreview?): Single<TextStoryPostSendResult> {
return Single.fromCallable {
val messages: MutableList<OutgoingSecureMediaMessage> = mutableListOf()
val messages: MutableList<OutgoingMediaMessage> = mutableListOf()
val distributionListSentTimestamp = System.currentTimeMillis()
for (contact in contactSearchKey) {
@@ -79,27 +77,15 @@ class TextStoryPostSendRepository {
}
val message = OutgoingMediaMessage(
recipient,
serializeTextStoryState(textStoryPostCreationState),
emptyList(),
if (recipient.isDistributionList) distributionListSentTimestamp else System.currentTimeMillis(),
-1,
0,
false,
ThreadTable.DistributionTypes.DEFAULT,
storyType.toTextStoryType(),
null,
false,
null,
emptyList(),
listOfNotNull(linkPreview),
emptyList(),
mutableSetOf(),
mutableSetOf(),
null
recipient = recipient,
body = serializeTextStoryState(textStoryPostCreationState),
timestamp = if (recipient.isDistributionList) distributionListSentTimestamp else System.currentTimeMillis(),
storyType = storyType.toTextStoryType(),
previews = listOfNotNull(linkPreview),
isSecure = true
)
messages.add(OutgoingSecureMediaMessage(message))
messages.add(message)
ThreadUtil.sleep(5)
}