Merge branch 'bug-fixes-1.11.25' into voice-calls-2

This commit is contained in:
ryanzhao 2022-04-05 11:36:56 +10:00
commit 7d3df3a016
10 changed files with 19 additions and 28 deletions

View File

@ -379,7 +379,7 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat
}
collectionView.allowsMultipleSelection = delegate.isInBatchSelectMode
collectionView.reloadData()
reloadDataAndRestoreSelection()
}
func clearCollectionViewSelection() {
@ -551,12 +551,7 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat
let assetItem = photoCollectionContents.assetItem(at: indexPath.item, photoMediaSize: photoMediaSize)
cell.configure(item: assetItem)
let isSelected = delegate.imagePicker(self, isAssetSelected: assetItem.asset)
if isSelected {
cell.isSelected = isSelected
} else {
cell.isSelected = isSelected
}
cell.isSelected = delegate.imagePicker(self, isAssetSelected: assetItem.asset)
return cell
}

View File

@ -3,7 +3,6 @@ import SessionSnodeKit
@objc(LKBackgroundPoller)
public final class BackgroundPoller : NSObject {
private static var closedGroupPoller: ClosedGroupPoller!
private static var promises: [Promise<Void>] = []
private override init() { }

View File

@ -61,7 +61,7 @@ public final class AttachmentDownloadJob : NSObject, Job, NSCoding { // NSObject
// MARK: Running
public func execute() {
if let id = id {
JobQueue.currentlyExecutingJobs.insert(id)
JobQueue.currentlyExecutingJobs.mutate{ $0.insert(id) }
}
guard !isDeferred else { return }
if TSAttachment.fetch(uniqueId: attachmentID) is TSAttachmentStream {

View File

@ -61,7 +61,7 @@ public final class AttachmentUploadJob : NSObject, Job, NSCoding { // NSObject/N
// MARK: Running
public func execute() {
if let id = id {
JobQueue.currentlyExecutingJobs.insert(id)
JobQueue.currentlyExecutingJobs.mutate{ $0.insert(id) }
}
guard let stream = TSAttachment.fetch(uniqueId: attachmentID) as? TSAttachmentStream else {
return handleFailure(error: Error.noAttachment)

View File

@ -5,9 +5,7 @@ public final class JobQueue : NSObject, JobDelegate {
private static var jobIDs: [UInt64:UInt64] = [:]
internal static var currentlyExecutingJobs: Set<String> = []
private let internalQueue: DispatchQueue = DispatchQueue(label:"executingJobQueue")
internal static var currentlyExecutingJobs: Atomic<Set<String>> = Atomic([])
@objc public static let shared = JobQueue()
@ -38,7 +36,7 @@ public final class JobQueue : NSObject, JobDelegate {
allJobTypes.forEach { type in
let allPendingJobs = SNMessagingKitConfiguration.shared.storage.getAllPendingJobs(of: type)
allPendingJobs.sorted(by: { $0.id! < $1.id! }).forEach { job in // Retry the oldest jobs first
guard !JobQueue.currentlyExecutingJobs.contains(job.id!) else {
guard !JobQueue.currentlyExecutingJobs.wrappedValue.contains(job.id!) else {
return SNLog("Not resuming already executing job.")
}
SNLog("Resuming pending job of type: \(type).")
@ -95,7 +93,7 @@ public final class JobQueue : NSObject, JobDelegate {
}
private func removeExecutingJob(_ jobID: String) {
let _ = internalQueue.sync { JobQueue.currentlyExecutingJobs.remove(jobID) }
JobQueue.currentlyExecutingJobs.mutate { $0.remove(jobID) }
}
private func getRetryInterval(for job: Job) -> TimeInterval {

View File

@ -59,7 +59,7 @@ public final class MessageReceiveJob : NSObject, Job, NSCoding { // NSObject/NSC
public func execute() -> Promise<Void> {
if let id = id { // Can be nil (e.g. when background polling)
JobQueue.currentlyExecutingJobs.insert(id)
JobQueue.currentlyExecutingJobs.mutate { $0.insert(id) }
}
let (promise, seal) = Promise<Void>.pending()
SNMessagingKitConfiguration.shared.storage.write(with: { transaction in // Intentionally capture self

View File

@ -71,7 +71,7 @@ public final class MessageSendJob : NSObject, Job, NSCoding { // NSObject/NSCodi
// MARK: Running
public func execute() {
if let id = id {
JobQueue.currentlyExecutingJobs.insert(id)
JobQueue.currentlyExecutingJobs.mutate{ $0.insert(id) }
}
let storage = SNMessagingKitConfiguration.shared.storage
if let message = message as? VisibleMessage {

View File

@ -39,7 +39,7 @@ public final class NotifyPNServerJob : NSObject, Job, NSCoding { // NSObject/NSC
public func execute() -> Promise<Void> {
if let id = id {
JobQueue.currentlyExecutingJobs.insert(id)
JobQueue.currentlyExecutingJobs.mutate{ $0.insert(id) }
}
let server = PushNotificationAPI.server
let parameters = [ "data" : message.data.description, "send_to" : message.recipient ]

View File

@ -3,7 +3,7 @@ import SessionSnodeKit
@objc(SNOpenGroupAPIV2)
public final class OpenGroupAPIV2 : NSObject {
private static var authTokenPromises: [String:Promise<String>] = [:]
private static var authTokenPromises: Atomic<[String:Promise<String>]> = Atomic([:])
private static var hasPerformedInitialPoll: [String:Bool] = [:]
private static var hasUpdatedLastOpenDate = false
public static let workQueue = DispatchQueue(label: "OpenGroupAPIV2.workQueue", qos: .userInitiated) // It's important that this is a serial queue
@ -210,7 +210,7 @@ public final class OpenGroupAPIV2 : NSObject {
if let authToken = storage.getAuthToken(for: room, on: server) {
return Promise.value(authToken)
} else {
if let authTokenPromise = authTokenPromises["\(server).\(room)"] {
if let authTokenPromise = authTokenPromises.wrappedValue["\(server).\(room)"] {
return authTokenPromise
} else {
let promise = requestNewAuthToken(for: room, on: server)
@ -225,11 +225,11 @@ public final class OpenGroupAPIV2 : NSObject {
return promise
}
promise.done(on: OpenGroupAPIV2.workQueue) { _ in
authTokenPromises["\(server).\(room)"] = nil
authTokenPromises.mutate{ $0["\(server).\(room)"] = nil }
}.catch(on: OpenGroupAPIV2.workQueue) { _ in
authTokenPromises["\(server).\(room)"] = nil
authTokenPromises.mutate{ $0["\(server).\(room)"] = nil }
}
authTokenPromises["\(server).\(room)"] = promise
authTokenPromises.mutate{ $0["\(server).\(room)"] = promise }
return promise
}
}

View File

@ -3,9 +3,8 @@ import PromiseKit
@objc(LKClosedGroupPoller)
public final class ClosedGroupPoller : NSObject {
private var isPolling: [String:Bool] = [:]
private var isPolling: Atomic<[String:Bool]> = Atomic([:])
private var timers: [String:Timer] = [:]
private let internalQueue: DispatchQueue = DispatchQueue(label:"isPollingQueue")
// MARK: Settings
private static let minPollInterval: Double = 2
@ -44,7 +43,7 @@ public final class ClosedGroupPoller : NSObject {
// Might be a race condition that the setUpPolling finishes too soon,
// and the timer is not created, if we mark the group as is polling
// after setUpPolling. So the poller may not work, thus misses messages.
internalQueue.sync{ isPolling[groupPublicKey] = true }
isPolling.mutate{ $0[groupPublicKey] = true }
setUpPolling(for: groupPublicKey)
}
@ -55,7 +54,7 @@ public final class ClosedGroupPoller : NSObject {
}
public func stopPolling(for groupPublicKey: String) {
internalQueue.sync{ isPolling[groupPublicKey] = false }
isPolling.mutate{ $0[groupPublicKey] = false }
timers[groupPublicKey]?.invalidate()
}
@ -139,6 +138,6 @@ public final class ClosedGroupPoller : NSObject {
// MARK: Convenience
private func isPolling(for groupPublicKey: String) -> Bool {
return internalQueue.sync{ isPolling[groupPublicKey] ?? false }
return isPolling.wrappedValue[groupPublicKey] ?? false
}
}