diff --git a/submodules/AccountContext/Sources/FetchMediaUtils.swift b/submodules/AccountContext/Sources/FetchMediaUtils.swift index 29bf1e3d89..0ce7cc87ea 100644 --- a/submodules/AccountContext/Sources/FetchMediaUtils.swift +++ b/submodules/AccountContext/Sources/FetchMediaUtils.swift @@ -57,7 +57,7 @@ public func messageMediaImageInteractiveFetched(fetchManager: FetchManager, mess if let range = range { ranges = RangeSet(range.lowerBound ..< range.upperBound) } else { - ranges = RangeSet(0 ..< Int64.max) + ranges = RangeSet(0 ..< Int64(Int32.max)) } return fetchManager.interactivelyFetched(category: .image, location: .chat(messageId.peerId), locationKey: .messageId(messageId), mediaReference: mediaReference, resourceReference: mediaReference.resourceReference(resource), ranges: ranges, statsCategory: .image, elevatedPriority: false, userInitiated: userInitiated, priority: priority, storeToDownloadsPeerType: storeToDownloadsPeerType) } diff --git a/submodules/FetchManagerImpl/Sources/FetchManagerImpl.swift b/submodules/FetchManagerImpl/Sources/FetchManagerImpl.swift index c998542496..a257e4a7fb 100644 --- a/submodules/FetchManagerImpl/Sources/FetchManagerImpl.swift +++ b/submodules/FetchManagerImpl/Sources/FetchManagerImpl.swift @@ -226,7 +226,7 @@ private final class FetchManagerCategoryContext { let storeManager = self.storeManager let parsedRanges: [(Range, MediaBoxFetchPriority)]? - if ranges == RangeSet(0 ..< Int64.max) { + if ranges == RangeSet(0 ..< Int64.max), !"".isEmpty { parsedRanges = nil } else { var resultRanges: [(Range, MediaBoxFetchPriority)] = [] @@ -325,7 +325,7 @@ private final class FetchManagerCategoryContext { isVideoPreload = true } - if count == 1 && isCompleteRange { + if count == 1 && isCompleteRange && !"".isEmpty { parsedRanges = nil } else { var resultRanges: [(Range, MediaBoxFetchPriority)] = [] diff --git a/submodules/Postbox/Sources/MediaBox.swift b/submodules/Postbox/Sources/MediaBox.swift index 61335eaf68..633603c788 100644 --- a/submodules/Postbox/Sources/MediaBox.swift +++ b/submodules/Postbox/Sources/MediaBox.swift @@ -574,6 +574,12 @@ public final class MediaBox { let disposable = MetaDisposable() self.dataQueue.async { + let paths = self.storePathsForId(resource.id) + if let _ = fileSize(paths.complete) { + subscriber.putCompletion() + return + } + guard let (fileContext, releaseContext) = self.fileContext(for: resource.id) else { subscriber.putCompletion() return diff --git a/submodules/Postbox/Sources/MediaBoxFile.swift b/submodules/Postbox/Sources/MediaBoxFile.swift index 3cf588079b..2486bf6ac5 100644 --- a/submodules/Postbox/Sources/MediaBoxFile.swift +++ b/submodules/Postbox/Sources/MediaBoxFile.swift @@ -1253,6 +1253,7 @@ final class MediaBoxFileContext { func fetched(range: Range, priority: MediaBoxFetchPriority, fetch: @escaping (Signal<[(Range, MediaBoxFetchPriority)], NoError>) -> Signal, error: @escaping (MediaResourceDataFetchError) -> Void, completed: @escaping () -> Void) -> Disposable { switch self.content { case .complete: + completed() return EmptyDisposable case let .partial(file): return file.fetched(range: range, priority: priority, fetch: fetch, error: error, completed: completed) diff --git a/submodules/TelegramCore/Sources/Network/MultipartFetch.swift b/submodules/TelegramCore/Sources/Network/MultipartFetch.swift index 1eb94cff1f..7c406cd4b1 100644 --- a/submodules/TelegramCore/Sources/Network/MultipartFetch.swift +++ b/submodules/TelegramCore/Sources/Network/MultipartFetch.swift @@ -715,6 +715,7 @@ private final class MultipartFetchManager { } let part = self.source.request(offset: downloadRange.lowerBound, limit: downloadRange.upperBound - downloadRange.lowerBound, tag: self.parameters?.tag, resource: self.resource, resourceReference: self.resourceReference, fileReference: self.fileReference, continueInBackground: self.continueInBackground) + //|> delay(5.0, queue: self.queue) |> deliverOn(self.queue) let partDisposable = MetaDisposable() self.fetchingParts[downloadRange.lowerBound] = (Int64(downloadRange.count), partDisposable) diff --git a/submodules/TelegramUI/Sources/PrefetchManager.swift b/submodules/TelegramUI/Sources/PrefetchManager.swift index 3ec707682b..a3cc9cc687 100644 --- a/submodules/TelegramUI/Sources/PrefetchManager.swift +++ b/submodules/TelegramUI/Sources/PrefetchManager.swift @@ -104,6 +104,11 @@ private final class PrefetchManagerInnerImpl { } private func updateOrderedPreloadMedia(_ items: [PrefetchMediaItem], automaticDownloadSettings: MediaAutoDownloadSettings, networkType: MediaAutoDownloadNetworkType) { + #if DEBUG + if "".isEmpty { + return + } + #endif var validIds = Set() var order: Int32 = 0 for mediaItem in items {