From 98261cdf451df5d4377ffa3f4bd2c2b5e934b33e Mon Sep 17 00:00:00 2001
From: ialokim <ialokim@mailbox.org>
Date: Wed, 10 Nov 2021 22:17:33 +0100
Subject: [PATCH] retain selected contact and message draft on switching away
 from private messages

---
 .../briar/desktop/contact/ContactListViewModel.kt           | 6 ------
 .../briar/desktop/conversation/ConversationViewModel.kt     | 4 ++++
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/main/kotlin/org/briarproject/briar/desktop/contact/ContactListViewModel.kt b/src/main/kotlin/org/briarproject/briar/desktop/contact/ContactListViewModel.kt
index 0617d92f2f..09029da0ca 100644
--- a/src/main/kotlin/org/briarproject/briar/desktop/contact/ContactListViewModel.kt
+++ b/src/main/kotlin/org/briarproject/briar/desktop/contact/ContactListViewModel.kt
@@ -33,12 +33,6 @@ constructor(
         loadContacts()
     }
 
-    override fun onCleared() {
-        super.onCleared()
-        // todo: also reset filterBy?
-        _selectedContactId.value = null
-    }
-
     private val _filterBy = mutableStateOf("")
     private val _selectedContactId = mutableStateOf<ContactId?>(null)
 
diff --git a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationViewModel.kt b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationViewModel.kt
index 97d7a96a76..3092b4e8a1 100644
--- a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationViewModel.kt
+++ b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationViewModel.kt
@@ -62,6 +62,9 @@ constructor(
     val newMessage: State<String> = _newMessage
 
     fun setContactId(id: ContactId) {
+        if (_contactId.value == id)
+            return
+
         _contactId.value = id
         _contactItem.value = ContactItem(
             contactManager.getContact(id),
@@ -69,6 +72,7 @@ constructor(
             conversationManager.getGroupCount(id),
         )
         loadMessages()
+        setNewMessage("")
     }
 
     fun setNewMessage(msg: String) {
-- 
GitLab