Skip to content

Commit

Permalink
read reactions in message summary (#2608)
Browse files Browse the repository at this point in the history
  • Loading branch information
r10s authored Feb 26, 2025
1 parent 4487c3f commit 5397fad
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Share files generated by webxdc apps directly (#2606)
- Tweak menu order (#2604)
- Save space by Deduplicating files on sending (#2612)
- Accessibility: voice over reads a reaction summary for messages (#2608)
- Fix: Hide read-only chats on forwarding and sort list accordingly (#2436)
- Fix: Let 'Cancel' work as expecting when forwarding messages (#2436)
- Fix: Preserve filenames on sharing (#2605)
Expand Down
4 changes: 2 additions & 2 deletions deltachat-ios/Chat/Views/Cells/AudioMessageCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public class AudioMessageCell: BaseMessageCell, ReusableCell {
mainContentView.spacing = 0
}
if msg.type == DC_MSG_VOICE {
accessibilityLabel = String.localized("voice_message")
a11yDcType = String.localized("voice_message")
} else {
accessibilityLabel = String.localized("audio")
a11yDcType = String.localized("audio")
}

delegate?.getAudioDuration(messageId: messageId, successHandler: { [weak self] messageId, duration in
Expand Down
36 changes: 29 additions & 7 deletions deltachat-ios/Chat/Views/Cells/BaseMessageCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ public class BaseMessageCell: UITableViewCell {
private var showSelectionBackground: Bool
private var timer: Timer?

private var dcContextId: Int?
private var dcMsgId: Int?
var a11yDcType: String?

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {

reactionsView = ReactionsView()
Expand Down Expand Up @@ -517,9 +521,7 @@ public class BaseMessageCell: UITableViewCell {
}

messageLabel.attributedText = getFormattedText(messageText: msg.text, searchText: searchText, highlight: highlight)

messageLabel.delegate = self
accessibilityLabel = configureAccessibilityString(message: msg)

if let reactions = dcContext.getMessageReactions(messageId: msg.id) {
reactionsView.isHidden = false
Expand All @@ -529,6 +531,9 @@ public class BaseMessageCell: UITableViewCell {
reactionsView.isHidden = true
bottomConstraint?.constant = -3
}

self.dcContextId = dcContext.id
self.dcMsgId = msg.id
}

private func getFormattedText(messageText: String?, searchText: String?, highlight: Bool) -> NSAttributedString? {
Expand Down Expand Up @@ -568,7 +573,13 @@ public class BaseMessageCell: UITableViewCell {
return nil
}

func configureAccessibilityString(message: DcMsg) -> String {
public override func accessibilityElementDidBecomeFocused() {
logger.info("jit-rendering accessibility string") // jit-rendering is needed as the reactions summary require quite some database calls
guard let dcContextId, let dcMsgId else { return }
let dcContext = DcAccounts.shared.get(id: dcContextId)
let msg = dcContext.getMessage(id: dcMsgId)
let reactions = dcContext.getMessageReactions(messageId: msg.id)

var topLabelAccessibilityString = ""
var quoteAccessibilityString = ""
var messageLabelAccessibilityString = ""
Expand All @@ -583,15 +594,24 @@ public class BaseMessageCell: UITableViewCell {
if let senderTitle = quoteView.senderTitle.text, let quote = quoteView.quote.text {
quoteAccessibilityString = "\(senderTitle), \(quote), \(String.localized("reply_noun")), "
}
if let additionalAccessibilityInfo = accessibilityLabel {
additionalAccessibilityString = "\(additionalAccessibilityInfo), "
if let a11yDcType {
additionalAccessibilityString = "\(a11yDcType), "
}

var reactionsString = ""
if let reactions {
reactionsString = ", " + String.localized(stringID: "n_reactions", parameter: reactions.reactionsByContact.count) + ": "
for (contactId, reactions) in reactions.reactionsByContact {
reactionsString += dcContext.getContact(id: contactId).displayName + ": " + reactions.joined(separator: " ") + ", "
}
}

return "\(topLabelAccessibilityString) " +
accessibilityLabel = "\(topLabelAccessibilityString) " +
"\(quoteAccessibilityString) " +
"\(additionalAccessibilityString) " +
"\(messageLabelAccessibilityString) " +
"\(StatusView.getAccessibilityString(message: message))"
"\(StatusView.getAccessibilityString(message: msg))" +
"\(reactionsString) "
}

func getBackgroundColor(dcContext: DcContext, message: DcMsg) -> UIColor {
Expand Down Expand Up @@ -637,6 +657,8 @@ public class BaseMessageCell: UITableViewCell {
reactionsView.prepareForReuse()
timer?.invalidate()
timer = nil
dcContextId = nil
dcMsgId = nil
}

@objc func reactionsViewTapped(_ sender: Any?) {
Expand Down
2 changes: 1 addition & 1 deletion deltachat-ios/Chat/Views/Cells/ContactCardCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ContactCardCell: BaseMessageCell, ReusableCell {
}

contactView.configure(message: msg, dcContext: dcContext)
accessibilityLabel = "\(String.localized("document")), \(contactView.configureAccessibilityLabel())"
a11yDcType = "\(String.localized("document")), \(contactView.configureAccessibilityLabel())"
super.update(dcContext: dcContext,
msg: msg,
messageStyle: messageStyle,
Expand Down
2 changes: 1 addition & 1 deletion deltachat-ios/Chat/Views/Cells/FileTextCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class FileTextCell: BaseMessageCell, ReusableCell {
}

fileView.configure(message: msg)
accessibilityLabel = "\(String.localized("document")), \(fileView.configureAccessibilityLabel())"
a11yDcType = "\(String.localized("document")), \(fileView.configureAccessibilityLabel())"
super.update(dcContext: dcContext,
msg: msg,
messageStyle: messageStyle,
Expand Down
4 changes: 2 additions & 2 deletions deltachat-ios/Chat/Views/Cells/ImageTextCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ class ImageTextCell: BaseMessageCell, ReusableCell {
size: CGSize(width: 500, height: 500)))
contentImageIsPlaceholder = false
playButtonView.isHidden = true
accessibilityLabel = msg.type == DC_MSG_GIF ? String.localized("gif") : String.localized("image")
a11yDcType = msg.type == DC_MSG_GIF ? String.localized("gif") : String.localized("image")
setAspectRatioFor(message: msg)
} else if msg.type == DC_MSG_VIDEO, let url = msg.fileURL {
playButtonView.isHidden = false
accessibilityLabel = String.localized("video")
a11yDcType = String.localized("video")
let placeholderImage = UIImage(color: UIColor.init(alpha: 0, red: 255, green: 255, blue: 255), size: CGSize(width: 250, height: 250))
contentImageView.image = placeholderImage
DispatchQueue.global(qos: .userInteractive).async {
Expand Down
2 changes: 1 addition & 1 deletion deltachat-ios/Chat/Views/Cells/WebxdcCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public class WebxdcCell: FileTextCell {
showName: showName,
searchText: searchText,
highlight: highlight)
accessibilityLabel = fileView.configureAccessibilityLabel()
a11yDcType = fileView.configureAccessibilityLabel()
}
}

0 comments on commit 5397fad

Please sign in to comment.