Merge branch 'feature/6393_fix_display_permalink_to_message_as_pill' into 'develop'

fix: display permalink to message as pill (MESSENGER-6393)

See merge request bwmessenger/bundesmessenger/bundesmessenger-ios!400
This commit is contained in:
JanNiklas Grabowski
2024-09-05 11:27:03 +00:00

View File

@@ -56,7 +56,17 @@ struct PillProvider {
// Do not pillify an url if it is a markdown or an http link (except for user and room) with a custom text
// First, we need to handle the case where the label can contains more than one # (room alias)
var urlFromLabel = URL(string: label)?.absoluteURL
var urlFromLabel: URL?
/*
BWI: 6393 fix permalink to message not displayed as pill.
Due to changes in the latest iOS version, we need to remove the percent encoding from the label before searching for markdown or an http link.
The URL extracted from an attributed string now returns a URL without percent encoding. Checking against the encoded label will always fail.
*/
if #available(iOS 18.0, *) {
urlFromLabel = URL(string: label.removingPercentEncoding ?? label)?.absoluteURL
} else {
urlFromLabel = URL(string: label)?.absoluteURL
}
if urlFromLabel == nil, label.filter({ $0 == "#" }).count > 1 {
if let escapedLabel = label.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed), let url = URL(string: escapedLabel) {
urlFromLabel = Tools.fixURL(withSeveralHashKeys: url)