mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 19:38:52 +01:00
Load parts during message sync
This commit is contained in:
@@ -21,17 +21,21 @@ package data.mapper
|
||||
import android.content.Context
|
||||
import android.database.Cursor
|
||||
import android.net.Uri
|
||||
import android.provider.Telephony
|
||||
import android.provider.Telephony.*
|
||||
import com.google.android.mms.pdu_alt.PduHeaders
|
||||
import common.util.Keys
|
||||
import common.util.extensions.map
|
||||
import data.model.Message
|
||||
import data.model.MmsPart
|
||||
import timber.log.Timber
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class CursorToMessage @Inject constructor(
|
||||
private val context: Context,
|
||||
private val keys: Keys
|
||||
private val keys: Keys,
|
||||
private val cursorToPart: CursorToPart
|
||||
) : Mapper<Pair<Cursor, CursorToMessage.MessageColumns>, Message> {
|
||||
|
||||
override fun map(from: Pair<Cursor, MessageColumns>): Message {
|
||||
@@ -78,7 +82,9 @@ class CursorToMessage @Inject constructor(
|
||||
mmsStatus = cursor.getInt(columnsMap.mmsStatus)
|
||||
subject = cursor.getString(columnsMap.mmsSubject) ?: ""
|
||||
textContentType = ""
|
||||
attachmentType = Message.AttachmentType.NOT_LOADED
|
||||
attachmentType = Message.AttachmentType.NOT_LOADED
|
||||
|
||||
parts.addAll(getMmsParts(contentId))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,6 +110,12 @@ class CursorToMessage @Inject constructor(
|
||||
return ""
|
||||
}
|
||||
|
||||
private fun getMmsParts(contentId: Long): List<MmsPart> {
|
||||
return context.contentResolver.query(CursorToPart.CONTENT_URI, null,
|
||||
"${Telephony.Mms.Part.MSG_ID} = ?", arrayOf(contentId.toString()), null)
|
||||
.map { cursorToPart.map(it) }
|
||||
}
|
||||
|
||||
companion object {
|
||||
val URI = Uri.parse("content://mms-sms/complete-conversations")
|
||||
val PROJECTION = arrayOf(
|
||||
|
||||
@@ -142,20 +142,6 @@ class MessageRepository @Inject constructor(
|
||||
.findAllSorted("date")
|
||||
}
|
||||
|
||||
fun loadParts(id: Long) {
|
||||
Realm.getDefaultInstance()?.use { realm ->
|
||||
realm.where(Message::class.java).equalTo("id", id).findFirst()?.let { message ->
|
||||
realm.executeTransaction {
|
||||
val parts = realm.copyToRealmOrUpdate(context.contentResolver.query(CursorToPart.CONTENT_URI, null,
|
||||
"${Telephony.Mms.Part.MSG_ID} = ?", arrayOf(message.contentId.toString()), null)
|
||||
.map { cursorToPart.map(it) })
|
||||
|
||||
message.parts = RealmList<MmsPart>().apply { addAll(parts) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the list of messages which should be shown in the notification
|
||||
* for a given conversation
|
||||
|
||||
Reference in New Issue
Block a user