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:
Doug
2024-04-29 17:32:16 +01:00
committed by GitHub
parent aaa8af2996
commit 7c94ed98a5
18 changed files with 111 additions and 52 deletions
@@ -218,6 +218,16 @@ struct AttributedStringBuilder: AttributedStringBuilderProtocol {
return TextParsingMatch(type: .userID(identifier: identifier), range: match.range)
}
matches.append(contentsOf: MatrixEntityRegex.roomAliasRegex.matches(in: string, options: []).compactMap { match in
guard let matchRange = Range(match.range, in: string) else {
return nil
}
let alias = String(string[matchRange])
return TextParsingMatch(type: .roomAlias(alias: alias), range: match.range)
})
matches.append(contentsOf: MatrixEntityRegex.linkRegex.matches(in: string, options: []).compactMap { match in
guard let matchRange = Range(match.range, in: string) else {
return nil
@@ -257,6 +267,10 @@ struct AttributedStringBuilder: AttributedStringBuilderProtocol {
switch match.type {
case .atRoom:
attributedString.addAttribute(.MatrixAllUsersMention, value: true, range: match.range)
case .roomAlias(let alias):
if let url = try? matrixToRoomAliasPermalink(roomAlias: alias) {
attributedString.addAttribute(.link, value: url, range: match.range)
}
case .userID, .link:
if let url = match.link {
attributedString.addAttribute(.link, value: url, range: match.range)
@@ -363,6 +377,7 @@ protocol MentionBuilderProtocol {
private struct TextParsingMatch {
enum MatchType {
case userID(identifier: String)
case roomAlias(alias: String)
case link(urlString: String)
case atRoom
}