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