Remove remote filter updating

This commit is contained in:
Justin Mazzocchi 2021-01-28 17:14:34 -08:00
parent b910afe671
commit 41cd030734
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
4 changed files with 2 additions and 99 deletions

View file

@ -62,31 +62,12 @@ public extension InstanceURLService {
.map { _ in true }
.eraseToAnyPublisher()
}
func updateFilter() -> AnyPublisher<Never, Error> {
httpClient.request(UpdatedFilterTarget())
.handleEvents(receiveOutput: { appPreferences.updateInstanceFilter($0) })
.ignoreOutput()
.eraseToAnyPublisher()
}
}
private struct UpdatedFilterTarget: DecodableTarget {
typealias ResultType = BloomFilter<String>
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<String>(
static let filter = BloomFilter<String>(
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<String> {
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
}
}

View file

@ -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<String>(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
}
}
}

View file

@ -50,12 +50,6 @@ final class AddIdentityViewController: UIViewController {
setupViewModelBindings()
initialDisplay()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
viewModel.refreshFilter()
}
}
private extension AddIdentityViewController {

View file

@ -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)
}