Handle urls sent in messages without a scheme (ie apple.com)

This commit is contained in:
Garth Vander Houwen 2022-12-24 17:03:53 -08:00
parent 1f54338ab9
commit 33e6193543
2 changed files with 7 additions and 4 deletions

View file

@ -19,6 +19,7 @@ func generateMessageMarkdown (message: String) -> String {
for match in matches {
guard let range = Range(match.range, in: message) else { continue }
print(match.url ?? "No URL")
if match.resultType == .address {
let address = message[range]
let urlEncodedAddress = address.addingPercentEncoding(withAllowedCharacters: .alphanumerics)
@ -27,8 +28,10 @@ func generateMessageMarkdown (message: String) -> String {
let phone = messageWithMarkdown[range]
messageWithMarkdown = messageWithMarkdown.replacingOccurrences(of: phone, with: "[\(phone)](tel:\(phone))")
} else if match.resultType == .link {
let url = messageWithMarkdown[range]
messageWithMarkdown = messageWithMarkdown.replacingOccurrences(of: url, with: "[\(String(match.url?.host ?? "Link"))\(String(match.url?.path ?? ""))](\(url))")
let url = match.url?.absoluteString ?? ""
if url.count > 0 {
messageWithMarkdown = messageWithMarkdown.replacingOccurrences(of: url, with: "[\(String(match.url?.host ?? "Link"))\(String(match.url?.path ?? ""))](\(url))")
}
}
}
}

View file

@ -61,9 +61,9 @@ struct ChannelMessageList: View {
}
VStack(alignment: currentUser ? .trailing : .leading) {
let markdownText: LocalizedStringKey = LocalizedStringKey.init(message.messagePayloadMarkdown ?? (message.messagePayload ?? "EMPTY MESSAGE"))
let skyBlue = Color(red: 0.4627, green: 0.8392, blue: 1.0)
let linkBlue = Color(red: 0.4627, green: 0.8392, blue: 1) /* #76d6ff */
Text(markdownText)
.tint(skyBlue)
.tint(linkBlue)
.padding(10)
.foregroundColor(.white)
.background(currentUser ? .accentColor : Color(.gray))