Plain composer suggestions and pills (#2751)

* Move ComposerToolbar files to withing the RoomScreen folder (as it's not a screen on its own)

* Switch the plain composer to NSAttributedStrings

* Enable suggestions on the plain composer

* Introduce a new `MatrixUserDisplayName` attributed string attributed and use it for mention building

* Implement mention pill rendering and sending on the plain message composer

* Fix plain composer snapshot tests

* Fix broken formatting options layout

* Add clarifying comment.
This commit is contained in:
Stefan Ceriu
2024-05-03 12:06:16 +03:00
committed by GitHub
parent d067e844da
commit 38416dbb5c
27 changed files with 418 additions and 232 deletions
@@ -18,7 +18,7 @@ import Foundation
import UIKit
struct MentionBuilder: MentionBuilderProtocol {
func handleUserMention(for attributedString: NSMutableAttributedString, in range: NSRange, url: URL, userID: String) {
func handleUserMention(for attributedString: NSMutableAttributedString, in range: NSRange, url: URL, userID: String, userDisplayName: String?) {
let attributes = attributedString.attributes(at: 0, longestEffectiveRange: nil, in: range)
let font = attributes[.font] as? UIFont ?? .preferredFont(forTextStyle: .body)
let blockquote = attributes[.MatrixBlockquote]
@@ -26,7 +26,12 @@ struct MentionBuilder: MentionBuilderProtocol {
let attachmentData = PillTextAttachmentData(type: .user(userID: userID), font: font)
guard let attachment = PillTextAttachment(attachmentData: attachmentData) else {
attributedString.addAttributes([.MatrixUserID: userID], range: range)
attributedString.addAttribute(.MatrixUserID, value: userID, range: range)
if let userDisplayName {
attributedString.addAttribute(.MatrixUserDisplayName, value: userDisplayName, range: range)
}
return
}
@@ -20,7 +20,7 @@ import Foundation
struct PlainMentionBuilder: MentionBuilderProtocol {
func handleAllUsersMention(for attributedString: NSMutableAttributedString, in range: NSRange) { }
func handleUserMention(for attributedString: NSMutableAttributedString, in range: NSRange, url: URL, userID: String) {
func handleUserMention(for attributedString: NSMutableAttributedString, in range: NSRange, url: URL, userID: String, userDisplayName: String?) {
guard !attributedString.attributedSubstring(from: range).string.hasPrefix("@") else {
return
}