#591 - More accurate dates and snippets when syncing messages

This commit is contained in:
Moez Bhatti
2018-07-27 23:25:14 -04:00
parent 99f115d06b
commit 80e8a7e28d
@@ -41,6 +41,7 @@ import com.moez.QKSMS.util.tryOrNull
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.subjects.Subject
import io.realm.Realm
import io.realm.Sort
import javax.inject.Inject
import javax.inject.Singleton
@@ -126,6 +127,17 @@ class SyncRepositoryImpl @Inject constructor(
conversation?.name = data.name
}
realm.where(Message::class.java)
.sort("date", Sort.DESCENDING)
.distinctValues("threadId")
.findAll()
.forEach { message ->
val conversation = conversations.firstOrNull { conversation -> conversation.id == message.threadId }
conversation?.date = message.date
conversation?.snippet = message.getSummary()
conversation?.me = message.isMe()
}
realm.insertOrUpdate(conversations)
}