From cda6504354c33f88fa597a08c02e526a3755c938 Mon Sep 17 00:00:00 2001 From: Nico Alt <nicoalt@posteo.org> Date: Tue, 18 Jan 2022 20:05:46 +0100 Subject: [PATCH] Let users delete contacts --- .../briar/desktop/contact/ContactDropDown.kt | 3 +- .../conversation/ConversationDialogs.kt | 34 +++++++++++++++++++ .../conversation/ConversationHeader.kt | 9 ++++- .../conversation/ConversationScreen.kt | 10 ++++++ .../conversation/ConversationViewModel.kt | 4 +++ .../resources/strings/BriarDesktop.properties | 2 ++ 6 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/org/briarproject/briar/desktop/contact/ContactDropDown.kt b/src/main/kotlin/org/briarproject/briar/desktop/contact/ContactDropDown.kt index aee76df586..a854d7ea11 100644 --- a/src/main/kotlin/org/briarproject/briar/desktop/contact/ContactDropDown.kt +++ b/src/main/kotlin/org/briarproject/briar/desktop/contact/ContactDropDown.kt @@ -45,6 +45,7 @@ fun ContactDropDown( close: () -> Unit, onMakeIntroduction: () -> Unit, onDeleteAllMessages: () -> Unit, + onDeleteContact: () -> Unit, ) { val coreFeatureFlags = getCoreFeatureFlags() val desktopFeatureFlags = getDesktopFeatureFlags() @@ -121,7 +122,7 @@ fun ContactDropDown( DropdownMenuItem(onClick = { false }, enabled = false) { Text(i18n("contacts.dropdown.contact.change"), fontSize = 14.sp) } - DropdownMenuItem(onClick = { false }) { + DropdownMenuItem(onClick = { close(); onDeleteContact() }) { Text(i18n("contacts.dropdown.contact.delete"), fontSize = 14.sp) } } diff --git a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationDialogs.kt b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationDialogs.kt index db10035258..f43dc960ef 100644 --- a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationDialogs.kt +++ b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationDialogs.kt @@ -156,3 +156,37 @@ fun DeleteAllMessagesFailedDialog( } ) } + +@OptIn(ExperimentalMaterialApi::class) +@Composable +fun DeleteContactConfirmationDialog( + isVisible: Boolean, + close: () -> Unit, + onDelete: () -> Unit = {}, + onCancel: () -> Unit = {}, +) { + if (!isVisible) return + + AlertDialog( + onDismissRequest = close, + title = { + Text( + text = i18n("conversation.delete.contact.dialog.title"), + modifier = Modifier.width(IntrinsicSize.Max) + ) + }, + text = { + Text(i18n("conversation.delete.contact.dialog.message")) + }, + dismissButton = { + TextButton(onClick = { close(); onDelete() }) { + Text(i18n("delete")) + } + }, + confirmButton = { + TextButton(onClick = { close(); onCancel() }) { + Text(i18n("cancel")) + } + } + ) +} diff --git a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationHeader.kt b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationHeader.kt index 22b29ffbe4..9100b8bdbe 100644 --- a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationHeader.kt +++ b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationHeader.kt @@ -56,6 +56,7 @@ fun ConversationHeader( contactItem: ContactItem, onMakeIntroduction: () -> Unit, onDeleteAllMessages: () -> Unit, + onDeleteContact: () -> Unit, ) { val (isExpanded, setExpanded) = remember { mutableStateOf(false) } val onlineColor = @@ -95,7 +96,13 @@ fun ConversationHeader( modifier = Modifier.align(Alignment.CenterVertically).padding(end = 16.dp) ) { Icon(Icons.Filled.MoreVert, i18n("access.contact.menu"), modifier = Modifier.size(24.dp)) - ContactDropDown(isExpanded, { setExpanded(false) }, onMakeIntroduction, onDeleteAllMessages) + ContactDropDown( + isExpanded, + { setExpanded(false) }, + onMakeIntroduction, + onDeleteAllMessages, + onDeleteContact + ) } } HorizontalDivider(modifier = Modifier.align(Alignment.BottomCenter)) 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 e028b054bd..5389849dcf 100644 --- a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationScreen.kt +++ b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationScreen.kt @@ -71,6 +71,7 @@ fun ConversationScreen( val (infoDrawer, setInfoDrawer) = remember { mutableStateOf(false) } val (contactDrawerState, setDrawerState) = remember { mutableStateOf(ContactInfoDrawerState.MakeIntro) } val (deleteAllMessagesDialogVisible, setDeleteAllMessagesDialog) = remember { mutableStateOf(false) } + val (deleteContactDialogVisible, setDeleteContactDialog) = remember { mutableStateOf(false) } BoxWithConstraints(Modifier.fillMaxSize()) { val animatedInfoDrawerOffsetX by animateDpAsState(if (infoDrawer) (-275).dp else 0.dp) @@ -83,6 +84,9 @@ fun ConversationScreen( }, onDeleteAllMessages = { setDeleteAllMessagesDialog(true) + }, + onDeleteContact = { + setDeleteContactDialog(true) } ) }, @@ -158,5 +162,11 @@ fun ConversationScreen( deletionResult = viewModel.deletionResult.value, close = viewModel::confirmDeletionResult ) + + DeleteContactConfirmationDialog( + isVisible = deleteContactDialogVisible, + close = { setDeleteContactDialog(false) }, + onDelete = viewModel::deleteContact + ) } } 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 a26baff16b..fce0ab729b 100644 --- a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationViewModel.kt +++ b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationViewModel.kt @@ -430,4 +430,8 @@ constructor( fun confirmDeletionResult() { _deletionResult.value = null } + + fun deleteContact() = runOnDbThread { + contactManager.removeContact(_contactId.value!!) + } } diff --git a/src/main/resources/strings/BriarDesktop.properties b/src/main/resources/strings/BriarDesktop.properties index 72c22adff3..7b65487cb9 100644 --- a/src/main/resources/strings/BriarDesktop.properties +++ b/src/main/resources/strings/BriarDesktop.properties @@ -45,6 +45,8 @@ conversation.delete.failed.dialog.message.ongoing_invitations=Messages related t conversation.delete.failed.dialog.message.not_all_selected_both=To delete an invitation or introduction, you need to select the request and the response. conversation.delete.failed.dialog.message.not_all_selected_introductions=To delete an introduction, you need to select the request and the response. conversation.delete.failed.dialog.message.not_all_selected_invitations=To delete an invitation, you need to select the request and the response. +conversation.delete.contact.dialog.title=Confirm Contact Deletion +conversation.delete.contact.dialog.message=Are you sure that you want to remove this contact and all messages exchanged with this contact? # Private Groups groups.card.created=Created by {0} -- GitLab