Merge pull request #619 from Naveen3Singh/sms_mms_improvements

Fix MMS issues
This commit is contained in:
Tibor Kaputa
2023-03-25 08:39:01 +01:00
committed by GitHub
2 changed files with 29 additions and 25 deletions

View File

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

View File

@@ -133,12 +133,11 @@ class MessagingUtils(val context: Context) {
} }
@Deprecated("TODO: Move/rewrite MMS code into the app.") @Deprecated("TODO: Move/rewrite MMS code into the app.")
fun sendMmsMessage(text: String, addresses: List<String>, attachments: List<Attachment>, settings: Settings) { fun sendMmsMessage(text: String, addresses: List<String>, attachment: Attachment?, settings: Settings) {
val transaction = Transaction(context, settings) val transaction = Transaction(context, settings)
val message = Message(text, addresses.toTypedArray()) val message = Message(text, addresses.toTypedArray())
if (attachments.isNotEmpty()) { if (attachment != null) {
for (attachment in attachments) {
try { try {
val uri = attachment.getUri() val uri = attachment.getUri()
context.contentResolver.openInputStream(uri)?.use { context.contentResolver.openInputStream(uri)?.use {
@@ -157,7 +156,6 @@ class MessagingUtils(val context: Context) {
context.showErrorToast(e.localizedMessage ?: context.getString(R.string.unknown_error_occurred)) context.showErrorToast(e.localizedMessage ?: context.getString(R.string.unknown_error_occurred))
} }
} }
}
val mmsSentIntent = Intent(context, MmsSentReceiver::class.java) val mmsSentIntent = Intent(context, MmsSentReceiver::class.java)
transaction.setExplicitBroadcastForSentMms(mmsSentIntent) transaction.setExplicitBroadcastForSentMms(mmsSentIntent)