From b69f4227080a3dfc522961d9089542dc2a39da14 Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Mon, 17 Jul 2023 16:55:19 +0400 Subject: [PATCH] ios: fix editing w/t change (#2710) --- .../Chat/ComposeMessage/ComposeView.swift | 24 +++++++++++-------- apps/ios/SimpleXChat/ChatTypes.swift | 15 +++++++++++- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/apps/ios/Shared/Views/Chat/ComposeMessage/ComposeView.swift b/apps/ios/Shared/Views/Chat/ComposeMessage/ComposeView.swift index cb49eced17..1d47227094 100644 --- a/apps/ios/Shared/Views/Chat/ComposeMessage/ComposeView.swift +++ b/apps/ios/Shared/Views/Chat/ComposeMessage/ComposeView.swift @@ -665,17 +665,21 @@ struct ComposeView: View { if let oldMsgContent = ei.content.msgContent { do { let mc = updateMsgContent(oldMsgContent) - let chatItem = try await apiUpdateChatItem( - type: chat.chatInfo.chatType, - id: chat.chatInfo.apiId, - itemId: ei.id, - msg: mc, - live: live - ) - await MainActor.run { - _ = self.chatModel.upsertChatItem(self.chat.chatInfo, chatItem) + if mc != oldMsgContent || (ei.meta.itemLive ?? false) { + let chatItem = try await apiUpdateChatItem( + type: chat.chatInfo.chatType, + id: chat.chatInfo.apiId, + itemId: ei.id, + msg: mc, + live: live + ) + await MainActor.run { + _ = self.chatModel.upsertChatItem(self.chat.chatInfo, chatItem) + } + return chatItem + } else { + return nil } - return chatItem } catch { logger.error("ChatView.sendMessage error: \(error.localizedDescription)") AlertManager.shared.showAlertMsg(title: "Error updating message", message: "Error: \(responseError(error))") diff --git a/apps/ios/SimpleXChat/ChatTypes.swift b/apps/ios/SimpleXChat/ChatTypes.swift index 664c8277ba..378a032afe 100644 --- a/apps/ios/SimpleXChat/ChatTypes.swift +++ b/apps/ios/SimpleXChat/ChatTypes.swift @@ -2724,7 +2724,7 @@ public enum CIFileStatus: Decodable, Equatable { } } -public enum MsgContent { +public enum MsgContent: Equatable { case text(String) case link(text: String, preview: LinkPreview) case image(text: String, image: String) @@ -2785,6 +2785,19 @@ public enum MsgContent { case image case duration } + + public static func == (lhs: MsgContent, rhs: MsgContent) -> Bool { + switch (lhs, rhs) { + case let (.text(lt), .text(rt)): return lt == rt + case let (.link(lt, lp), .link(rt, rp)): return lt == rt && lp == rp + case let (.image(lt, li), .image(rt, ri)): return lt == rt && li == ri + case let (.video(lt, li, ld), .video(rt, ri, rd)): return lt == rt && li == ri && ld == rd + case let (.voice(lt, ld), .voice(rt, rd)): return lt == rt && ld == rd + case let (.file(lf), .file(rf)): return lf == rf + case let (.unknown(lType, lt), .unknown(rType, rt)): return lType == rType && lt == rt + default: return false + } + } } extension MsgContent: Decodable {