Replies now display mentions with @displayname (#1957)

* reply with mentions

* fixed a bug and wrote a test for it

* error message
This commit is contained in:
Mauro
2023-10-25 18:39:18 +02:00
committed by GitHub
parent c020ba2d85
commit c04e812a02
7 changed files with 132 additions and 44 deletions
+11 -4
View File
@@ -67,7 +67,12 @@ struct MessageText: UIViewRepresentable {
let textView = MessageTextView(usingTextLayoutManager: false)
textView.roomContext = viewModel
textView.updateClosure = {
attributedString = AttributedString(textView.attributedText)
do {
attributedString = try AttributedString(textView.attributedText, including: \.elementX)
} catch {
MXLog.error("[MessageText] Failed to update attributedString: \(error)]")
return
}
}
textView.isEditable = false
textView.isScrollEnabled = false
@@ -87,14 +92,16 @@ struct MessageText: UIViewRepresentable {
textView.textContainer.lineFragmentPadding = 0
textView.layoutManager.usesFontLeading = false
textView.backgroundColor = .clear
textView.attributedText = NSAttributedString(attributedString)
if let attributedText = try? NSAttributedString(attributedString, including: \.elementX) {
textView.attributedText = attributedText
}
textView.delegate = context.coordinator
return textView
}
func updateUIView(_ uiView: MessageTextView, context: Context) {
let newAttributedText = NSAttributedString(attributedString)
if uiView.attributedText != newAttributedText {
if let newAttributedText = try? NSAttributedString(attributedString, including: \.elementX),
uiView.attributedText != newAttributedText {
uiView.flushPills()
uiView.attributedText = newAttributedText
}