Application was always picking first participant when tapping on avatars in conversations. It was also using first participant for MMS notifications. This stores sender's phone number in the database, so it can be used to look up correct participant in the list of participants. If matching on number fails, matching on name is attempted. If both of these fail, it falls back to previous behavior, which is just picking the first participant. This may also be connected to #32, but I am not sure, since this should just be related to behavior when tapping on avatars. Mixing up avatars in the conversation should be a different issue. This closes #433, closes #500, closes #384
53 lines
2.2 KiB
Kotlin
53 lines
2.2 KiB
Kotlin
package com.simplemobiletools.smsmessenger.receivers
|
|
|
|
import android.content.Context
|
|
import android.net.Uri
|
|
import android.os.Handler
|
|
import android.os.Looper
|
|
import com.bumptech.glide.Glide
|
|
import com.simplemobiletools.commons.extensions.isNumberBlocked
|
|
import com.simplemobiletools.commons.extensions.normalizePhoneNumber
|
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
|
import com.simplemobiletools.smsmessenger.R
|
|
import com.simplemobiletools.smsmessenger.extensions.*
|
|
import com.simplemobiletools.smsmessenger.helpers.refreshMessages
|
|
|
|
// more info at https://github.com/klinker41/android-smsmms
|
|
class MmsReceiver : com.klinker.android.send_message.MmsReceivedReceiver() {
|
|
|
|
override fun isAddressBlocked(context: Context, address: String): Boolean {
|
|
val normalizedAddress = address.normalizePhoneNumber()
|
|
return context.isNumberBlocked(normalizedAddress)
|
|
}
|
|
|
|
override fun onMessageReceived(context: Context, messageUri: Uri) {
|
|
val mms = context.getLatestMMS() ?: return
|
|
val address = mms.getSender()?.phoneNumbers?.first()?.normalizedNumber ?: ""
|
|
|
|
val size = context.resources.getDimension(R.dimen.notification_large_icon_size).toInt()
|
|
ensureBackgroundThread {
|
|
val glideBitmap = try {
|
|
Glide.with(context)
|
|
.asBitmap()
|
|
.load(mms.attachment!!.attachments.first().getUri())
|
|
.centerCrop()
|
|
.into(size, size)
|
|
.get()
|
|
} catch (e: Exception) {
|
|
null
|
|
}
|
|
|
|
Handler(Looper.getMainLooper()).post {
|
|
context.showReceivedMessageNotification(mms.id, address, mms.body, mms.threadId, glideBitmap)
|
|
val conversation = context.getConversations(mms.threadId).firstOrNull() ?: return@post
|
|
ensureBackgroundThread {
|
|
context.insertOrUpdateConversation(conversation)
|
|
context.updateUnreadCountBadge(context.conversationsDB.getUnreadConversations())
|
|
refreshMessages()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
override fun onError(context: Context, error: String) {}
|
|
}
|