properly store sent messages in local db

This commit is contained in:
tibbi 2020-12-21 23:17:20 +01:00
parent 733428da38
commit e116c5baa8
2 changed files with 9 additions and 0 deletions

View File

@ -704,7 +704,13 @@ class ThreadActivity : SimpleActivity() {
notificationManager.cancel(threadId.hashCode()) notificationManager.cancel(threadId.hashCode())
} }
val lastMaxId = messages.maxByOrNull { it.id }?.id ?: 0L
messages = getMessages(threadId) messages = getMessages(threadId)
messages.filter { !it.isReceivedMessage() && it.id > lastMaxId }.forEach {
messagesDB.insertOrIgnore(it)
}
setupAdapter() setupAdapter()
} }
} }

View File

@ -11,6 +11,9 @@ interface MessagesDao {
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertOrUpdate(message: Message) fun insertOrUpdate(message: Message)
@Insert(onConflict = OnConflictStrategy.IGNORE)
fun insertOrIgnore(message: Message): Long
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertMessages(vararg message: Message) fun insertMessages(vararg message: Message)