forked from upstream-mirrors/quik
Load recipient instead of contact during sync
Improves sync speed by ~33%
This commit is contained in:
@@ -85,7 +85,7 @@ class NotificationManager @Inject constructor(
|
||||
.setStyle(style)
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 24 && conversation != null) {
|
||||
notification.addAction(getReplyAction(conversation.contacts[0]?.address.orEmpty(), conversation.id))
|
||||
notification.addAction(getReplyAction(conversation.recipients[0]?.address.orEmpty(), conversation.id))
|
||||
}
|
||||
|
||||
notificationManager.notify(threadId.toInt(), notification.build())
|
||||
|
||||
@@ -4,21 +4,18 @@ import android.database.Cursor
|
||||
import android.net.Uri
|
||||
import android.provider.Telephony.Threads
|
||||
import com.moez.QKSMS.data.model.Conversation
|
||||
import com.moez.QKSMS.data.repository.ContactRepository
|
||||
import io.reactivex.rxkotlin.toFlowable
|
||||
import com.moez.QKSMS.data.model.Recipient
|
||||
import javax.inject.Inject
|
||||
|
||||
class CursorToConversation @Inject constructor(private val contactsRepo: ContactRepository) : Mapper<Cursor, Conversation> {
|
||||
class CursorToConversation @Inject constructor() : Mapper<Cursor, Conversation> {
|
||||
|
||||
override fun map(from: Cursor): Conversation {
|
||||
return Conversation().apply {
|
||||
id = from.getLong(ID)
|
||||
|
||||
contacts.addAll(from.getString(RECIPIENT_IDS).split(" ").toFlowable()
|
||||
.map { id -> id.toLong() }
|
||||
.flatMap { id -> contactsRepo.getContact(id) }
|
||||
.filter { contact -> contact.recipientId != 0L }
|
||||
.blockingIterable())
|
||||
recipients.addAll(from.getString(RECIPIENT_IDS)
|
||||
.split(" ")
|
||||
.map { recipientId -> recipientId.toLong() }
|
||||
.map { recipientId -> Recipient().apply { id = recipientId } })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,14 +7,14 @@ import io.realm.annotations.PrimaryKey
|
||||
open class Conversation : RealmObject() {
|
||||
|
||||
@PrimaryKey var id: Long = 0
|
||||
var contacts: RealmList<Contact> = RealmList()
|
||||
var recipients: RealmList<Recipient> = RealmList()
|
||||
var archived: Boolean = false
|
||||
|
||||
fun getTitle(): String {
|
||||
var title = ""
|
||||
contacts.forEachIndexed { index, recipient ->
|
||||
title += if (recipient.name.isNotEmpty()) recipient.name else recipient.address
|
||||
if (index < contacts.size - 1) {
|
||||
recipients.forEachIndexed { index, recipient ->
|
||||
title += recipient.address
|
||||
if (index < recipients.size - 1) {
|
||||
title += ", "
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.moez.QKSMS.data.model
|
||||
|
||||
import io.realm.RealmObject
|
||||
import io.realm.annotations.PrimaryKey
|
||||
|
||||
open class Recipient : RealmObject() {
|
||||
|
||||
@PrimaryKey var id: Long = 0
|
||||
var address: String = ""
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import android.provider.Telephony
|
||||
import com.moez.QKSMS.common.util.extensions.asFlowable
|
||||
import com.moez.QKSMS.data.mapper.CursorToConversation
|
||||
import com.moez.QKSMS.data.mapper.CursorToMessage
|
||||
import com.moez.QKSMS.data.model.Recipient
|
||||
import com.moez.QKSMS.data.model.SyncLog
|
||||
import io.reactivex.Flowable
|
||||
import io.realm.Realm
|
||||
@@ -42,7 +43,6 @@ open class PartialSync @Inject constructor(
|
||||
}
|
||||
.map { contentResolver.query(CursorToConversation.URI, CursorToConversation.PROJECTION, "date >= ?", arrayOf(lastSync.toString()), "date desc") }
|
||||
.flatMap { cursor -> cursor.asFlowable().map { cursorToConversation.map(it) } }
|
||||
.distinct { conversation -> conversation.id }
|
||||
.doOnNext { conversation -> realm?.insertOrUpdate(conversation) }
|
||||
.map { conversation -> conversation.id }
|
||||
.map { threadId -> Uri.withAppendedPath(Telephony.MmsSms.CONTENT_CONVERSATIONS_URI, threadId.toString()) }
|
||||
@@ -54,10 +54,20 @@ open class PartialSync @Inject constructor(
|
||||
.takeWhile { message -> message.date >= lastSync }
|
||||
}
|
||||
.filter { message -> message.type == "sms" || message.type == "mms" }
|
||||
.distinct { message -> message.id }
|
||||
.doOnNext { message -> realm?.insertOrUpdate(message) }
|
||||
.count()
|
||||
.toFlowable()
|
||||
.map { contentResolver.query(Uri.parse("content://mms-sms/canonical-addresses"), null, null, null, null) }
|
||||
.flatMap { cursor -> cursor.asFlowable() }
|
||||
.map { cursor ->
|
||||
Recipient().apply {
|
||||
id = cursor.getLong(0)
|
||||
address = cursor.getString(1)
|
||||
}
|
||||
}
|
||||
.doOnNext { recipient -> realm?.insertOrUpdate(recipient)}
|
||||
.count()
|
||||
.toFlowable()
|
||||
.doOnNext {
|
||||
realm?.commitTransaction()
|
||||
realm?.close()
|
||||
|
||||
@@ -6,12 +6,11 @@ import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.data.model.Contact
|
||||
import io.realm.RealmList
|
||||
import kotlinx.android.synthetic.main.group_avatar_view.view.*
|
||||
|
||||
class GroupAvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : ConstraintLayout(context, attrs) {
|
||||
|
||||
var contacts: RealmList<Contact> = RealmList()
|
||||
var contacts: List<Contact> = ArrayList()
|
||||
set(value) {
|
||||
field = value
|
||||
updateView()
|
||||
|
||||
@@ -141,8 +141,8 @@ class ComposeViewModel(threadId: Long) : QkViewModel<ComposeView, ComposeState>(
|
||||
// Open the phone dialer if the call button is clicked
|
||||
intents += view.callIntent
|
||||
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||
.map { conversation -> conversation.contacts.first() }
|
||||
.map { contact -> contact.address }
|
||||
.map { conversation -> conversation.recipients.first() }
|
||||
.map { recipient -> recipient.address }
|
||||
.subscribe { address -> navigator.makePhoneCall(address) }
|
||||
|
||||
// Toggle the archived state of the conversation
|
||||
@@ -171,7 +171,7 @@ class ComposeViewModel(threadId: Long) : QkViewModel<ComposeView, ComposeState>(
|
||||
.map { body -> body.toString() }
|
||||
.withLatestFrom(conversation, { body, conversation ->
|
||||
val threadId = conversation.id
|
||||
val address = conversation.contacts.first()?.address.orEmpty()
|
||||
val address = conversation.recipients.first()?.address.orEmpty()
|
||||
sendMessage.execute(SendMessage.Params(threadId, address, body))
|
||||
newState { it.copy(editingMode = false, draft = "", canSend = false) }
|
||||
})
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.jakewharton.rxbinding2.view.RxView
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.DateFormatter
|
||||
import com.moez.QKSMS.data.model.Contact
|
||||
import com.moez.QKSMS.data.model.ConversationMessagePair
|
||||
import com.moez.QKSMS.data.repository.MessageRepository
|
||||
import com.moez.QKSMS.presentation.Navigator
|
||||
@@ -62,7 +63,7 @@ class ConversationsAdapter @Inject constructor(
|
||||
RxView.clicks(view).subscribe { navigator.showConversation(message.threadId) }
|
||||
RxView.longClicks(view).subscribe { longClicks.onNext(conversation.id) }
|
||||
|
||||
view.avatars.contacts = conversation.contacts
|
||||
view.avatars.contacts = conversation.recipients.map { recipient -> Contact().apply { address = recipient.address } }
|
||||
view.title.text = conversation.getTitle()
|
||||
view.date.text = dateFormatter.getConversationTimestamp(message.date)
|
||||
view.snippet.text = message.body
|
||||
|
||||
Reference in New Issue
Block a user