From c50a77ddd09db4b51974a274e90a6466adb74e45 Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Mon, 8 Feb 2021 12:36:54 -0800 Subject: [PATCH] Don't send non-HTTP URLs to SFSafariViewController --- Extensions/URL+Extensions.swift | 8 ++++++++ View Controllers/TableViewController.swift | 2 +- .../ViewModels/View Models/CollectionItemsViewModel.swift | 6 +++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Extensions/URL+Extensions.swift b/Extensions/URL+Extensions.swift index d048857..ac0bce2 100644 --- a/Extensions/URL+Extensions.swift +++ b/Extensions/URL+Extensions.swift @@ -2,6 +2,14 @@ import Foundation +extension URL { + var isHTTPURL: Bool { + guard let scheme = scheme else { return false } + + return scheme == "http" || scheme == "https" + } +} + extension URL: Identifiable { public var id: String { absoluteString } } diff --git a/View Controllers/TableViewController.swift b/View Controllers/TableViewController.swift index 741812a..daa2961 100644 --- a/View Controllers/TableViewController.swift +++ b/View Controllers/TableViewController.swift @@ -451,7 +451,7 @@ private extension TableViewController { func open(url: URL) { func openWithRegardToBrowserSetting(url: URL) { - if viewModel.identityContext.appPreferences.openLinksInDefaultBrowser { + if viewModel.identityContext.appPreferences.openLinksInDefaultBrowser || !url.isHTTPURL { UIApplication.shared.open(url) } else { present(SFSafariViewController(url: url), animated: true) diff --git a/ViewModels/Sources/ViewModels/View Models/CollectionItemsViewModel.swift b/ViewModels/Sources/ViewModels/View Models/CollectionItemsViewModel.swift index 5158773..c658daf 100644 --- a/ViewModels/Sources/ViewModels/View Models/CollectionItemsViewModel.swift +++ b/ViewModels/Sources/ViewModels/View Models/CollectionItemsViewModel.swift @@ -54,7 +54,11 @@ public class CollectionItemsViewModel: ObservableObject { markerScrollPositionItemId = identityContext.service.getLocalLastReadId(timeline: timeline) } - lastReadId.compactMap { $0 } + lastReadId + .filter { _ in + identityContext.appPreferences.positionBehavior(timeline: timeline) == .localRememberPosition + } + .compactMap { $0 } .removeDuplicates() .debounce(for: .seconds(Self.lastReadIdDebounceInterval), scheduler: DispatchQueue.global()) .flatMap { identityContext.service.setLocalLastReadId($0, timeline: timeline) }