Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

edit messages #2611

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased
2025-02

- Edit messages sent by you (#6550)
- Share files generated by webxdc apps directly (#2606)
- Tweak menu order (#2604)
- Save space by Deduplicating files on sending (#2612)
Expand Down
34 changes: 29 additions & 5 deletions deltachat-ios/Chat/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ class ChatViewController: UITableViewController, UITableViewDropDelegate {
messageInputBar.inputTextView.resignFirstResponder()
} else {
messageInputBar.setMiddleContentView(messageInputBar.inputTextView, animated: false)
messageInputBar.setLeftStackViewWidthConstant(to: 40, animated: false)
messageInputBar.setLeftStackViewWidthConstant(to: draft.sendEditRequestFor == nil ? 40 : 0, animated: false)
messageInputBar.setRightStackViewWidthConstant(to: 40, animated: false)
messageInputBar.padding = UIEdgeInsets(top: 6, left: 6, bottom: 6, right: 12)
inputAccessoryView = messageInputBar
Expand Down Expand Up @@ -1665,6 +1665,15 @@ class ChatViewController: UITableViewController, UITableViewDropDelegate {
replyToMessage(at: indexPath)
}

private func editSentMessage(at indexPath: IndexPath) {
let message = dcContext.getMessage(id: messageIds[indexPath.row])

draft.clear()
draft.sendEditRequestFor = message.id
configureDraftArea(draft: draft)
messageInputBar.inputTextView.text = message.text
}

private func toggleSave(at indexPath: IndexPath) {
let message = dcContext.getMessage(id: messageIds[indexPath.row])
if message.savedMessageId != 0 {
Expand Down Expand Up @@ -1909,6 +1918,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(
Expand Down Expand Up @@ -2364,7 +2379,10 @@ extension ChatViewController: InputBarAccessoryViewDelegate {
func inputBar(_ inputBar: InputBarAccessoryView, didPressSendButtonWith text: String) {
let trimmedText = text.replacingOccurrences(of: "\u{FFFC}", with: "", options: .literal, range: nil)
.trimmingCharacters(in: .whitespacesAndNewlines)
if let filePath = draft.attachment, let viewType = draft.viewType {

if let sendEditRequestFor = draft.sendEditRequestFor {
dcContext.sendEditRequest(msgId: sendEditRequestFor, newText: text)
} else if let filePath = draft.attachment, let viewType = draft.viewType {
switch viewType {
case DC_MSG_GIF, DC_MSG_IMAGE, DC_MSG_FILE, DC_MSG_VIDEO, DC_MSG_WEBXDC, DC_MSG_VCARD:
self.sendAttachmentMessage(viewType: viewType, filePath: filePath, message: trimmedText, quoteMessage: draft.quoteMessage)
Expand Down Expand Up @@ -2392,9 +2410,15 @@ extension ChatViewController: InputBarAccessoryViewDelegate {
// MARK: - DraftPreviewDelegate
extension ChatViewController: DraftPreviewDelegate {
func onCancelQuote() {
draft.setQuote(quotedMsg: nil)
configureDraftArea(draft: draft)
focusInputTextView()
if draft.sendEditRequestFor != nil {
draft.clear()
draftArea.cancel()
messageInputBar.inputTextView.text = nil
} else {
draft.setQuote(quotedMsg: nil)
configureDraftArea(draft: draft)
focusInputTextView()
}
}

func onCancelAttachment() {
Expand Down
10 changes: 9 additions & 1 deletion deltachat-ios/Chat/DraftModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ public class DraftModel {
var dcContext: DcContext
var text: String?
let chatId: Int
var isEditing: Bool = false
var isEditing: Bool = false // multi edit
var sendEditRequestFor: Int?
var quoteMessage: DcMsg? {
return draftMsg?.quoteMessage
}
Expand Down Expand Up @@ -39,6 +40,7 @@ public class DraftModel {
draftMsg = dcContext.newMessage(viewType: DC_MSG_TEXT)
}
draftMsg?.quoteMessage = quotedMsg
sendEditRequestFor = nil
}

public func setAttachment(viewType: Int32?, path: String?, mimetype: String? = nil) {
Expand All @@ -62,6 +64,11 @@ public class DraftModel {
}

public func save(context: DcContext) {
if sendEditRequestFor != nil {
clear()
return
}

if (text?.isEmpty ?? true) &&
(draftMsg == nil || quoteMessage == nil && attachment == nil) {
self.clear()
Expand All @@ -82,6 +89,7 @@ public class DraftModel {
public func clear() {
text = nil
draftMsg = nil
sendEditRequestFor = nil
dcContext.setDraft(chatId: chatId, message: nil)
}
}
9 changes: 8 additions & 1 deletion deltachat-ios/Chat/Views/QuotePreview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ public class QuotePreview: DraftPreview {
}

override public func configure(draft: DraftModel) {
if !draft.isEditing,
if !draft.isEditing, let sendEditRequestFor = draft.sendEditRequestFor {
quoteView.senderTitle.text = String.localized("edit_message")
quoteView.senderTitle.textColor = DcColors.unknownSender
quoteView.quote.text = draft.dcContext.getMessage(id: sendEditRequestFor).text
quoteView.setImagePreview(nil)
quoteView.citeBar.backgroundColor = DcColors.unknownSender
isHidden = false
} else if !draft.isEditing,
let quoteText = draft.quoteText {
quoteView.quote.text = quoteText
compactView = draft.attachment != nil
Expand Down
13 changes: 11 additions & 2 deletions deltachat-ios/Chat/Views/StatusView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import DcCore
public class StatusView: UIView {
private let contentStackView: UIStackView
let dateLabel: UILabel
private let editedLabel: UILabel
private let padlockView: UIImageView
private let locationView: UIImageView
private let stateView: UIImageView
Expand All @@ -16,6 +17,11 @@ public class StatusView: UIView {
dateLabel.translatesAutoresizingMaskIntoConstraints = false
dateLabel.font = UIFont.preferredFont(for: .caption1, weight: .regular)

editedLabel = UILabel()
editedLabel.text = String.localized("edited")
editedLabel.translatesAutoresizingMaskIntoConstraints = false
editedLabel.font = UIFont.preferredFont(for: .caption1, weight: .regular)

padlockView = UIImageView()
padlockView.translatesAutoresizingMaskIntoConstraints = false
locationView = UIImageView()
Expand All @@ -25,9 +31,9 @@ public class StatusView: UIView {
savedView = UIImageView()
savedView.translatesAutoresizingMaskIntoConstraints = false

contentStackView = UIStackView(arrangedSubviews: [savedView, padlockView, dateLabel, locationView, stateView])
contentStackView = UIStackView(arrangedSubviews: [savedView, padlockView, dateLabel, editedLabel, locationView, stateView])
contentStackView.alignment = .center
contentStackView.spacing = 0
contentStackView.spacing = 2
contentStackView.translatesAutoresizingMaskIntoConstraints = false

super.init(frame: frame)
Expand Down Expand Up @@ -68,6 +74,7 @@ public class StatusView: UIView {

public func prepareForReuse() {
dateLabel.text = nil
editedLabel.isHidden = true
padlockView.isHidden = true
locationView.isHidden = true
savedView.isHidden = true
Expand All @@ -77,6 +84,8 @@ public class StatusView: UIView {
public func update(message: DcMsg, tintColor: UIColor) {
dateLabel.text = message.formattedSentDate()
dateLabel.textColor = tintColor
editedLabel.isHidden = !message.isEdited
editedLabel.textColor = tintColor

if message.showPadlock() {
padlockView.image = UIImage(named: "ic_lock")?.maskWithColor(color: tintColor)
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 @@
dc_send_msg(contextPointer, UInt32(chatId), message.messagePointer)
}

public func sendEditRequest(msgId: Int, newText: String) {
dc_send_edit_request(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_edit_request' 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 @@
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 @@
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 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
Loading