Fix fetch status after completion

This commit is contained in:
Ali 2022-01-28 19:45:34 +04:00
parent af9292e981
commit 111306430c

View File

@ -395,7 +395,7 @@ private final class FetchManagerCategoryContext {
} }
} }
func cancelEntry(_ entryId: FetchManagerLocationEntryId) { func cancelEntry(_ entryId: FetchManagerLocationEntryId, isCompleted: Bool) {
var id: FetchManagerLocationEntryId = entryId var id: FetchManagerLocationEntryId = entryId
if self.entries[id] == nil { if self.entries[id] == nil {
for (key, _) in self.entries { for (key, _) in self.entries {
@ -411,6 +411,9 @@ private final class FetchManagerCategoryContext {
if let statusContext = self.statusContexts[id] { if let statusContext = self.statusContexts[id] {
if statusContext.hasEntry { if statusContext.hasEntry {
if isCompleted {
statusContext.originalStatus = .Local
}
let previousStatus = statusContext.combinedStatus let previousStatus = statusContext.combinedStatus
statusContext.hasEntry = false statusContext.hasEntry = false
if let combinedStatus = statusContext.combinedStatus, combinedStatus != previousStatus { if let combinedStatus = statusContext.combinedStatus, combinedStatus != previousStatus {
@ -513,7 +516,7 @@ public final class FetchManagerImpl: FetchManager {
return return
} }
strongSelf.withCategoryContext(key, { context in strongSelf.withCategoryContext(key, { context in
context.cancelEntry(id) context.cancelEntry(id, isCompleted: true)
}) })
} }
}, activeEntriesUpdated: { [weak self] in }, activeEntriesUpdated: { [weak self] in
@ -619,7 +622,7 @@ public final class FetchManagerImpl: FetchManager {
public func cancelInteractiveFetches(category: FetchManagerCategory, location: FetchManagerLocation, locationKey: FetchManagerLocationKey, resource: MediaResource) { public func cancelInteractiveFetches(category: FetchManagerCategory, location: FetchManagerLocation, locationKey: FetchManagerLocationKey, resource: MediaResource) {
self.queue.async { self.queue.async {
self.withCategoryContext(category, { context in self.withCategoryContext(category, { context in
context.cancelEntry(FetchManagerLocationEntryId(location: location, resourceId: resource.id, locationKey: locationKey)) context.cancelEntry(FetchManagerLocationEntryId(location: location, resourceId: resource.id, locationKey: locationKey), isCompleted: false)
}) })
self.postbox.mediaBox.cancelInteractiveResourceFetch(resource) self.postbox.mediaBox.cancelInteractiveResourceFetch(resource)