Refresh realm before updating badge count

This commit is contained in:
moezbhatti
2019-08-30 17:50:40 +02:00
parent b2708a3654
commit f92afde645
@@ -91,12 +91,14 @@ class MessageRepositoryImpl @Inject constructor(
} }
override fun getUnreadCount(): Long { override fun getUnreadCount(): Long {
return Realm.getDefaultInstance() return Realm.getDefaultInstance().use { realm ->
.where(Conversation::class.java) realm.refresh()
.equalTo("archived", false) realm.where(Conversation::class.java)
.equalTo("blocked", false) .equalTo("archived", false)
.equalTo("read", false) .equalTo("blocked", false)
.count() .equalTo("read", false)
.count()
}
} }
override fun getPart(id: Long): MmsPart? { override fun getPart(id: Long): MmsPart? {
@@ -351,13 +353,13 @@ class MessageRepositoryImpl @Inject constructor(
// Insert the message to the native content provider // Insert the message to the native content provider
val values = contentValuesOf( val values = contentValuesOf(
Telephony.Sms.ADDRESS to address, Telephony.Sms.ADDRESS to address,
Telephony.Sms.BODY to body, Telephony.Sms.BODY to body,
Telephony.Sms.DATE to System.currentTimeMillis(), Telephony.Sms.DATE to System.currentTimeMillis(),
Telephony.Sms.READ to true, Telephony.Sms.READ to true,
Telephony.Sms.SEEN to true, Telephony.Sms.SEEN to true,
Telephony.Sms.TYPE to Telephony.Sms.MESSAGE_TYPE_OUTBOX, Telephony.Sms.TYPE to Telephony.Sms.MESSAGE_TYPE_OUTBOX,
Telephony.Sms.THREAD_ID to threadId Telephony.Sms.THREAD_ID to threadId
) )
if (prefs.canUseSubId.get()) { if (prefs.canUseSubId.get()) {
@@ -406,9 +408,9 @@ class MessageRepositoryImpl @Inject constructor(
// Insert the message to the native content provider // Insert the message to the native content provider
val values = contentValuesOf( val values = contentValuesOf(
Telephony.Sms.ADDRESS to address, Telephony.Sms.ADDRESS to address,
Telephony.Sms.BODY to body, Telephony.Sms.BODY to body,
Telephony.Sms.DATE_SENT to sentTime Telephony.Sms.DATE_SENT to sentTime
) )
if (prefs.canUseSubId.get()) { if (prefs.canUseSubId.get()) {