From 0629d086c561052d44159b8a2ad1dbd883227634 Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Fri, 14 Jan 2022 08:43:49 +1100 Subject: [PATCH] Updated the link previews to default to HTTPS --- .../Link Previews/OWSLinkPreview.swift | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/SessionMessagingKit/Sending & Receiving/Link Previews/OWSLinkPreview.swift b/SessionMessagingKit/Sending & Receiving/Link Previews/OWSLinkPreview.swift index a512f12dc..cb0cd1919 100644 --- a/SessionMessagingKit/Sending & Receiving/Link Previews/OWSLinkPreview.swift +++ b/SessionMessagingKit/Sending & Receiving/Link Previews/OWSLinkPreview.swift @@ -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)