mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Permalink Tweaks 2 (#2766)
* Missing changelog. * Parse bare room aliases as permalinks. Update the SDK. * Fix tapping the same permalink twice. Add a test. Don't clear the focussed item when reaching the bottom of the timeline. * Make sure sending a message returns to live.
This commit is contained in:
@@ -20,15 +20,18 @@ import MatrixRustSDK
|
||||
// https://spec.matrix.org/latest/appendices/#identifier-grammar
|
||||
enum MatrixEntityRegex: String {
|
||||
case homeserver
|
||||
case userId
|
||||
case userID
|
||||
case roomAlias
|
||||
case allUsers
|
||||
|
||||
var rawValue: String {
|
||||
switch self {
|
||||
case .homeserver:
|
||||
return "[A-Z0-9]+((\\.|\\-)[A-Z0-9]+){0,}(:[0-9]{2,5})?"
|
||||
case .userId:
|
||||
case .userID:
|
||||
return "@[\\x21-\\x39\\x3B-\\x7F]+:" + MatrixEntityRegex.homeserver.rawValue
|
||||
case .roomAlias:
|
||||
return "#[A-Z0-9._%#@=+-]+:" + MatrixEntityRegex.homeserver.rawValue
|
||||
case .allUsers:
|
||||
return PillConstants.atRoom
|
||||
}
|
||||
@@ -36,7 +39,8 @@ enum MatrixEntityRegex: String {
|
||||
|
||||
// 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 userIdentifierRegex = try! NSRegularExpression(pattern: MatrixEntityRegex.userID.rawValue, options: .caseInsensitive)
|
||||
static var roomAliasRegex = try! NSRegularExpression(pattern: MatrixEntityRegex.roomAlias.rawValue, options: .caseInsensitive)
|
||||
static var allUsersRegex = try! NSRegularExpression(pattern: MatrixEntityRegex.allUsers.rawValue)
|
||||
static var linkRegex = try! NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
|
||||
// swiftlint:enable force_try
|
||||
@@ -57,6 +61,14 @@ enum MatrixEntityRegex: String {
|
||||
return match.range.length == identifier.count
|
||||
}
|
||||
|
||||
static func isMatrixRoomAlias(_ alias: String) -> Bool {
|
||||
guard let match = roomAliasRegex.firstMatch(in: alias) else {
|
||||
return false
|
||||
}
|
||||
|
||||
return match.range.length == alias.count
|
||||
}
|
||||
|
||||
static func containsMatrixAllUsers(_ string: String) -> Bool {
|
||||
guard allUsersRegex.firstMatch(in: string) != nil else {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user