got editing down

Signed-off-by: rapterjet2004 <juliuslinus1@gmail.com>
This commit is contained in:
rapterjet2004 2024-09-27 10:14:34 -05:00 committed by Marcel Hibbe
parent 8cd0983088
commit 411a4f1dce
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
2 changed files with 15 additions and 2 deletions

View File

@ -3666,7 +3666,9 @@ class ChatActivity :
}
override fun editTemporaryMessage(id: Int, newMessage: String) {
// TODO update adapter item and call viewModel to persist data
messageInputViewModel.editQueuedMessage(roomToken, id, newMessage)
adapter?.notifyDataSetChanged() // TODO optimize this
}
override fun deleteTemporaryMessage(id: Int) {

View File

@ -49,7 +49,7 @@ class MessageInputViewModel @Inject constructor(
data class QueuedMessage(
val id: Int,
val message: CharSequence? = null,
var message: CharSequence? = null,
val displayName: String? = null,
val replyTo: Int? = null,
val sendWithoutNotification: Boolean? = null
@ -303,6 +303,17 @@ class MessageInputViewModel @Inject constructor(
_messageQueueSizeFlow.tryEmit(queue.size)
}
fun editQueuedMessage(roomToken: String, id: Int, newMessage: String) {
val queue = dataStore.getMessageQueue(roomToken)
for (qMsg in queue) {
if (qMsg.id == id) {
qMsg.message = newMessage
break
}
}
dataStore.saveMessageQueue(roomToken, queue)
}
companion object {
private val TAG = MessageInputViewModel::class.java.simpleName
private const val DELAY_BETWEEN_QUEUED_MESSAGES: Long = 100