insert messages in a local db at fetching
This commit is contained in:
parent
633f7cf5c0
commit
e357b4a659
3 changed files with 20 additions and 2 deletions
|
|
@ -105,6 +105,13 @@ fun Context.getMessages(threadId: Int): ArrayList<Message> {
|
|||
messages = messages.filter { it.participants.isNotEmpty() }
|
||||
.sortedWith(compareBy<Message> { it.date }.thenBy { it.id }).toMutableList() as ArrayList<Message>
|
||||
|
||||
// use a separate thread for saving messages in a db
|
||||
Thread {
|
||||
messages.chunked(30).forEach { currentMessages ->
|
||||
messagesDB.insertMessages(*currentMessages.toTypedArray())
|
||||
}
|
||||
}.start()
|
||||
|
||||
return messages
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue