mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 11:38:51 +01:00
Ensure that MMS have unique keys
This commit is contained in:
@@ -22,12 +22,16 @@ import android.content.Context
|
||||
import android.database.Cursor
|
||||
import android.net.Uri
|
||||
import android.provider.Telephony.*
|
||||
import common.util.Keys
|
||||
import data.model.Message
|
||||
import data.model.Message.DeliveryStatus
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
class CursorToMessage @Inject constructor(val context: Context) : Mapper<Pair<Cursor, CursorToMessage.MessageColumns>, Message> {
|
||||
class CursorToMessage @Inject constructor(
|
||||
private val context: Context,
|
||||
private val keys: Keys
|
||||
) : Mapper<Pair<Cursor, CursorToMessage.MessageColumns>, Message> {
|
||||
|
||||
override fun map(from: Pair<Cursor, MessageColumns>): Message {
|
||||
val cursor = from.first
|
||||
@@ -39,7 +43,8 @@ class CursorToMessage @Inject constructor(val context: Context) : Mapper<Pair<Cu
|
||||
else -> cursor.getString(columnsMap.msgType)
|
||||
}
|
||||
|
||||
id = cursor.getLong(columnsMap.msgId)
|
||||
id = keys.newId()
|
||||
contentId = cursor.getLong(columnsMap.msgId)
|
||||
|
||||
when (type) {
|
||||
"sms" -> {
|
||||
|
||||
@@ -30,6 +30,12 @@ open class Message : RealmObject() {
|
||||
enum class AttachmentType { TEXT, IMAGE, VIDEO, AUDIO, SLIDESHOW, NOT_LOADED }
|
||||
|
||||
@PrimaryKey var id: Long = 0
|
||||
|
||||
// The MMS-SMS content provider returns messages where duplicate ids can exist. This is because
|
||||
// SMS and MMS are stored in separate tables. We can't use these ids as our realm message id
|
||||
// since it's our primary key for the single message object, so we'll store the original id in
|
||||
// case we need to access the original message item in the content provider
|
||||
var contentId: Long = 0
|
||||
var threadId: Long = 0
|
||||
var address: String = ""
|
||||
var boxId: Int = 0
|
||||
@@ -70,7 +76,7 @@ open class Message : RealmObject() {
|
||||
|
||||
fun getUri(): Uri {
|
||||
val baseUri = if (isMms()) Mms.CONTENT_URI else Sms.CONTENT_URI
|
||||
return ContentUris.withAppendedId(baseUri, id)
|
||||
return ContentUris.withAppendedId(baseUri, contentId)
|
||||
}
|
||||
|
||||
fun isMms(): Boolean = type == "mms"
|
||||
|
||||
Reference in New Issue
Block a user