mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-26 10:58:02 +00:00
ui: fix possible suspect for race condition on accept contact (#6121)
This commit is contained in:
@@ -1617,7 +1617,8 @@ func networkErrorAlert<R>(_ res: APIResult<R>) -> Alert? {
|
||||
}
|
||||
}
|
||||
|
||||
func acceptContactRequest(incognito: Bool, contactRequestId: Int64) async {
|
||||
func acceptContactRequest(incognito: Bool, contactRequestId: Int64, inProgress: Binding<Bool>? = nil) async {
|
||||
await MainActor.run { inProgress?.wrappedValue = true }
|
||||
if let contact = await apiAcceptContactRequest(incognito: incognito, contactReqId: contactRequestId) {
|
||||
let chat = Chat(chatInfo: ChatInfo.direct(contact: contact), chatItems: [])
|
||||
await MainActor.run {
|
||||
@@ -1627,6 +1628,7 @@ func acceptContactRequest(incognito: Bool, contactRequestId: Int64) async {
|
||||
ChatModel.shared.replaceChat(contactRequestChatId(contactRequestId), chat)
|
||||
}
|
||||
NetworkModel.shared.setContactNetworkStatus(contact, .connected)
|
||||
inProgress?.wrappedValue = false
|
||||
}
|
||||
if contact.sndReady {
|
||||
let chatId = chat.id
|
||||
@@ -1636,6 +1638,8 @@ func acceptContactRequest(incognito: Bool, contactRequestId: Int64) async {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
await MainActor.run { inProgress?.wrappedValue = false }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,10 +84,8 @@ struct ContextContactRequestActionsView: View {
|
||||
}
|
||||
|
||||
private func acceptRequest(incognito: Bool = false) {
|
||||
inProgress = true
|
||||
Task {
|
||||
await acceptContactRequest(incognito: incognito, contactRequestId: contactRequestId)
|
||||
await MainActor.run { inProgress = false }
|
||||
await acceptContactRequest(incognito: incognito, contactRequestId: contactRequestId, inProgress: $inProgress)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -707,7 +707,6 @@ fun acceptContactRequest(
|
||||
withBGApi {
|
||||
inProgress?.value = true
|
||||
val contact = chatModel.controller.apiAcceptContactRequest(rhId, incognito, contactRequestId)
|
||||
inProgress?.value = false
|
||||
if (contact != null && isCurrentUser) {
|
||||
val chat = Chat(remoteHostId = rhId, ChatInfo.Direct(contact), listOf())
|
||||
withContext(Dispatchers.Main) {
|
||||
@@ -716,9 +715,12 @@ fun acceptContactRequest(
|
||||
} else {
|
||||
chatModel.chatsContext.replaceChat(rhId, contactRequestChatId(contactRequestId), chat)
|
||||
}
|
||||
inProgress?.value = false
|
||||
}
|
||||
chatModel.setContactNetworkStatus(contact, NetworkStatus.Connected())
|
||||
close?.invoke(chat)
|
||||
} else {
|
||||
inProgress?.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user