Merge pull request #549 from mpretty-cyro/feature/more-link-previews

Default link previews to use HTTPS
pull/561/head
RyanZhao 4 years ago committed by GitHub
commit 8a1e916bcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -385,10 +385,16 @@ public class OWSLinkPreview: MTLModel {
var urlMatches: [URLMatchResult] = []
let matches = detector.matches(in: body, options: [], range: NSRange(location: 0, length: body.count))
for match in matches {
guard let matchURL = match.url else {
continue
}
let urlString = matchURL.absoluteString
guard let matchURL = match.url else { continue }
// If the URL entered didn't have a scheme it will default to 'http', we want to catch this and
// set the scheme to 'https' instead as we don't load previews for 'http' so this will result
// in more previews actually getting loaded without forcing the user to enter 'https://' before
// every URL they enter
let urlString: String = (matchURL.absoluteString == "http://\(body)" ?
"https://\(body)" :
matchURL.absoluteString
)
if isValidLinkUrl(urlString) {
let matchResult = URLMatchResult(urlString: urlString, matchRange: match.range)
urlMatches.append(matchResult)

Loading…
Cancel
Save