Don't show notification for active conversation, improve messaging performance

Previously, the app would mark the conversation read every time a message was received. Now, when we're receiving a message, we can see which conversation is open (if any), and mark it read during the inital write. Now we don't need to query and do another transaction for marking read
This commit is contained in:
Moez Bhatti
2018-09-05 17:51:53 -04:00
parent 8c01ef6612
commit 957a1ad1d4
7 changed files with 71 additions and 18 deletions
@@ -0,0 +1,19 @@
package com.moez.QKSMS.manager
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class ActiveConversationManagerImpl @Inject constructor() : ActiveConversationManager {
private var threadId: Long? = null
override fun setActiveConversation(threadId: Long?) {
this.threadId = threadId
}
override fun getActiveConversation(): Long? {
return threadId
}
}
@@ -36,6 +36,7 @@ import com.klinker.android.send_message.StripAccents
import com.klinker.android.send_message.Transaction
import com.moez.QKSMS.compat.TelephonyCompat
import com.moez.QKSMS.extensions.anyOf
import com.moez.QKSMS.manager.ActiveConversationManager
import com.moez.QKSMS.manager.KeyManager
import com.moez.QKSMS.model.Attachment
import com.moez.QKSMS.model.Conversation
@@ -57,6 +58,7 @@ import javax.inject.Singleton
@Singleton
class MessageRepositoryImpl @Inject constructor(
private val activeConversationManager: ActiveConversationManager,
private val context: Context,
private val messageIds: KeyManager,
private val imageRepository: ImageRepository,
@@ -351,6 +353,7 @@ class MessageRepositoryImpl @Inject constructor(
threadId = TelephonyCompat.getOrCreateThreadId(context, address)
boxId = Telephony.Sms.MESSAGE_TYPE_INBOX
type = "sms"
read = activeConversationManager.getActiveConversation() == threadId
}
val realm = Realm.getDefaultInstance()
var managedMessage: Message? = null