session-ios/SessionSnodeKit/GetSnodePoolJob.swift
Morgan Pretty 20dc74bc96 Added paging to the Home/MessageRequests screens and fix a bunch of bugs
Added a cache to the Identicon to prevent unneeded image generation
Replaced some 'withTint' calls to use the standard 'withRenderingMode' instead
Fixed a bug where the background would remain when swiping to reply
Fixed a crash which could occur with String-based settings
Fixed an issue where all messages in a thread wouldn't get marked as read when opening the thread (ie. existing behaviour)
Fixed a bug where going to the all media screen from a specific
Fixed a bug where the 'areCallsEnabled' preference wasn't getting migrated
Fixed a bug where you couldn't join any of the default open groups
Fixed a bug where it was polling for the invalid placeholder default open group
Fixed a few threading issues related to PromiseKit defaulting to run on the main thread
Updated and number of processes to run on "default" priority queues intead of "userInitiated" ones (since the docs suggest those are blocking)
Optimised the PagedDatabaseObserver to do a much more efficient count query
Updated the PagedDatabaseObserver to allow for triggering content updates when data changes outside of the paged or associated tables changes
Updated the HomeVC and MessageRequestsViewController to use paged queries
Made some optimisations to prevent unneeded database changes
2022-06-24 18:29:45 +10:00

53 lines
1.8 KiB
Swift

// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
import Foundation
import GRDB
import SignalCoreKit
import SessionUtilitiesKit
public enum GetSnodePoolJob: JobExecutor {
public static let maxFailureCount: Int = -1
public static let requiresThreadId: Bool = false
public static let requiresInteractionId: Bool = false
public static func run(
_ job: Job,
queue: DispatchQueue,
success: @escaping (Job, Bool) -> (),
failure: @escaping (Job, Error?, Bool) -> (),
deferred: @escaping (Job) -> ()
) {
// If the user doesn't exist then don't do anything (when the user registers we run this
// job directly)
guard Identity.userExists() else {
deferred(job)
return
}
// If we already have cached Snodes then we still want to trigger the 'SnodeAPI.getSnodePool'
// but we want to succeed this job immediately (since it's marked as blocking), this allows us
// to block if we have no Snode pool and prevent other jobs from failing but avoids having to
// wait if we already have a potentially valid snode pool
guard !SnodeAPI.hasCachedSnodesInclusingExpired() else {
SnodeAPI.getSnodePool().retainUntilComplete()
success(job, false)
return
}
SnodeAPI.getSnodePool()
.done(on: queue) { _ in success(job, false) }
.catch(on: queue) { error in failure(job, error, false) }
.retainUntilComplete()
}
public static func run() {
GetSnodePoolJob.run(
Job(variant: .getSnodePool),
queue: DispatchQueue.global(qos: .background),
success: { _, _ in },
failure: { _, _, _ in },
deferred: { _ in }
)
}
}