diff --git a/deltachat-ios/Chat/ChatViewController.swift b/deltachat-ios/Chat/ChatViewController.swift index bc1364859..3f6bf4982 100644 --- a/deltachat-ios/Chat/ChatViewController.swift +++ b/deltachat-ios/Chat/ChatViewController.swift @@ -1665,6 +1665,20 @@ class ChatViewController: UITableViewController, UITableViewDropDelegate { replyToMessage(at: indexPath) } + private func editSentMessage(at indexPath: IndexPath) { + let message = dcContext.getMessage(id: messageIds[indexPath.row]) + let alert = UIAlertController(title: nil, message: nil, preferredStyle: .alert) + alert.addTextField { textfield in + textfield.text = message.text + } + alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default) { [weak self] _ in + guard let self, let textfield = alert.textFields?.first else { return } + dcContext.sendTextEdit(msgId: message.id, newText: textfield.text ?? "") + }) + alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel)) + present(alert, animated: true) + } + private func toggleSave(at indexPath: IndexPath) { let message = dcContext.getMessage(id: messageIds[indexPath.row]) if message.savedMessageId != 0 { @@ -1909,6 +1923,12 @@ extension ChatViewController { UIAction.menuAction(localizationKey: "forward", systemImageName: "arrowshape.turn.up.forward", indexPath: indexPath, action: forward) ) + if message.isFromCurrentSender && message.hasText && !message.isMarkerOrInfo && dcChat.canSend { + children.append( + UIAction.menuAction(localizationKey: "global_menu_edit_desktop", systemImageName: "pencil", indexPath: indexPath, action: editSentMessage) + ) + } + if !dcChat.isSelfTalk && message.canSave { if message.savedMessageId != 0 { children.append( diff --git a/deltachat-ios/Chat/Views/StatusView.swift b/deltachat-ios/Chat/Views/StatusView.swift index 1551c1705..3b719233e 100644 --- a/deltachat-ios/Chat/Views/StatusView.swift +++ b/deltachat-ios/Chat/Views/StatusView.swift @@ -75,7 +75,11 @@ public class StatusView: UIView { } public func update(message: DcMsg, tintColor: UIColor) { - dateLabel.text = message.formattedSentDate() + dateLabel.text = if message.isEdited { + message.formattedSentDate() + " " + String.localized("edited") + } else { + message.formattedSentDate() + } dateLabel.textColor = tintColor if message.showPadlock() { diff --git a/deltachat-ios/DC/DcContext.swift b/deltachat-ios/DC/DcContext.swift index fc60a51ff..3047289e8 100644 --- a/deltachat-ios/DC/DcContext.swift +++ b/deltachat-ios/DC/DcContext.swift @@ -62,6 +62,10 @@ public class DcContext { dc_send_msg(contextPointer, UInt32(chatId), message.messagePointer) } + public func sendTextEdit(msgId: Int, newText: String) { + dc_send_text_edit(contextPointer, UInt32(msgId), newText) + } + public func downloadFullMessage(id: Int) { dc_download_full_msg(contextPointer, Int32(id)) } diff --git a/deltachat-ios/DC/DcMsg.swift b/deltachat-ios/DC/DcMsg.swift index 5dd0e9369..9a400f72e 100644 --- a/deltachat-ios/DC/DcMsg.swift +++ b/deltachat-ios/DC/DcMsg.swift @@ -31,6 +31,10 @@ public class DcMsg { return dc_msg_is_forwarded(messagePointer) != 0 } + public var isEdited: Bool { + return dc_msg_is_edited(messagePointer) != 0 + } + public var isValid: Bool { return messagePointer != nil } @@ -43,7 +47,6 @@ public class DcMsg { return Int(dc_msg_get_id(messagePointer)) } - public var fromContactId: Int { return Int(dc_msg_get_from_id(messagePointer)) } @@ -103,6 +106,10 @@ public class DcMsg { } } + public var hasText: Bool { + return !(text ?? "").isEmpty + } + public var subject: String { guard let cString = dc_msg_get_subject(messagePointer) else { return "" } let swiftString = String(cString: cString)