Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7a8aea0f authored by Moez Bhatti's avatar Moez Bhatti
Browse files

Use RealmAdapter for conversation info media

parent 8f2415af
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@ class CursorToPartImpl @Inject constructor(private val context: Context) : Curso

    override fun map(from: Cursor) = MmsPart().apply {
        id = from.getLong(from.getColumnIndexOrThrow(Telephony.Mms.Part._ID))
        messageId = from.getLong(from.getColumnIndexOrThrow(Telephony.Mms.Part.MSG_ID))

        // Type will sometimes return null, resulting in a crash if we don't default to an empty string
        type = from.getString(from.getColumnIndexOrThrow(Telephony.Mms.Part.CONTENT_TYPE)) ?: ""
+7 −10
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import com.klinker.android.send_message.BroadcastUtils
import com.klinker.android.send_message.StripAccents
import io.reactivex.Flowable
import io.reactivex.Maybe
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import io.realm.Realm
@@ -50,7 +49,6 @@ import util.MessageUtils
import util.Preferences
import util.extensions.asFlowable
import util.extensions.asMaybe
import util.extensions.asObservable
import util.extensions.insertOrUpdate
import util.extensions.map
import javax.inject.Inject
@@ -207,15 +205,14 @@ class MessageRepositoryImpl @Inject constructor(
                .findFirst()
    }

    override fun getPartsForConversation(threadId: Long): Observable<List<MmsPart>> {
    override fun getPartsForConversation(threadId: Long): RealmResults<MmsPart> {
        return Realm.getDefaultInstance()
                .where(Message::class.java)
                .equalTo("threadId", threadId)
                .isNotEmpty("parts")
                .sort("date")
                .findAll()
                .asObservable()
                .map { messages -> messages.flatMap { it.parts } }
                .where(MmsPart::class.java)
                .equalTo("messages.threadId", threadId)
                .contains("type", "image/")
                .isNotEmpty("image")
                .sort("id", Sort.DESCENDING)
                .findAllAsync()
    }

    /**
+5 −1
Original line number Diff line number Diff line
@@ -19,15 +19,19 @@
package model

import io.realm.RealmObject
import io.realm.RealmResults
import io.realm.annotations.LinkingObjects
import io.realm.annotations.PrimaryKey

open class MmsPart : RealmObject() {

    @PrimaryKey var id: Long = 0
    var messageId: Long = 0
    var type: String = ""

    var text: String? = null
    var image: String? = null

    @LinkingObjects("parts")
    val messages: RealmResults<Message>? = null

}
 No newline at end of file
+1 −2
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ package repository

import io.reactivex.Flowable
import io.reactivex.Maybe
import io.reactivex.Observable
import io.realm.RealmResults
import model.Conversation
import model.Message
@@ -56,7 +55,7 @@ interface MessageRepository {

    fun getPart(id: Long): MmsPart?

    fun getPartsForConversation(threadId: Long): Observable<List<MmsPart>>
    fun getPartsForConversation(threadId: Long): RealmResults<MmsPart>

    /**
     * Retrieves the list of messages which should be shown in the notification
+1 −1
Original line number Diff line number Diff line
@@ -94,7 +94,7 @@ class ConversationInfoActivity : QkThemedActivity<ConversationInfoViewModel>(),
            false -> R.string.info_block
        })

        mediaAdapter.data = state.media
        mediaAdapter.updateData(state.media)
    }

    override fun showDeleteDialog() {
Loading