From 411a4f1dce91c80262385678186c07bd9d25b4a5 Mon Sep 17 00:00:00 2001 From: rapterjet2004 Date: Fri, 27 Sep 2024 10:14:34 -0500 Subject: [PATCH] got editing down Signed-off-by: rapterjet2004 --- .../java/com/nextcloud/talk/chat/ChatActivity.kt | 4 +++- .../talk/chat/viewmodels/MessageInputViewModel.kt | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt index 2f91c8158..6ac8ee528 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt @@ -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) { diff --git a/app/src/main/java/com/nextcloud/talk/chat/viewmodels/MessageInputViewModel.kt b/app/src/main/java/com/nextcloud/talk/chat/viewmodels/MessageInputViewModel.kt index 75a10a9c8..d52fd9368 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/viewmodels/MessageInputViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/viewmodels/MessageInputViewModel.kt @@ -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