ui: fix possible suspect for race condition on accept contact (#6121)

This commit is contained in:
spaced4ndy
2025-07-28 16:51:37 +01:00
committed by GitHub
parent 7988463a47
commit 69461c2257
3 changed files with 9 additions and 5 deletions
+5 -1
View File
@@ -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 }
}
}