Skip to content

Commit

Permalink
add edit option
Browse files Browse the repository at this point in the history
  • Loading branch information
r10s committed Feb 15, 2025
1 parent 140a173 commit cc6406c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
20 changes: 20 additions & 0 deletions deltachat-ios/Chat/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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: "edit_text", systemImageName: "pencil", indexPath: indexPath, action: editSentMessage)
)
}

if !dcChat.isSelfTalk && message.canSave {
if message.savedMessageId != 0 {
children.append(
Expand Down
6 changes: 5 additions & 1 deletion deltachat-ios/Chat/Views/StatusView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 4 additions & 0 deletions deltachat-ios/DC/DcContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check failure on line 66 in deltachat-ios/DC/DcContext.swift

View workflow job for this annotation

GitHub Actions / build

cannot find 'dc_send_text_edit' in scope
}

public func downloadFullMessage(id: Int) {
dc_download_full_msg(contextPointer, Int32(id))
}
Expand Down
9 changes: 8 additions & 1 deletion deltachat-ios/DC/DcMsg.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 35 in deltachat-ios/DC/DcMsg.swift

View workflow job for this annotation

GitHub Actions / build

cannot find 'dc_msg_is_edited' in scope
}

public var isValid: Bool {
return messagePointer != nil
}
Expand All @@ -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))
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit cc6406c

Please sign in to comment.