Send MMS attachments separately

If the message contains text, it is sent with the last attachment.
This commit is contained in:
Naveen 2023-02-19 03:03:01 +05:30
parent 8158531315
commit c931eb0171
2 changed files with 13 additions and 3 deletions

View File

@ -1228,8 +1228,9 @@ class ThreadActivity : SimpleActivity() {
sendMessageCompat(text, addresses, subscriptionId, attachments) sendMessageCompat(text, addresses, subscriptionId, attachments)
ensureBackgroundThread { ensureBackgroundThread {
val messageIds = messages.map { it.id } val messageIds = messages.map { it.id }
val message = getMessages(threadId, getImageResolutions = true, limit = 1).firstOrNull { it.id !in messageIds } val messages = getMessages(threadId, getImageResolutions = true, limit = maxOf(1, attachments.size))
if (message != null) { .filter { it.id !in messageIds }
for (message in messages) {
insertOrUpdateMessage(message) insertOrUpdateMessage(message)
} }
} }

View File

@ -40,7 +40,16 @@ fun Context.sendMessageCompat(text: String, addresses: List<String>, subId: Int?
val isMms = attachments.isNotEmpty() || isLongMmsMessage(text, settings) || addresses.size > 1 && settings.group val isMms = attachments.isNotEmpty() || isLongMmsMessage(text, settings) || addresses.size > 1 && settings.group
if (isMms) { if (isMms) {
messagingUtils.sendMmsMessage(text, addresses, attachments, settings) // we send all MMS attachments separately to reduces the chances of hitting provider MMS limit.
if (attachments.size > 1) {
for (i in 0 until attachments.lastIndex - 1) {
val attachment = attachments[i]
messagingUtils.sendMmsMessage("", addresses, listOf(attachment), settings)
}
}
val lastAttachment = attachments[attachments.lastIndex]
messagingUtils.sendMmsMessage(text, addresses, listOf(lastAttachment), settings)
} else { } else {
try { try {
messagingUtils.sendSmsMessage(text, addresses.toSet(), settings.subscriptionId, settings.deliveryReports) messagingUtils.sendSmsMessage(text, addresses.toSet(), settings.subscriptionId, settings.deliveryReports)