ios: prevent messages from being sent twice (#1120)

This commit is contained in:
Evgeny Poberezkin
2022-09-24 22:20:56 +01:00
committed by GitHub
parent d15fec4fab
commit 36f635f6f0

View File

@@ -288,20 +288,23 @@ struct ComposeView: View {
case let .editingItem(chatItem: ei):
if let oldMsgContent = ei.content.msgContent {
do {
let mc = updateMsgContent(oldMsgContent)
await MainActor.run { clearState() }
let chatItem = try await apiUpdateChatItem(
type: chat.chatInfo.chatType,
id: chat.chatInfo.apiId,
itemId: ei.id,
msg: updateMsgContent(oldMsgContent)
msg: mc
)
DispatchQueue.main.async {
let _ = self.chatModel.upsertChatItem(self.chat.chatInfo, chatItem)
}
} catch {
clearState()
logger.error("ChatView.sendMessage error: \(error.localizedDescription)")
AlertManager.shared.showAlertMsg(title: "Error updating message", message: "Error: \(responseError(error))")
}
} else {
await MainActor.run { clearState() }
}
default:
var mc: MsgContent? = nil
@@ -332,6 +335,7 @@ struct ComposeView: View {
default:
quotedItemId = nil
}
await MainActor.run { clearState() }
if let mc = mc,
let chatItem = await apiSendMessage(
type: chat.chatInfo.chatType,
@@ -343,7 +347,6 @@ struct ComposeView: View {
chatModel.addChatItem(chat.chatInfo, chatItem)
}
}
clearState()
}
}