From 35adc10f11cc2ddd0e63dfdbc1521d64596ab8d1 Mon Sep 17 00:00:00 2001
From: ialokim <ialokim@mailbox.org>
Date: Mon, 3 Jan 2022 09:57:36 +0100
Subject: [PATCH] don't reload messages after cancelled introduction dialog,
 some JavaDoc and variable renaming

---
 .../desktop/contact/ContactInfoDrawer.kt      |  2 +-
 .../conversation/ConversationItemView.kt      |  3 +
 .../ConversationMessageItemView.kt            |  3 +
 .../ConversationNoticeItemView.kt             |  3 +
 .../ConversationRequestItemView.kt            |  3 +
 .../conversation/ConversationScreen.kt        | 10 ++--
 .../conversation/ConversationVisitor.kt       | 56 +++++++++----------
 .../introduction/ContactDrawerMakeIntro.kt    |  6 +-
 8 files changed, 50 insertions(+), 36 deletions(-)

diff --git a/src/main/kotlin/org/briarproject/briar/desktop/contact/ContactInfoDrawer.kt b/src/main/kotlin/org/briarproject/briar/desktop/contact/ContactInfoDrawer.kt
index c7d7433540..6988c76f63 100644
--- a/src/main/kotlin/org/briarproject/briar/desktop/contact/ContactInfoDrawer.kt
+++ b/src/main/kotlin/org/briarproject/briar/desktop/contact/ContactInfoDrawer.kt
@@ -14,7 +14,7 @@ enum class ContactInfoDrawerState {
 @Composable
 fun ContactInfoDrawer(
     contactItem: ContactItem,
-    closeInfoDrawer: () -> Unit,
+    closeInfoDrawer: (reload: Boolean) -> Unit,
     drawerState: ContactInfoDrawerState
 ) {
     when (drawerState) {
diff --git a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationItemView.kt b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationItemView.kt
index d746990c38..6eccffeb5b 100644
--- a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationItemView.kt
+++ b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationItemView.kt
@@ -140,6 +140,9 @@ fun main() = preview {
     }
 }
 
+/**
+ * Base Composable for all kind of messages in private chats.
+ */
 @Composable
 fun ConversationItemView(
     item: ConversationItem,
diff --git a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationMessageItemView.kt b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationMessageItemView.kt
index 74833a0d07..b9ef25101f 100644
--- a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationMessageItemView.kt
+++ b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationMessageItemView.kt
@@ -39,6 +39,9 @@ fun main() = preview(
     )
 }
 
+/**
+ * Composable for normal private text messages.
+ */
 @Composable
 fun ConversationMessageItemView(m: ConversationMessageItem) {
     val textColor = if (m.isIncoming) MaterialTheme.colors.textPrimary else Color.White
diff --git a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationNoticeItemView.kt b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationNoticeItemView.kt
index fab635a35b..48dff66eb9 100644
--- a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationNoticeItemView.kt
+++ b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationNoticeItemView.kt
@@ -50,6 +50,9 @@ fun main() = preview(
     )
 }
 
+/**
+ * Composable for private messages containing a notice.
+ */
 @Composable
 fun ConversationNoticeItemView(m: ConversationNoticeItem) {
     val textColor = if (m.isIncoming) MaterialTheme.colors.textPrimary else Color.White
diff --git a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationRequestItemView.kt b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationRequestItemView.kt
index aab9ac9138..bca4e4827d 100644
--- a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationRequestItemView.kt
+++ b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationRequestItemView.kt
@@ -65,6 +65,9 @@ fun main() = preview(
     )
 }
 
+/**
+ * Composable for private messages containing a request to action.
+ */
 @Composable
 fun ConversationRequestItemView(
     m: ConversationRequestItem,
diff --git a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationScreen.kt b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationScreen.kt
index 1299e27b82..e10fe586a4 100644
--- a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationScreen.kt
+++ b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationScreen.kt
@@ -127,11 +127,13 @@ fun ConversationScreen(
             ) {
                 ContactInfoDrawer(
                     contactItem,
-                    closeInfoDrawer = {
+                    closeInfoDrawer = { reload ->
                         setInfoDrawer(false)
-                        // reload all messages to also show introduction message
-                        // todo: might be better to have an event to react to, also for (all) outgoing messages
-                        viewModel.reloadMessages()
+                        if (reload) {
+                            // reload all messages to also show introduction message
+                            // todo: might be better to have an event to react to, also for (all) outgoing messages
+                            viewModel.reloadMessages()
+                        }
                     },
                     contactDrawerState
                 )
diff --git a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationVisitor.kt b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationVisitor.kt
index d491cf6f14..6dde8f0f1b 100644
--- a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationVisitor.kt
+++ b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationVisitor.kt
@@ -43,6 +43,7 @@ internal class ConversationVisitor(
     @DatabaseExecutor
     override fun visitPrivateMessageHeader(h: PrivateMessageHeader): ConversationItem {
         val item = ConversationMessageItem(h)
+        // todo: handle attachments here
         if (h.hasText()) {
             item.text = loadMessageText(txn, h.id)
         } else {
@@ -52,23 +53,22 @@ internal class ConversationVisitor(
     }
 
     override fun visitBlogInvitationRequest(r: BlogInvitationRequest): ConversationItem {
-
         return if (r.isLocal)
             ConversationNoticeItem(
                 i18nF("blog.invitation.sent", r.name, contactName),
                 r
             )
         else {
-            val text = i18nF("blog.invitation.received", contactName, r.name)
+            val notice = i18nF("blog.invitation.received", contactName, r.name)
             // todo: add proper check for feature support
             if (false)
                 ConversationRequestItem(
-                    text,
+                    notice,
                     ConversationRequestItem.RequestType.BLOG, r
                 )
             else
                 ConversationNoticeItem(
-                    text + "\n" + i18n("unsupported_feature"),
+                    notice + "\n" + i18n("unsupported_feature"),
                     r
                 )
         }
@@ -76,7 +76,7 @@ internal class ConversationVisitor(
 
     override fun visitBlogInvitationResponse(r: BlogInvitationResponse): ConversationItem {
         return if (r.isLocal) {
-            val text = when {
+            val notice = when {
                 r.wasAccepted() ->
                     i18nF("blog.invitation.response.accepted.sent", contactName)
                 r.isAutoDecline ->
@@ -84,15 +84,15 @@ internal class ConversationVisitor(
                 else ->
                     i18nF("blog.invitation.response.declined.sent", contactName)
             }
-            ConversationNoticeItem(text, r)
+            ConversationNoticeItem(notice, r)
         } else {
-            val text = when {
+            val notice = when {
                 r.wasAccepted() ->
                     i18nF("blog.invitation.response.accepted.received", contactName)
                 else ->
                     i18nF("blog.invitation.response.declined.received", contactName)
             }
-            ConversationNoticeItem(text, r)
+            ConversationNoticeItem(notice, r)
         }
     }
 
@@ -103,16 +103,16 @@ internal class ConversationVisitor(
                 r
             )
         else {
-            val text = i18nF("forum.invitation.received", contactName, r.name)
+            val notice = i18nF("forum.invitation.received", contactName, r.name)
             // todo: add proper check for feature support
             if (false)
                 ConversationRequestItem(
-                    text,
+                    notice,
                     ConversationRequestItem.RequestType.FORUM, r
                 )
             else
                 ConversationNoticeItem(
-                    text + "\n" + i18n("unsupported_feature"),
+                    notice + "\n" + i18n("unsupported_feature"),
                     r
                 )
         }
@@ -120,7 +120,7 @@ internal class ConversationVisitor(
 
     override fun visitForumInvitationResponse(r: ForumInvitationResponse): ConversationItem {
         return if (r.isLocal) {
-            val text = when {
+            val notice = when {
                 r.wasAccepted() ->
                     i18nF("forum.invitation.response.accepted.sent", contactName)
                 r.isAutoDecline ->
@@ -128,15 +128,15 @@ internal class ConversationVisitor(
                 else ->
                     i18nF("forum.invitation.response.declined.sent", contactName)
             }
-            ConversationNoticeItem(text, r)
+            ConversationNoticeItem(notice, r)
         } else {
-            val text = when {
+            val notice = when {
                 r.wasAccepted() ->
                     i18nF("forum.invitation.response.accepted.received", contactName)
                 else ->
                     i18nF("forum.invitation.response.declined.received", contactName)
             }
-            ConversationNoticeItem(text, r)
+            ConversationNoticeItem(notice, r)
         }
     }
 
@@ -147,16 +147,16 @@ internal class ConversationVisitor(
                 r
             )
         else {
-            val text = i18nF("group.invitation.received", contactName, r.name)
+            val notice = i18nF("group.invitation.received", contactName, r.name)
             // todo: add proper check for feature support
             if (false)
                 ConversationRequestItem(
-                    text,
+                    notice,
                     ConversationRequestItem.RequestType.GROUP, r
                 )
             else
                 ConversationNoticeItem(
-                    text + "\n" + i18n("unsupported_feature"),
+                    notice + "\n" + i18n("unsupported_feature"),
                     r
                 )
         }
@@ -164,7 +164,7 @@ internal class ConversationVisitor(
 
     override fun visitGroupInvitationResponse(r: GroupInvitationResponse): ConversationItem {
         return if (r.isLocal) {
-            val text = when {
+            val notice = when {
                 r.wasAccepted() ->
                     i18nF("group.invitation.response.accepted.sent", contactName)
                 r.isAutoDecline ->
@@ -172,15 +172,15 @@ internal class ConversationVisitor(
                 else ->
                     i18nF("group.invitation.response.declined.sent", contactName)
             }
-            ConversationNoticeItem(text, r)
+            ConversationNoticeItem(notice, r)
         } else {
-            val text = when {
+            val notice = when {
                 r.wasAccepted() ->
                     i18nF("group.invitation.response.accepted.received", contactName)
                 else ->
                     i18nF("group.invitation.response.declined.received", contactName)
             }
-            ConversationNoticeItem(text, r)
+            ConversationNoticeItem(notice, r)
         }
     }
 
@@ -192,7 +192,7 @@ internal class ConversationVisitor(
                 r
             )
         else {
-            val text = when {
+            val notice = when {
                 r.wasAnswered() ->
                     i18nF("introduction.request.answered.received", contactName, name)
                 r.isContact ->
@@ -201,7 +201,7 @@ internal class ConversationVisitor(
                     i18nF("introduction.request.received", contactName, name)
             }
             ConversationRequestItem(
-                text,
+                notice,
                 ConversationRequestItem.RequestType.INTRODUCTION, r
             )
         }
@@ -210,7 +210,7 @@ internal class ConversationVisitor(
     override fun visitIntroductionResponse(r: IntroductionResponse): ConversationItem {
         val name = getContactDisplayName(r.introducedAuthor.name, r.introducedAuthorInfo.alias)
         return if (r.isLocal) {
-            val text = when {
+            val notice = when {
                 r.wasAccepted() -> {
                     val suffix = if (r.canSucceed())
                         "\n\n" + i18nF("introduction.response.accepted.sent.info", name)
@@ -222,9 +222,9 @@ internal class ConversationVisitor(
                 else ->
                     i18nF("introduction.response.declined.sent", name)
             }
-            ConversationNoticeItem(text, r)
+            ConversationNoticeItem(notice, r)
         } else {
-            val text = when {
+            val notice = when {
                 r.wasAccepted() ->
                     i18nF("introduction.response.accepted.received", contactName, name)
                 r.isIntroducer ->
@@ -232,7 +232,7 @@ internal class ConversationVisitor(
                 else ->
                     i18nF("introduction.response.declined.received_by_introducee", contactName, name)
             }
-            ConversationNoticeItem(text, r)
+            ConversationNoticeItem(notice, r)
         }
     }
 }
diff --git a/src/main/kotlin/org/briarproject/briar/desktop/introduction/ContactDrawerMakeIntro.kt b/src/main/kotlin/org/briarproject/briar/desktop/introduction/ContactDrawerMakeIntro.kt
index 1a471e98ba..1f63c8d9aa 100644
--- a/src/main/kotlin/org/briarproject/briar/desktop/introduction/ContactDrawerMakeIntro.kt
+++ b/src/main/kotlin/org/briarproject/briar/desktop/introduction/ContactDrawerMakeIntro.kt
@@ -39,7 +39,7 @@ import java.util.Locale
 @Composable
 fun ContactDrawerMakeIntro(
     contactItem: ContactItem,
-    closeInfoDrawer: () -> Unit,
+    closeInfoDrawer: (reload: Boolean) -> Unit,
     viewModel: IntroductionViewModel = viewModel(),
 ) {
     LaunchedEffect(contactItem) {
@@ -50,7 +50,7 @@ fun ContactDrawerMakeIntro(
             Column {
                 Row(Modifier.fillMaxWidth().height(HEADER_SIZE)) {
                     IconButton(
-                        onClick = closeInfoDrawer,
+                        onClick = { closeInfoDrawer(false) },
                         Modifier.padding(horizontal = 11.dp).size(32.dp).align(Alignment.CenterVertically)
                     ) {
                         Icon(Icons.Filled.Close, i18n("access.introduction.close"))
@@ -111,7 +111,7 @@ fun ContactDrawerMakeIntro(
                 TextButton(
                     onClick = {
                         viewModel.makeIntroduction()
-                        closeInfoDrawer()
+                        closeInfoDrawer(true)
                     },
                     Modifier.fillMaxWidth()
                 ) {
-- 
GitLab