Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Deleted) #324

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions app/src/main/kotlin/org/fossify/messages/messaging/Messaging.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import org.fossify.messages.messaging.SmsException.Companion.ERROR_PERSISTING_ME
import org.fossify.messages.messaging.SmsException.Companion.ERROR_SENDING_MESSAGE
import org.fossify.messages.models.Attachment

@Deprecated("TODO: Move/rewrite messaging config code into the app.")
fun Context.getSendMessageSettings(): Settings {
val settings = Settings()
settings.useSystemSending = true
Expand All @@ -32,6 +31,23 @@ fun Context.isLongMmsMessage(text: String, settings: Settings = getSendMessageSe
return numPages > settings.sendLongAsMmsAfter && settings.sendLongAsMms
}

fun Context.sendMmsMessagesSeparately(
text: String,
addresses: List<String>,
attachments: List<Attachment>,
settings: Settings,
messageId: Long?
) {
val messagingUtils = messagingUtils
val lastIndex = attachments.lastIndex
if (attachments.size > 1) {
for (i in 0 until lastIndex) {
messagingUtils.sendMmsMessage("", addresses, attachments[i], settings, messageId)
}
}
messagingUtils.sendMmsMessage(text, addresses, attachments[lastIndex], settings, messageId)
}

/** Sends the message using the in-app SmsManager API wrappers if it's an SMS or using android-smsmms for MMS. */
fun Context.sendMessageCompat(
text: String,
Expand All @@ -49,18 +65,8 @@ fun Context.sendMessageCompat(
val isMms = attachments.isNotEmpty() || isLongMmsMessage(text, settings)
|| addresses.size > 1 && settings.group
if (isMms) {
// 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) {
for (i in 0 until lastIndex) {
val attachment = attachments[i]
messagingUtils.sendMmsMessage("", addresses, attachment, settings, messageId)
}
}

val lastAttachment = attachments[lastIndex]
messagingUtils.sendMmsMessage(text, addresses, lastAttachment, settings, messageId)
sendMmsMessagesSeparately(text, addresses, attachments, settings, messageId)
} else {
messagingUtils.sendMmsMessage(text, addresses, null, settings, messageId)
}
Expand All @@ -79,12 +85,10 @@ fun Context.sendMessageCompat(
id = R.string.empty_destination_address,
length = LENGTH_LONG
)

ERROR_PERSISTING_MESSAGE -> toast(
id = R.string.unable_to_save_message,
length = LENGTH_LONG
)

ERROR_SENDING_MESSAGE -> toast(
msg = getString(R.string.unknown_error_occurred_sending_message, e.errorCode),
length = LENGTH_LONG
Expand Down