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 c7d7433540af448c1ee1480879bf340dfe9e8ad4..6988c76f63dcd77309031d8a6fe7d3cd96f1ad29 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 d746990c38859cccfb836c8f874665cde0568a80..6eccffeb5b046b59c5560900955eb4cfe180710f 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 74833a0d0790f76c6b2f878dca62fbf0f4a15ddf..b9ef25101f019b5b99ccf9c9345c3f54b1101e1d 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 fab635a35b9731315f2395f39698e1dd3d44b2eb..48dff66eb9e3bca62a0a16f4d743594c354ca34f 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 aab9ac91388deca657d2415ac98cba035822ba87..bca4e4827d779bb9b7e1dab9f335d6cf7dd46ed7 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 1299e27b82b381a49a45e93578d7141516826855..e10fe586a45effdf5250ccfbc14b2ffd4ea8c16c 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 d491cf6f148c81563307148fd3659a5525154233..6dde8f0f1b46a582d954503f9c7b8f8b728b2f21 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 1a471e98bab625745c5cf27edc924cf76d4f9348..1f63c8d9aa5761c7cbd8500d0a76ed4c135285aa 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() ) {