Implement deletion of non-existent conversations
This commit is contained in:
@@ -85,6 +85,15 @@ class CachedChatDatabase (private val realmConfig: RealmConfiguration) {
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteConversations(conversations: List<ModelConversation>) = realm.writeBlocking {
|
||||
conversations.forEach { inConversation ->
|
||||
val conversation = getConversationByGuid(inConversation.guid)
|
||||
findLatest(conversation)?.let {
|
||||
delete(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun fetchConversations(): List<ModelConversation> {
|
||||
val items = realm.query(Conversation::class).find()
|
||||
return items.map { it.toConversation() }
|
||||
|
||||
@@ -121,10 +121,11 @@ class ChatRepository(
|
||||
Log.d(REPO_LOG, "Synchronizing conversations")
|
||||
|
||||
// Sync conversations
|
||||
val conversations = fetchConversations()
|
||||
database.writeConversations(conversations)
|
||||
val serverConversations = fetchConversations()
|
||||
val deletedConversations = conversations.minus(serverConversations)
|
||||
|
||||
// TODO: Delete non-existent conversations.
|
||||
database.deleteConversations(deletedConversations)
|
||||
database.writeConversations(serverConversations)
|
||||
|
||||
// Sync top N number of conversations' message content
|
||||
Log.d(REPO_LOG, "Synchronizing messages")
|
||||
|
||||
Reference in New Issue
Block a user