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 43462c4da9fe403ef300db44546669ca03b86490..c7d7433540af448c1ee1480879bf340dfe9e8ad4 100644 --- a/src/main/kotlin/org/briarproject/briar/desktop/contact/ContactInfoDrawer.kt +++ b/src/main/kotlin/org/briarproject/briar/desktop/contact/ContactInfoDrawer.kt @@ -14,10 +14,10 @@ enum class ContactInfoDrawerState { @Composable fun ContactInfoDrawer( contactItem: ContactItem, - setInfoDrawer: (Boolean) -> Unit, + closeInfoDrawer: () -> Unit, drawerState: ContactInfoDrawerState ) { when (drawerState) { - MakeIntro -> ContactDrawerMakeIntro(contactItem, setInfoDrawer) + MakeIntro -> ContactDrawerMakeIntro(contactItem, closeInfoDrawer) } } 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 a842320ce8d40e3427ceeb7910a5600203fc2ed0..1299e27b82b381a49a45e93578d7141516826855 100644 --- a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationScreen.kt +++ b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationScreen.kt @@ -125,7 +125,16 @@ fun ConversationScreen( RoundedCornerShape(topStart = 10.dp, bottomStart = 10.dp) ) ) { - ContactInfoDrawer(contactItem, setInfoDrawer, contactDrawerState) + ContactInfoDrawer( + contactItem, + closeInfoDrawer = { + 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() + }, + contactDrawerState + ) } } } 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 70dc74982218b28c8c2f5f5f7fa067f9508c816d..adbbb13391584c567733d90c3d8096b7087ccd3f 100644 --- a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationViewModel.kt +++ b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationViewModel.kt @@ -182,6 +182,10 @@ constructor( } } + fun reloadMessages() = runOnDbThreadWithTransaction(true) { txn -> + loadMessages(txn, contactItem.value!!) + } + private fun loadMessages(txn: Transaction, contact: ContactItem) { try { var start = LogUtils.now() @@ -282,7 +286,7 @@ constructor( throw IllegalArgumentException("Only introduction requests are supported for the time being.") } // reload all messages to also show request response message - // todo: might be better to have an event to react to, also for (all) outgoing messages + // todo: might be better to have an event to react to, also for (other) outgoing messages loadMessages(txn, contactItem.value!!) } } 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 e0081588c2b7ba0d001fa7469cfc54907cd52e8a..1a471e98bab625745c5cf27edc924cf76d4f9348 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, - setInfoDrawer: (Boolean) -> Unit, + closeInfoDrawer: () -> Unit, viewModel: IntroductionViewModel = viewModel(), ) { LaunchedEffect(contactItem) { @@ -50,7 +50,7 @@ fun ContactDrawerMakeIntro( Column { Row(Modifier.fillMaxWidth().height(HEADER_SIZE)) { IconButton( - onClick = { setInfoDrawer(false) }, + onClick = closeInfoDrawer, Modifier.padding(horizontal = 11.dp).size(32.dp).align(Alignment.CenterVertically) ) { Icon(Icons.Filled.Close, i18n("access.introduction.close")) @@ -109,7 +109,10 @@ fun ContactDrawerMakeIntro( } Row(Modifier.padding(8.dp)) { TextButton( - onClick = { setInfoDrawer(false) }, + onClick = { + viewModel.makeIntroduction() + closeInfoDrawer() + }, Modifier.fillMaxWidth() ) { val text = i18n("introduction.introduce") diff --git a/src/main/kotlin/org/briarproject/briar/desktop/introduction/IntroductionViewModel.kt b/src/main/kotlin/org/briarproject/briar/desktop/introduction/IntroductionViewModel.kt index 4b6bb3ef97ec6d951c0df3d0989e636e91652473..7ee9d42f34a535911e2b8c9112e6d1933f2d0d1b 100644 --- a/src/main/kotlin/org/briarproject/briar/desktop/introduction/IntroductionViewModel.kt +++ b/src/main/kotlin/org/briarproject/briar/desktop/introduction/IntroductionViewModel.kt @@ -7,6 +7,7 @@ import org.briarproject.bramble.api.db.TransactionManager import org.briarproject.bramble.api.event.EventBus import org.briarproject.bramble.api.lifecycle.LifecycleManager import org.briarproject.briar.api.conversation.ConversationManager +import org.briarproject.briar.api.introduction.IntroductionManager import org.briarproject.briar.desktop.contact.BaseContactItem import org.briarproject.briar.desktop.contact.ContactItem import org.briarproject.briar.desktop.contact.ContactsViewModel @@ -17,6 +18,7 @@ import javax.inject.Inject class IntroductionViewModel @Inject constructor( + private val introductionManager: IntroductionManager, contactManager: ContactManager, conversationManager: ConversationManager, connectionRegistry: ConnectionRegistry, @@ -63,4 +65,16 @@ constructor( _firstContact.value?.idWrapper != contactItem.idWrapper } else false } + + fun makeIntroduction() { + val c1 = requireNotNull(_firstContact.value) + val c2 = requireNotNull(_secondContact.value) + val msg = _introductionMessage.value + + runOnDbThread { + val c1 = contactManager.getContact(c1.idWrapper.contactId) + val c2 = contactManager.getContact(c2.idWrapper.contactId) + introductionManager.makeIntroduction(c1, c2, msg) + } + } }