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 452a4c12b8
commit addd5827ea
27 changed files with 418 additions and 232 deletions

View File

@@ -285,7 +285,7 @@ struct AttributedStringBuilder: AttributedStringBuilderProtocol {
if let url = value as? URL, let matrixEntity = parseMatrixEntityFrom(uri: url.absoluteString) {
switch matrixEntity.id {
case .user(let userID):
mentionBuilder.handleUserMention(for: attributedString, in: range, url: url, userID: userID)
mentionBuilder.handleUserMention(for: attributedString, in: range, url: url, userID: userID, userDisplayName: nil)
case .room(let roomID):
attributedString.addAttributes([.MatrixRoomID: roomID], range: range)
case .roomAlias(let alias):
@@ -362,6 +362,7 @@ extension NSAttributedString.Key {
static let DTTextBlocks: NSAttributedString.Key = .init(rawValue: DTTextBlocksAttribute)
static let MatrixBlockquote: NSAttributedString.Key = .init(rawValue: BlockquoteAttribute.name)
static let MatrixUserID: NSAttributedString.Key = .init(rawValue: UserIDAttribute.name)
static let MatrixUserDisplayName: NSAttributedString.Key = .init(rawValue: UserDisplayNameAttribute.name)
static let MatrixRoomID: NSAttributedString.Key = .init(rawValue: RoomIDAttribute.name)
static let MatrixRoomAlias: NSAttributedString.Key = .init(rawValue: RoomAliasAttribute.name)
static let MatrixEventOnRoomID: NSAttributedString.Key = .init(rawValue: EventOnRoomIDAttribute.name)
@@ -370,7 +371,7 @@ extension NSAttributedString.Key {
}
protocol 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?)
func handleAllUsersMention(for attributedString: NSMutableAttributedString, in range: NSRange)
}

View File

@@ -26,4 +26,6 @@ protocol AttributedStringBuilderProtocol {
func fromPlain(_ string: String?) -> AttributedString?
func fromHTML(_ htmlString: String?) -> AttributedString?
func detectPermalinks(_ attributedString: NSMutableAttributedString)
}

View File

@@ -26,6 +26,13 @@ enum UserIDAttribute: AttributedStringKey {
static var name = "MXUserIDAttribute"
}
/// This attribute is used to help the composer convert a mention into to a markdown link before sending
/// the message. It doesn't interact mention pills, as these fetch display names live from the room.
enum UserDisplayNameAttribute: AttributedStringKey {
typealias Value = String
static var name = "MXUserDisplayNameAttribute"
}
enum RoomIDAttribute: AttributedStringKey {
typealias Value = String
static var name = "MXRoomIDAttribute"
@@ -65,6 +72,7 @@ extension AttributeScopes {
let blockquote: BlockquoteAttribute
let userID: UserIDAttribute
let userDisplayName: UserDisplayNameAttribute
let roomID: RoomIDAttribute
let roomAlias: RoomAliasAttribute
let eventOnRoomID: EventOnRoomIDAttribute