Skip to content

Commit

Permalink
create accessibility string jit
Browse files Browse the repository at this point in the history
  • Loading branch information
r10s committed Feb 14, 2025
1 parent 0f54a3b commit 4698115
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 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,9 @@ public class BaseMessageCell: UITableViewCell {
private var showSelectionBackground: Bool
private var timer: Timer?

private var dcContextId: Int?
private var dcMsgId: Int?

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

reactionsView = ReactionsView()
Expand Down Expand Up @@ -519,8 +522,7 @@ public class BaseMessageCell: UITableViewCell {
messageLabel.attributedText = getFormattedText(messageText: msg.text, searchText: searchText, highlight: highlight)
messageLabel.delegate = self

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

accessibilityLabel = configureAccessibilityString(message: msg, reactions: reactions)
self.dcContextId = dcContext.id
self.dcMsgId = msg.id
}

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

func configureAccessibilityString(message: DcMsg, reactions: DcReactions?) -> 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 @@ -590,19 +599,18 @@ public class BaseMessageCell: UITableViewCell {

var reactionsString = ""
if let reactions {
// make sure not to add database calls here, this is rarely used but would slow things down always
reactionsString = ", " + String.localized(stringID: "n_reactions", parameter: reactions.reactionsByContact.count) + ": "
reactions.reactions.forEach {
reactionsString += $0.count > 1 ? " \($0.count)" : ""
reactionsString += " \($0.emoji)"
}
}

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

Expand Down Expand Up @@ -649,6 +657,8 @@ public class BaseMessageCell: UITableViewCell {
reactionsView.prepareForReuse()
timer?.invalidate()
timer = nil
dcContextId = nil
dcMsgId = nil
}

@objc func reactionsViewTapped(_ sender: Any?) {
Expand Down

0 comments on commit 4698115

Please sign in to comment.