Merge pull request #497 from Naveen3Singh/persist_sub_id

Persist subscription id when sending sms messages
This commit is contained in:
Tibor Kaputa 2022-11-21 20:51:21 +01:00 committed by GitHub
commit 0a9cc5f9fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 25 deletions

View File

@ -1116,7 +1116,6 @@ class ThreadActivity : SimpleActivity() {
val messageIds = messages.map { it.id }
val message = getMessages(threadId, getImageResolutions = true, limit = 1).firstOrNull { it.id !in messageIds }
if (message != null) {
maybeUpdateMessageSubId(message)
insertOrUpdateMessage(message)
}
}
@ -1306,7 +1305,6 @@ class ThreadActivity : SimpleActivity() {
}
messages.filter { !it.isScheduled && !it.isReceivedMessage() && it.id > lastMaxId }.forEach { latestMessage ->
maybeUpdateMessageSubId(latestMessage)
messagesDB.insertOrIgnore(latestMessage)
}
@ -1316,18 +1314,6 @@ class ThreadActivity : SimpleActivity() {
}
}
@SuppressLint("MissingPermission")
private fun maybeUpdateMessageSubId(message: Message) {
// subscriptionIds seem to be not filled out at sending with multiple SIM cards, so fill it manually
if ((subscriptionManagerCompat().activeSubscriptionInfoList?.size ?: 0) > 1) {
val subscriptionId = availableSIMCards.getOrNull(currentSIMCardIndex)?.subscriptionId
if (subscriptionId != null) {
updateMessageSubscriptionId(message.id, subscriptionId)
message.subscriptionId = subscriptionId
}
}
}
private fun isMmsMessage(text: String): Boolean {
val isGroupMms = participants.size > 1 && config.sendGroupMessageMMS
val isLongMmsMessage = isLongMmsMessage(text) && config.sendLongMessageMMS

View File

@ -112,7 +112,7 @@ fun Context.getMessages(
val thread = cursor.getLongValue(Sms.THREAD_ID)
val subscriptionId = cursor.getIntValue(Sms.SUBSCRIPTION_ID)
val status = cursor.getIntValue(Sms.STATUS)
val participants = senderNumber.split(getAddressSeparator().toRegex()).map { number ->
val participants = senderNumber.split(getAddressSeparator()).map { number ->
val phoneNumber = PhoneNumber(number, 0, "", number)
val participantPhoto = getNameAndPhotoFromPhoneNumber(number)
SimpleContact(0, 0, participantPhoto.name, photoUri, arrayListOf(phoneNumber), ArrayList(), ArrayList())
@ -676,16 +676,6 @@ fun Context.updateMessageStatus(id: Long, status: Int) {
contentResolver.update(uri, contentValues, selection, selectionArgs)
}
fun Context.updateMessageSubscriptionId(messageId: Long, subscriptionId: Int) {
val uri = Sms.CONTENT_URI
val contentValues = ContentValues().apply {
put(Sms.SUBSCRIPTION_ID, subscriptionId)
}
val selection = "${Sms._ID} = ?"
val selectionArgs = arrayOf(messageId.toString())
contentResolver.update(uri, contentValues, selection, selectionArgs)
}
fun Context.updateUnreadCountBadge(conversations: List<Conversation>) {
val unreadCount = conversations.count { !it.read }
if (unreadCount == 0) {