ui: add swipe/menu actions to member contact requests (#6138)

* ios: add swipe actions to member contact requests

* kotlin

* padding
This commit is contained in:
spaced4ndy
2025-08-01 16:08:54 +01:00
committed by GitHub
parent f42a6751b1
commit 1fb8e63680
6 changed files with 149 additions and 65 deletions
@@ -14,6 +14,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import chat.simplex.common.model.*
import chat.simplex.common.platform.chatModel
import chat.simplex.common.ui.theme.DEFAULT_PADDING_HALF
import chat.simplex.common.views.helpers.*
import chat.simplex.res.MR
import dev.icerock.moko.resources.compose.painterResource
@@ -59,7 +60,8 @@ fun ComposeContextMemberContactActionsView(
if (groupDirectInv.memberRemoved) {
Row(
Modifier
.fillMaxSize(),
.fillMaxSize()
.padding(horizontal = DEFAULT_PADDING_HALF),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterHorizontally)
) {
@@ -149,7 +151,7 @@ private fun deleteMemberContact(rhId: Long?, contact: Contact) {
fun acceptMemberContact(
rhId: Long?,
contactId: Long,
close: ((chat: Chat) -> Unit)? = null, // currently unused, can pass function to open chat if reused in other views (e.g. see onRequestAccepted)
close: ((chat: Chat) -> Unit)? = null,
inProgress: MutableState<Boolean>? = null
) {
withBGApi {
@@ -271,8 +271,14 @@ suspend fun setGroupMembers(rhId: Long?, groupInfo: GroupInfo, chatModel: ChatMo
@Composable
fun ContactMenuItems(chat: Chat, contact: Contact, chatModel: ChatModel, showMenu: MutableState<Boolean>, showMarkRead: Boolean) {
if (contact.nextAcceptContactRequest && contact.contactRequestId != null) {
ContactRequestMenuItems(chat.remoteHostId, contactRequestId = contact.contactRequestId, chatModel, showMenu)
if (contact.nextAcceptContactRequest) {
if (contact.contactRequestId != null) {
ContactRequestMenuItems(chat.remoteHostId, contactRequestId = contact.contactRequestId, chatModel, showMenu)
} else if (contact.groupDirectInv != null && !contact.groupDirectInv.memberRemoved) {
MemberContactRequestMenuItems(chat.remoteHostId, contact, showMenu)
} else {
DeleteContactAction(chat, chatModel, showMenu)
}
} else {
if (contact.activeConn != null) {
if (showMarkRead) {
@@ -545,6 +551,28 @@ fun ContactRequestMenuItems(rhId: Long?, contactRequestId: Long, chatModel: Chat
)
}
@Composable
fun MemberContactRequestMenuItems(rhId: Long?, contact: Contact, showMenu: MutableState<Boolean>, onSuccess: ((chat: Chat) -> Unit)? = null) {
ItemAction(
stringResource(MR.strings.accept_contact_button),
painterResource(MR.images.ic_check),
color = MaterialTheme.colors.onBackground,
onClick = {
acceptMemberContact(rhId, contact.contactId, onSuccess)
showMenu.value = false
}
)
ItemAction(
stringResource(MR.strings.reject_contact_button),
painterResource(MR.images.ic_close),
onClick = {
showRejectMemberContactRequestAlert(rhId, contact)
showMenu.value = false
},
color = Color.Red
)
}
@Composable
fun ContactConnectionMenuItems(rhId: Long?, chatInfo: ChatInfo.ContactConnection, chatModel: ChatModel, showMenu: MutableState<Boolean>) {
ItemAction(
@@ -73,14 +73,25 @@ fun ContactListNavLinkView(chat: Chat, nextChatSelected: State<Boolean>, showDel
},
dropdownMenuItems = {
tryOrShowError("${chat.id}ContactListNavLinkDropdown", error = {}) {
if (contactType == ContactType.CONTACT_WITH_REQUEST && chat.chatInfo.contact.contactRequestId != null) {
ContactRequestMenuItems(
rhId = chat.remoteHostId,
contactRequestId = chat.chatInfo.contact.contactRequestId,
chatModel = chatModel,
showMenu = showMenu,
onSuccess = { onRequestAccepted(it) }
)
if (contactType == ContactType.CONTACT_WITH_REQUEST) {
if (chat.chatInfo.contact.contactRequestId != null) {
ContactRequestMenuItems(
rhId = chat.remoteHostId,
contactRequestId = chat.chatInfo.contact.contactRequestId,
chatModel = chatModel,
showMenu = showMenu,
onSuccess = { onRequestAccepted(it) }
)
} else if (chat.chatInfo.contact.groupDirectInv != null && !chat.chatInfo.contact.groupDirectInv.memberRemoved) {
MemberContactRequestMenuItems(
rhId = chat.remoteHostId,
contact = chat.chatInfo.contact,
showMenu = showMenu,
onSuccess = { onRequestAccepted(it) }
)
} else {
DeleteContactAction(chat, chatModel, showMenu)
}
} else {
DeleteContactAction(chat, chatModel, showMenu)
}