2022-03-28 23:43:42 +00:00
|
|
|
package org.thoughtcrime.securesms.database
|
|
|
|
|
2022-07-01 16:17:27 +00:00
|
|
|
import org.thoughtcrime.securesms.database.model.ParentStoryId
|
2022-03-28 23:43:42 +00:00
|
|
|
import org.thoughtcrime.securesms.database.model.StoryType
|
2022-05-16 13:24:48 +00:00
|
|
|
import org.thoughtcrime.securesms.database.model.databaseprotos.GiftBadge
|
2022-04-01 18:03:31 +00:00
|
|
|
import org.thoughtcrime.securesms.mms.IncomingMediaMessage
|
2022-03-28 23:43:42 +00:00
|
|
|
import org.thoughtcrime.securesms.mms.OutgoingMediaMessage
|
2022-07-13 17:51:36 +00:00
|
|
|
import org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage
|
2022-03-28 23:43:42 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient
|
2022-04-01 18:03:31 +00:00
|
|
|
import java.util.Optional
|
2022-03-28 23:43:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper methods for inserting an MMS message into the MMS table.
|
|
|
|
*/
|
|
|
|
object MmsHelper {
|
|
|
|
|
|
|
|
fun insert(
|
|
|
|
recipient: Recipient = Recipient.UNKNOWN,
|
|
|
|
body: String = "body",
|
|
|
|
sentTimeMillis: Long = System.currentTimeMillis(),
|
|
|
|
subscriptionId: Int = -1,
|
|
|
|
expiresIn: Long = 0,
|
|
|
|
viewOnce: Boolean = false,
|
|
|
|
distributionType: Int = ThreadDatabase.DistributionTypes.DEFAULT,
|
|
|
|
threadId: Long = 1,
|
2022-05-16 13:24:48 +00:00
|
|
|
storyType: StoryType = StoryType.NONE,
|
2022-07-01 16:17:27 +00:00
|
|
|
parentStoryId: ParentStoryId? = null,
|
|
|
|
isStoryReaction: Boolean = false,
|
2022-07-13 17:51:36 +00:00
|
|
|
giftBadge: GiftBadge? = null,
|
|
|
|
secure: Boolean = true
|
2022-03-28 23:43:42 +00:00
|
|
|
): Long {
|
|
|
|
val message = OutgoingMediaMessage(
|
|
|
|
recipient,
|
|
|
|
body,
|
|
|
|
emptyList(),
|
|
|
|
sentTimeMillis,
|
|
|
|
subscriptionId,
|
|
|
|
expiresIn,
|
|
|
|
viewOnce,
|
|
|
|
distributionType,
|
|
|
|
storyType,
|
2022-07-01 16:17:27 +00:00
|
|
|
parentStoryId,
|
|
|
|
isStoryReaction,
|
2022-03-28 23:43:42 +00:00
|
|
|
null,
|
|
|
|
emptyList(),
|
|
|
|
emptyList(),
|
|
|
|
emptyList(),
|
|
|
|
emptySet(),
|
2022-05-06 13:01:14 +00:00
|
|
|
emptySet(),
|
2022-05-16 13:24:48 +00:00
|
|
|
giftBadge
|
2022-07-13 17:51:36 +00:00
|
|
|
).let {
|
|
|
|
if (secure) OutgoingSecureMediaMessage(it) else it
|
|
|
|
}
|
2022-03-28 23:43:42 +00:00
|
|
|
|
|
|
|
return insert(
|
|
|
|
message = message,
|
2022-05-06 13:01:14 +00:00
|
|
|
threadId = threadId
|
2022-03-28 23:43:42 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun insert(
|
|
|
|
message: OutgoingMediaMessage,
|
|
|
|
threadId: Long
|
|
|
|
): Long {
|
|
|
|
return SignalDatabase.mms.insertMessageOutbox(message, threadId, false, GroupReceiptDatabase.STATUS_UNKNOWN, null)
|
|
|
|
}
|
2022-04-01 18:03:31 +00:00
|
|
|
|
|
|
|
fun insert(
|
|
|
|
message: IncomingMediaMessage,
|
|
|
|
threadId: Long
|
|
|
|
): Optional<MessageDatabase.InsertResult> {
|
|
|
|
return SignalDatabase.mms.insertSecureDecryptedMessageInbox(message, threadId)
|
|
|
|
}
|
2022-03-28 23:43:42 +00:00
|
|
|
}
|