From 41cd03073404eaa42f8f55e43321da507c5f8f9d Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Thu, 28 Jan 2021 17:14:34 -0800 Subject: [PATCH] Remove remote filter updating --- .../Services/InstanceURLService.swift | 27 +------- .../InstanceURLServiceTests.swift | 62 ------------------- .../AddIdentityViewController.swift | 6 -- .../View Models/AddIdentityViewModel.swift | 6 -- 4 files changed, 2 insertions(+), 99 deletions(-) diff --git a/ServiceLayer/Sources/ServiceLayer/Services/InstanceURLService.swift b/ServiceLayer/Sources/ServiceLayer/Services/InstanceURLService.swift index 632de38..7dc9e87 100644 --- a/ServiceLayer/Sources/ServiceLayer/Services/InstanceURLService.swift +++ b/ServiceLayer/Sources/ServiceLayer/Services/InstanceURLService.swift @@ -62,31 +62,12 @@ public extension InstanceURLService { .map { _ in true } .eraseToAnyPublisher() } - - func updateFilter() -> AnyPublisher { - httpClient.request(UpdatedFilterTarget()) - .handleEvents(receiveOutput: { appPreferences.updateInstanceFilter($0) }) - .ignoreOutput() - .eraseToAnyPublisher() - } -} - -private struct UpdatedFilterTarget: DecodableTarget { - typealias ResultType = BloomFilter - - let baseURL = URL(string: "https://filter.metabolist.com")! - let pathComponents = ["filter"] - let method = HTTPMethod.get - let queryParameters: [URLQueryItem] = [] - let jsonBody: [String: Any]? = nil - let multipartFormData: [String: MultipartFormValue]? = nil - let headers: [String: String]? = nil } private extension InstanceURLService { static let httpsPrefix = "https://" static let shortestPossibleURLLength = 4 - static let defaultFilter = BloomFilter( + static let filter = BloomFilter( hashes: [.djb232, .djb2a32, .sdbm32, .fnv132, .fnv1a32], data: Data([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -123,10 +104,6 @@ private extension InstanceURLService { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0 ])) - var filter: BloomFilter { - appPreferences.updatedInstanceFilter ?? Self.defaultFilter - } - private func isFiltered(url: URL) -> Bool { guard let host = url.host else { return true } @@ -136,7 +113,7 @@ private extension InstanceURLService { for component in allHostComponents.reversed() { hostComponents.insert(component, at: 0) - if filter.contains(hostComponents.joined(separator: ".")) { + if Self.filter.contains(hostComponents.joined(separator: ".")) { return true } } diff --git a/ServiceLayer/Tests/ServiceLayerTests/InstanceURLServiceTests.swift b/ServiceLayer/Tests/ServiceLayerTests/InstanceURLServiceTests.swift index 5957305..5bfac92 100644 --- a/ServiceLayer/Tests/ServiceLayerTests/InstanceURLServiceTests.swift +++ b/ServiceLayer/Tests/ServiceLayerTests/InstanceURLServiceTests.swift @@ -34,66 +34,4 @@ final class InstanceURLServiceTests: XCTestCase { return } } - - func testUpdating() throws { - let environment = AppEnvironment.mock() - var sut = InstanceURLService(environment: environment) - - guard case let .failure(error0) = sut.url(text: "filtered.instance"), - case InstanceURLError.instanceNotSupported = error0 - else { - XCTFail("Expected instance not supported error") - - return - } - - guard case .success = sut.url(text: "instance.filtered") else { - XCTFail("Expected success") - - return - } - - var updatedFilter = BloomFilter(hashes: [.djb232, .sdbm32], byteCount: 16) - - updatedFilter.insert("instance.filtered") - - let updatedFilterData = try JSONEncoder().encode(updatedFilter) - let stub: HTTPStub = .success((HTTPURLResponse(), updatedFilterData)) - - StubbingURLProtocol.setStub(stub, forURL: URL(string: "https://filter.metabolist.com/filter")!) - - let updateRecorder = sut.updateFilter().collect().record() - - _ = try wait(for: updateRecorder.next(), timeout: 1) - - guard case .success = sut.url(text: "filtered.instance") else { - XCTFail("Expected success") - - return - } - - guard case let .failure(error1) = sut.url(text: "instance.filtered"), - case InstanceURLError.instanceNotSupported = error1 - else { - XCTFail("Expected instance not supported error") - - return - } - - sut = InstanceURLService(environment: environment) - - guard case .success = sut.url(text: "filtered.instance") else { - XCTFail("Expected success") - - return - } - - guard case let .failure(error2) = sut.url(text: "instance.filtered"), - case InstanceURLError.instanceNotSupported = error2 - else { - XCTFail("Expected instance not supported error") - - return - } - } } diff --git a/View Controllers/AddIdentityViewController.swift b/View Controllers/AddIdentityViewController.swift index 29d8603..b87eb8d 100644 --- a/View Controllers/AddIdentityViewController.swift +++ b/View Controllers/AddIdentityViewController.swift @@ -50,12 +50,6 @@ final class AddIdentityViewController: UIViewController { setupViewModelBindings() initialDisplay() } - - override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(true) - - viewModel.refreshFilter() - } } private extension AddIdentityViewController { diff --git a/ViewModels/Sources/ViewModels/View Models/AddIdentityViewModel.swift b/ViewModels/Sources/ViewModels/View Models/AddIdentityViewModel.swift index e653b55..8f327f9 100644 --- a/ViewModels/Sources/ViewModels/View Models/AddIdentityViewModel.swift +++ b/ViewModels/Sources/ViewModels/View Models/AddIdentityViewModel.swift @@ -74,12 +74,6 @@ public extension AddIdentityViewModel { addIdentity(kind: .browsing) } - func refreshFilter() { - instanceURLService.updateFilter() - .sink { _ in } receiveValue: { _ in } - .store(in: &cancellables) - } - func registrationViewModel(instance: Instance, url: URL) -> RegistrationViewModel { RegistrationViewModel(instance: instance, url: url, allIdentitiesService: allIdentitiesService) }