mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
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:
@@ -16,6 +16,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
// https://spec.matrix.org/latest/appendices/#identifier-grammar
|
||||
enum MatrixEntityRegex: String {
|
||||
case homeserver
|
||||
case userId
|
||||
@@ -34,7 +35,56 @@ enum MatrixEntityRegex: String {
|
||||
case .roomId:
|
||||
return "![A-Z0-9]+:" + MatrixEntityRegex.homeserver.rawValue
|
||||
case .eventId:
|
||||
return "\\$[A-Z0-9]+:" + MatrixEntityRegex.homeserver.rawValue
|
||||
return "\\$[A-Z0-9\\/+]+"
|
||||
}
|
||||
}
|
||||
|
||||
// swiftlint:disable force_try
|
||||
static var homeserverRegex = try! NSRegularExpression(pattern: MatrixEntityRegex.homeserver.rawValue, options: .caseInsensitive)
|
||||
static var userIdentifierRegex = try! NSRegularExpression(pattern: MatrixEntityRegex.userId.rawValue, options: .caseInsensitive)
|
||||
static var roomAliasRegex = try! NSRegularExpression(pattern: MatrixEntityRegex.roomAlias.rawValue, options: .caseInsensitive)
|
||||
static var roomIdentifierRegex = try! NSRegularExpression(pattern: MatrixEntityRegex.roomId.rawValue, options: .caseInsensitive)
|
||||
static var eventIdentifierRegex = try! NSRegularExpression(pattern: MatrixEntityRegex.eventId.rawValue, options: .caseInsensitive)
|
||||
static var linkRegex = try! NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
|
||||
// swiftlint:enable force_try
|
||||
|
||||
static func isMatrixHomeserver(_ homeserver: String) -> Bool {
|
||||
guard let match = userIdentifierRegex.firstMatch(in: homeserver, range: .init(location: 0, length: homeserver.count)) else {
|
||||
return false
|
||||
}
|
||||
|
||||
return match.range.length == homeserver.count
|
||||
}
|
||||
|
||||
static func isMatrixUserIdentifier(_ identifier: String) -> Bool {
|
||||
guard let match = userIdentifierRegex.firstMatch(in: identifier, range: .init(location: 0, length: identifier.count)) else {
|
||||
return false
|
||||
}
|
||||
|
||||
return match.range.length == identifier.count
|
||||
}
|
||||
|
||||
static func isMatrixRoomAlias(_ alias: String) -> Bool {
|
||||
guard let match = roomAliasRegex.firstMatch(in: alias, range: .init(location: 0, length: alias.count)) else {
|
||||
return false
|
||||
}
|
||||
|
||||
return match.range.length == alias.count
|
||||
}
|
||||
|
||||
static func isMatrixRoomIdentifier(_ identifier: String) -> Bool {
|
||||
guard let match = roomIdentifierRegex.firstMatch(in: identifier, range: .init(location: 0, length: identifier.count)) else {
|
||||
return false
|
||||
}
|
||||
|
||||
return match.range.length == identifier.count
|
||||
}
|
||||
|
||||
static func isMatrixEventIdentifier(_ identifier: String) -> Bool {
|
||||
guard let match = eventIdentifierRegex.firstMatch(in: identifier, range: .init(location: 0, length: identifier.count)) else {
|
||||
return false
|
||||
}
|
||||
|
||||
return match.range.length == identifier.count
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user