Set of fixes to enable basic media tier attachment restore
This commit is contained in:
parent
57602e6d8c
commit
3e3ce9d983
@ -1428,6 +1428,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
ExperienceUpgradeFinder.markAllCompleteForNewUser(transaction: transaction.unwrapGrdbWrite)
|
||||
}
|
||||
}
|
||||
DependenciesBridge.shared.attachmentDownloadManager.beginDownloadingIfNecessary()
|
||||
}
|
||||
|
||||
Self.updateApplicationShortcutItems(isRegistered: isRegistered)
|
||||
|
||||
@ -408,6 +408,7 @@ public class CVAttachmentProgressView: ManualLayoutView {
|
||||
let wasNotCreatedLocally = outgoingMessage.wasNotCreatedLocally
|
||||
guard
|
||||
!attachmentStream.attachmentStream.isUploadedToTransitTier,
|
||||
!attachmentStream.attachmentStream.hasMediaTierInfo,
|
||||
!wasNotCreatedLocally,
|
||||
!hasSendFailed
|
||||
else {
|
||||
|
||||
@ -600,12 +600,15 @@ public class MessageBackupManagerImpl: MessageBackupManager {
|
||||
let shouldDownloadAllFullsize = backupAttachmentDownloadStore.getShouldStoreAllMediaLocally(tx: tx)
|
||||
try backupAttachmentDownloadStore.dequeueAndClearTable(tx: tx) { backupDownload in
|
||||
// Every backup attachment gets enqueued for thumbnail download at lower priority.
|
||||
/*
|
||||
TODO: Re-enable thumbnail downloading once AttachmentDownloadManager understands thumbnail types
|
||||
attachmentDownloadManager.enqueueDownloadOfAttachment(
|
||||
id: backupDownload.attachmentRowId,
|
||||
priority: .backupRestoreLow,
|
||||
source: .mediaTierThumbnail,
|
||||
tx: tx
|
||||
)
|
||||
*/
|
||||
// If its recent media, also download fullsize at higher priority.
|
||||
// Or if "optimize media" is off, download fullsize everything
|
||||
// regardless of date.
|
||||
|
||||
@ -79,6 +79,8 @@ extension AttachmentStream: TSResource {
|
||||
|
||||
public var isUploadedToTransitTier: Bool { attachment.isUploadedToTransitTier }
|
||||
|
||||
public var hasMediaTierInfo: Bool { attachment.hasMediaTierInfo }
|
||||
|
||||
public var mimeType: String { attachment.mimeType }
|
||||
|
||||
public var concreteType: ConcreteTSResource { attachment.concreteType }
|
||||
|
||||
@ -72,6 +72,10 @@ extension TSAttachment: TSResource {
|
||||
}
|
||||
}
|
||||
|
||||
public var hasMediaTierInfo: Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
public var mimeType: String {
|
||||
return contentType
|
||||
}
|
||||
|
||||
@ -47,6 +47,8 @@ public protocol TSResource {
|
||||
|
||||
var isUploadedToTransitTier: Bool { get }
|
||||
|
||||
var hasMediaTierInfo: Bool { get }
|
||||
|
||||
// MARK: - Converters
|
||||
|
||||
var concreteType: ConcreteTSResource { get }
|
||||
|
||||
@ -223,6 +223,10 @@ public class Attachment {
|
||||
return transitTierInfo != nil
|
||||
}
|
||||
|
||||
public var hasMediaTierInfo: Bool {
|
||||
return mediaTierInfo != nil
|
||||
}
|
||||
|
||||
func asStream() -> AttachmentStream? {
|
||||
return AttachmentStream(attachment: self)
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import Foundation
|
||||
|
||||
public class AttachmentDownloadManagerImpl: AttachmentDownloadManager {
|
||||
|
||||
private let appReadiness: Shims.AppReadiness
|
||||
private let attachmentDownloadStore: AttachmentDownloadStore
|
||||
private let attachmentStore: AttachmentStore
|
||||
private let attachmentUpdater: AttachmentUpdater
|
||||
@ -16,6 +17,7 @@ public class AttachmentDownloadManagerImpl: AttachmentDownloadManager {
|
||||
private let downloadabilityChecker: DownloadabilityChecker
|
||||
private let progressStates: ProgressStates
|
||||
private let queueLoader: PersistedQueueLoader
|
||||
private let tsAccountManager: TSAccountManager
|
||||
|
||||
public init(
|
||||
appReadiness: Shims.AppReadiness,
|
||||
@ -40,6 +42,7 @@ public class AttachmentDownloadManagerImpl: AttachmentDownloadManager {
|
||||
) {
|
||||
self.attachmentDownloadStore = attachmentDownloadStore
|
||||
self.attachmentStore = attachmentStore
|
||||
self.appReadiness = appReadiness
|
||||
self.db = db
|
||||
self.decrypter = Decrypter(
|
||||
attachmentValidator: attachmentValidator,
|
||||
@ -82,10 +85,27 @@ public class AttachmentDownloadManagerImpl: AttachmentDownloadManager {
|
||||
stickerManager: stickerManager,
|
||||
tsAccountManager: tsAccountManager
|
||||
)
|
||||
self.tsAccountManager = tsAccountManager
|
||||
|
||||
appReadiness.runNowOrWhenMainAppDidBecomeReadyAsync { [weak self] in
|
||||
self?.beginDownloadingIfNecessary()
|
||||
}
|
||||
|
||||
NotificationCenter.default.addObserver(
|
||||
self,
|
||||
selector: #selector(registrationStateDidChange),
|
||||
name: .registrationStateDidChange,
|
||||
object: nil
|
||||
)
|
||||
}
|
||||
|
||||
@objc
|
||||
private func registrationStateDidChange() {
|
||||
AssertIsOnMainThread()
|
||||
guard tsAccountManager.registrationStateWithMaybeSneakyTransaction.isRegistered else { return }
|
||||
appReadiness.runNowOrWhenMainAppDidBecomeReadyAsync { [weak self] in
|
||||
self?.beginDownloadingIfNecessary()
|
||||
}
|
||||
}
|
||||
|
||||
public func downloadBackup(metadata: BackupReadCredential) -> Promise<URL> {
|
||||
@ -214,6 +234,10 @@ public class AttachmentDownloadManagerImpl: AttachmentDownloadManager {
|
||||
guard CurrentAppContext().isMainApp else {
|
||||
return
|
||||
}
|
||||
guard tsAccountManager.registrationStateWithMaybeSneakyTransaction.isRegistered else {
|
||||
return
|
||||
}
|
||||
|
||||
Task { [weak self] in
|
||||
try await self?.queueLoader.loadFromQueueIfAble()
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user