mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-08-14 07:10:19 +00:00
android, desktop: do not offer to accept contact request that is being accepted
This commit is contained in:
@@ -122,6 +122,8 @@ object ChatModel {
|
||||
val incompleteInitializedDbRemoved = mutableStateOf(false)
|
||||
// map of connections network statuses, key is agent connection id
|
||||
val switchingUsersAndHosts = mutableStateOf(false)
|
||||
// ids of contact requests being accepted, to not offer accepting the same request from another view
|
||||
val acceptingContactRequests = mutableStateListOf<Long>()
|
||||
|
||||
// current chat
|
||||
val chatId = mutableStateOf<String?>(null)
|
||||
|
||||
+7
-5
@@ -28,12 +28,14 @@ fun ComposeContextContactRequestActionsView(
|
||||
rhId: Long?,
|
||||
contactRequestId: Long
|
||||
) {
|
||||
val inProgress = rememberSaveable { mutableStateOf(false) }
|
||||
val inProgressLocal = rememberSaveable { mutableStateOf(false) }
|
||||
// the request can also be accepted from another view, e.g. via notification
|
||||
val inProgress = remember(contactRequestId) { derivedStateOf { inProgressLocal.value || contactRequestId in chatModel.acceptingContactRequests } }
|
||||
var progressByTimeout by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
KeyChangeEffect(chatModel.chatId.value) {
|
||||
if (inProgress.value) {
|
||||
inProgress.value = false
|
||||
if (inProgressLocal.value) {
|
||||
inProgressLocal.value = false
|
||||
progressByTimeout = false
|
||||
}
|
||||
}
|
||||
@@ -89,9 +91,9 @@ fun ComposeContextContactRequestActionsView(
|
||||
else
|
||||
acceptButtonModifier.clickable {
|
||||
if (chatModel.addressShortLinkDataSet()) {
|
||||
acceptContactRequest(rhId, incognito = false, contactRequestId, isCurrentUser = true, chatModel = chatModel, close = null, inProgress = inProgress)
|
||||
acceptContactRequest(rhId, incognito = false, contactRequestId, isCurrentUser = true, chatModel = chatModel, close = null, inProgress = inProgressLocal)
|
||||
} else {
|
||||
showAcceptRequestAlert(rhId, contactRequestId, inProgress = inProgress)
|
||||
showAcceptRequestAlert(rhId, contactRequestId, inProgress = inProgressLocal)
|
||||
}
|
||||
}
|
||||
Row(
|
||||
|
||||
+16
-11
@@ -735,20 +735,25 @@ fun acceptContactRequest(
|
||||
) {
|
||||
withBGApi {
|
||||
inProgress?.value = true
|
||||
val contact = chatModel.controller.apiAcceptContactRequest(rhId, incognito, contactRequestId)
|
||||
if (contact != null && isCurrentUser) {
|
||||
val chat = Chat(remoteHostId = rhId, ChatInfo.Direct(contact), listOf())
|
||||
withContext(Dispatchers.Main) {
|
||||
if (contact.contactRequestId != null) { // means contact request was initially created with contact, so we don't need to replace it
|
||||
chatModel.chatsContext.updateContact(rhId, contact)
|
||||
} else {
|
||||
chatModel.chatsContext.replaceChat(rhId, contactRequestChatId(contactRequestId), chat)
|
||||
chatModel.acceptingContactRequests.add(contactRequestId)
|
||||
try {
|
||||
val contact = chatModel.controller.apiAcceptContactRequest(rhId, incognito, contactRequestId)
|
||||
if (contact != null && isCurrentUser) {
|
||||
val chat = Chat(remoteHostId = rhId, ChatInfo.Direct(contact), listOf())
|
||||
withContext(Dispatchers.Main) {
|
||||
if (contact.contactRequestId != null) { // means contact request was initially created with contact, so we don't need to replace it
|
||||
chatModel.chatsContext.updateContact(rhId, contact)
|
||||
} else {
|
||||
chatModel.chatsContext.replaceChat(rhId, contactRequestChatId(contactRequestId), chat)
|
||||
}
|
||||
inProgress?.value = false
|
||||
}
|
||||
close?.invoke(chat)
|
||||
} else {
|
||||
inProgress?.value = false
|
||||
}
|
||||
close?.invoke(chat)
|
||||
} else {
|
||||
inProgress?.value = false
|
||||
} finally {
|
||||
chatModel.acceptingContactRequests.remove(contactRequestId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user