mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
[WIP] Modern cache
This commit is contained in:
@@ -238,7 +238,23 @@ private final class FetchManagerCategoryContext {
|
||||
activeContext.disposable?.dispose()
|
||||
let postbox = self.postbox
|
||||
Logger.shared.log("FetchManager", "Begin fetching \(entry.resourceReference.resource.id.stringRepresentation) ranges: \(String(describing: parsedRanges))")
|
||||
activeContext.disposable = (fetchedMediaResource(mediaBox: postbox.mediaBox, reference: entry.resourceReference, ranges: parsedRanges, statsCategory: entry.statsCategory, reportResultStatus: true, continueInBackground: entry.userInitiated)
|
||||
|
||||
var userLocation: MediaResourceUserLocation = .other
|
||||
switch entry.id.location {
|
||||
case let .chat(peerId):
|
||||
userLocation = .peer(peerId)
|
||||
}
|
||||
var userContentType: MediaResourceUserContentType = .other
|
||||
switch entry.statsCategory {
|
||||
case .image:
|
||||
userContentType = .image
|
||||
case .video:
|
||||
userContentType = .video
|
||||
default:
|
||||
userContentType = .other
|
||||
}
|
||||
|
||||
activeContext.disposable = (fetchedMediaResource(mediaBox: postbox.mediaBox, userLocation: userLocation, userContentType: userContentType, reference: entry.resourceReference, ranges: parsedRanges, statsCategory: entry.statsCategory, reportResultStatus: true, continueInBackground: entry.userInitiated)
|
||||
|> mapToSignal { type -> Signal<FetchResourceSourceType, FetchResourceError> in
|
||||
if filterDownloadStatsEntry(entry: entry), case let .message(message, _) = entry.mediaReference, let messageId = message.id, case .remote = type {
|
||||
let _ = addRecentDownloadItem(postbox: postbox, item: RecentDownloadItem(messageId: messageId, resourceId: entry.resourceReference.resource.id.stringRepresentation, timestamp: Int32(Date().timeIntervalSince1970), isSeen: false)).start()
|
||||
@@ -349,11 +365,26 @@ private final class FetchManagerCategoryContext {
|
||||
if restart {
|
||||
activeContext.ranges = ranges
|
||||
|
||||
var userLocation: MediaResourceUserLocation = .other
|
||||
switch entry.id.location {
|
||||
case let .chat(peerId):
|
||||
userLocation = .peer(peerId)
|
||||
}
|
||||
var userContentType: MediaResourceUserContentType = .other
|
||||
switch entry.statsCategory {
|
||||
case .image:
|
||||
userContentType = .image
|
||||
case .video:
|
||||
userContentType = .video
|
||||
default:
|
||||
userContentType = .other
|
||||
}
|
||||
|
||||
let entryCompleted = self.entryCompleted
|
||||
let storeManager = self.storeManager
|
||||
activeContext.disposable?.dispose()
|
||||
if isVideoPreload {
|
||||
activeContext.disposable = (preloadVideoResource(postbox: self.postbox, resourceReference: entry.resourceReference, duration: 4.0)
|
||||
activeContext.disposable = (preloadVideoResource(postbox: self.postbox, userLocation: userLocation, userContentType: userContentType, resourceReference: entry.resourceReference, duration: 4.0)
|
||||
|> castError(FetchResourceError.self)
|
||||
|> map { _ -> FetchResourceSourceType in }
|
||||
|> then(.single(.local))
|
||||
@@ -364,7 +395,23 @@ private final class FetchManagerCategoryContext {
|
||||
} else {
|
||||
let postbox = self.postbox
|
||||
Logger.shared.log("FetchManager", "Begin fetching \(entry.resourceReference.resource.id.stringRepresentation) ranges: \(String(describing: parsedRanges))")
|
||||
activeContext.disposable = (fetchedMediaResource(mediaBox: postbox.mediaBox, reference: entry.resourceReference, ranges: parsedRanges, statsCategory: entry.statsCategory, reportResultStatus: true, continueInBackground: entry.userInitiated)
|
||||
|
||||
var userLocation: MediaResourceUserLocation = .other
|
||||
switch entry.id.location {
|
||||
case let .chat(peerId):
|
||||
userLocation = .peer(peerId)
|
||||
}
|
||||
var userContentType: MediaResourceUserContentType = .other
|
||||
switch entry.statsCategory {
|
||||
case .image:
|
||||
userContentType = .image
|
||||
case .video:
|
||||
userContentType = .video
|
||||
default:
|
||||
userContentType = .other
|
||||
}
|
||||
|
||||
activeContext.disposable = (fetchedMediaResource(mediaBox: postbox.mediaBox, userLocation: userLocation, userContentType: userContentType, reference: entry.resourceReference, ranges: parsedRanges, statsCategory: entry.statsCategory, reportResultStatus: true, continueInBackground: entry.userInitiated)
|
||||
|> mapToSignal { type -> Signal<FetchResourceSourceType, FetchResourceError> in
|
||||
if filterDownloadStatsEntry(entry: entry), case let .message(message, _) = entry.mediaReference, let messageId = message.id, case .remote = type {
|
||||
let _ = addRecentDownloadItem(postbox: postbox, item: RecentDownloadItem(messageId: messageId, resourceId: entry.resourceReference.resource.id.stringRepresentation, timestamp: Int32(Date().timeIntervalSince1970), isSeen: false)).start()
|
||||
|
||||
Reference in New Issue
Block a user