mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-25 09:41:00 +00:00
Remove remote filter updating
This commit is contained in:
parent
b910afe671
commit
41cd030734
4 changed files with 2 additions and 99 deletions
|
@ -62,31 +62,12 @@ public extension InstanceURLService {
|
||||||
.map { _ in true }
|
.map { _ in true }
|
||||||
.eraseToAnyPublisher()
|
.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 {
|
private extension InstanceURLService {
|
||||||
static let httpsPrefix = "https://"
|
static let httpsPrefix = "https://"
|
||||||
static let shortestPossibleURLLength = 4
|
static let shortestPossibleURLLength = 4
|
||||||
static let defaultFilter = BloomFilter<String>(
|
static let filter = BloomFilter<String>(
|
||||||
hashes: [.djb232, .djb2a32, .sdbm32, .fnv132, .fnv1a32],
|
hashes: [.djb232, .djb2a32, .sdbm32, .fnv132, .fnv1a32],
|
||||||
data: Data([
|
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,
|
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
|
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 {
|
private func isFiltered(url: URL) -> Bool {
|
||||||
guard let host = url.host else { return true }
|
guard let host = url.host else { return true }
|
||||||
|
|
||||||
|
@ -136,7 +113,7 @@ private extension InstanceURLService {
|
||||||
for component in allHostComponents.reversed() {
|
for component in allHostComponents.reversed() {
|
||||||
hostComponents.insert(component, at: 0)
|
hostComponents.insert(component, at: 0)
|
||||||
|
|
||||||
if filter.contains(hostComponents.joined(separator: ".")) {
|
if Self.filter.contains(hostComponents.joined(separator: ".")) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,66 +34,4 @@ final class InstanceURLServiceTests: XCTestCase {
|
||||||
return
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,12 +50,6 @@ final class AddIdentityViewController: UIViewController {
|
||||||
setupViewModelBindings()
|
setupViewModelBindings()
|
||||||
initialDisplay()
|
initialDisplay()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewWillAppear(_ animated: Bool) {
|
|
||||||
super.viewWillAppear(true)
|
|
||||||
|
|
||||||
viewModel.refreshFilter()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private extension AddIdentityViewController {
|
private extension AddIdentityViewController {
|
||||||
|
|
|
@ -74,12 +74,6 @@ public extension AddIdentityViewModel {
|
||||||
addIdentity(kind: .browsing)
|
addIdentity(kind: .browsing)
|
||||||
}
|
}
|
||||||
|
|
||||||
func refreshFilter() {
|
|
||||||
instanceURLService.updateFilter()
|
|
||||||
.sink { _ in } receiveValue: { _ in }
|
|
||||||
.store(in: &cancellables)
|
|
||||||
}
|
|
||||||
|
|
||||||
func registrationViewModel(instance: Instance, url: URL) -> RegistrationViewModel {
|
func registrationViewModel(instance: Instance, url: URL) -> RegistrationViewModel {
|
||||||
RegistrationViewModel(instance: instance, url: url, allIdentitiesService: allIdentitiesService)
|
RegistrationViewModel(instance: instance, url: url, allIdentitiesService: allIdentitiesService)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue