Fixes vector-im/element-x-ios/issues/117 - Event permalink timeline action

* moved NSRegularExpression outside of the AttributedString builder into the MatrixEntityRegex
* fixed eventId v3 regex
* added permalink builders for users, room identifiers and aliases, and events
* added timeline item permalink contextual menu actions and error alerts
* added an app wide ServiceLocator and moved the top level userIndicatorPresenter to it.
* added URL constructor that takes a StaticString and returns an non-optional
* Include Unit and UI tests in the swiftlint search paths
This commit is contained in:
Stefan Ceriu
2022-09-12 21:34:53 +03:00
committed by GitHub
parent 4006cc6b80
commit 4660f096f8
25 changed files with 414 additions and 103 deletions
@@ -22,24 +22,6 @@ struct AttributedStringBuilder: AttributedStringBuilderProtocol {
private let temporaryCodeBlockMarkingColor = UIColor.cyan
private let linkColor = UIColor.blue
private let userIdDetector: NSRegularExpression
private let roomIdDetector: NSRegularExpression
private let eventIdDetector: NSRegularExpression
private let roomAliasDetector: NSRegularExpression
private let linkDetector: NSDataDetector
init() {
do {
userIdDetector = try NSRegularExpression(pattern: MatrixEntityRegex.userId.rawValue, options: .caseInsensitive)
roomIdDetector = try NSRegularExpression(pattern: MatrixEntityRegex.roomId.rawValue, options: .caseInsensitive)
eventIdDetector = try NSRegularExpression(pattern: MatrixEntityRegex.eventId.rawValue, options: .caseInsensitive)
roomAliasDetector = try NSRegularExpression(pattern: MatrixEntityRegex.roomAlias.rawValue, options: .caseInsensitive)
linkDetector = try NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
} catch {
fatalError()
}
}
func fromPlain(_ string: String?) async -> AttributedString? {
await Task.detached {
fromPlain(string)
@@ -181,11 +163,11 @@ struct AttributedStringBuilder: AttributedStringBuilderProtocol {
let string = attributedString.string
let range = NSRange(location: 0, length: attributedString.string.count)
var matches = userIdDetector.matches(in: string, options: [], range: range)
matches.append(contentsOf: roomIdDetector.matches(in: string, options: [], range: range))
matches.append(contentsOf: eventIdDetector.matches(in: string, options: [], range: range))
matches.append(contentsOf: roomAliasDetector.matches(in: string, options: [], range: range))
matches.append(contentsOf: linkDetector.matches(in: string, options: [], range: range))
var matches = MatrixEntityRegex.userIdentifierRegex.matches(in: string, options: [], range: range)
matches.append(contentsOf: MatrixEntityRegex.roomIdentifierRegex.matches(in: string, options: [], range: range))
matches.append(contentsOf: MatrixEntityRegex.eventIdentifierRegex.matches(in: string, options: [], range: range))
matches.append(contentsOf: MatrixEntityRegex.roomAliasRegex.matches(in: string, options: [], range: range))
matches.append(contentsOf: MatrixEntityRegex.linkRegex.matches(in: string, options: [], range: range))
guard matches.count > 0 else {
return