diff --git a/submodules/ChatListUI/Sources/ChatListController.swift b/submodules/ChatListUI/Sources/ChatListController.swift index 298854e417..d4929ef3e5 100644 --- a/submodules/ChatListUI/Sources/ChatListController.swift +++ b/submodules/ChatListUI/Sources/ChatListController.swift @@ -2137,12 +2137,12 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController for (_, info) in resources.sorted(by: { $0.value.priority < $1.value.priority }) { let resource = info.resource validIds.append(resource.resource.id) - if preloadStoryResourceDisposables[resource.resource.id] == nil { + if self.preloadStoryResourceDisposables[resource.resource.id] == nil { var fetchRange: (Range, MediaBoxFetchPriority)? if let size = info.size { fetchRange = (0 ..< Int64(size), .default) } - preloadStoryResourceDisposables[resource.resource.id] = fetchedMediaResource(mediaBox: self.context.account.postbox.mediaBox, userLocation: .other, userContentType: .other, reference: resource, range: fetchRange).start() + self.preloadStoryResourceDisposables[resource.resource.id] = fetchedMediaResource(mediaBox: self.context.account.postbox.mediaBox, userLocation: .other, userContentType: .other, reference: resource, range: fetchRange).start() } } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/Stories.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/Stories.swift index b2918994db..5e32105419 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/Stories.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/Stories.swift @@ -347,16 +347,20 @@ public enum Stories { private enum CodingKeys: CodingKey { case opaqueState case hasMore + case refreshId } public let opaqueState: String + public let refreshId: UInt64 public let hasMore: Bool public init( opaqueState: String, + refreshId: UInt64, hasMore: Bool ) { self.opaqueState = opaqueState + self.refreshId = refreshId self.hasMore = hasMore } @@ -364,6 +368,7 @@ public enum Stories { let container = try decoder.container(keyedBy: CodingKeys.self) self.opaqueState = try container.decode(String.self, forKey: .opaqueState) + self.refreshId = UInt64(bitPattern: (try container.decodeIfPresent(Int64.self, forKey: .refreshId)) ?? 0) self.hasMore = try container.decode(Bool.self, forKey: .hasMore) } @@ -371,6 +376,7 @@ public enum Stories { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(self.opaqueState, forKey: .opaqueState) + try container.encode(Int64(bitPattern: self.refreshId), forKey: .refreshId) try container.encode(self.hasMore, forKey: .hasMore) } @@ -378,6 +384,9 @@ public enum Stories { if lhs.opaqueState != rhs.opaqueState { return false } + if lhs.refreshId != rhs.refreshId { + return false + } if lhs.hasMore != rhs.hasMore { return false } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/StoryListContext.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/StoryListContext.swift index 55578cae03..6ae73d4b5e 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/StoryListContext.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/StoryListContext.swift @@ -33,6 +33,7 @@ public final class StorySubscriptionsContext { private var loadedStateMark: OpaqueStateMark? private var stateDisposable: Disposable? private let loadMoreDisposable = MetaDisposable() + private let refreshTimerDisposable = MetaDisposable() init(queue: Queue, accountPeerId: PeerId, postbox: Postbox, network: Network) { self.accountPeerId = accountPeerId @@ -48,6 +49,7 @@ public final class StorySubscriptionsContext { deinit { self.stateDisposable?.dispose() self.loadMoreDisposable.dispose() + self.refreshTimerDisposable.dispose() } func loadMore() { @@ -151,7 +153,11 @@ public final class StorySubscriptionsContext { hasMore = currentState.hasMore } - transaction.setSubscriptionsStoriesState(state: CodableEntry(Stories.SubscriptionsState(opaqueState: state, hasMore: hasMore))) + transaction.setSubscriptionsStoriesState(state: CodableEntry(Stories.SubscriptionsState( + opaqueState: state, + refreshId: currentState?.refreshId ?? UInt64.random(in: 0 ... UInt64.max), + hasMore: hasMore + ))) case let .allStories(flags, state, userStories, users): var peers: [Peer] = [] var peerPresences: [PeerId: Api.User] = [:] @@ -209,7 +215,11 @@ public final class StorySubscriptionsContext { } } - transaction.replaceAllStorySubscriptions(state: CodableEntry(Stories.SubscriptionsState(opaqueState: state, hasMore: hasMore)), peerIds: peerEntries) + transaction.replaceAllStorySubscriptions(state: CodableEntry(Stories.SubscriptionsState( + opaqueState: state, + refreshId: UInt64.random(in: 0 ... UInt64.max), + hasMore: hasMore + )), peerIds: peerEntries) } } |> deliverOn(self.queue)).start(completed: { [weak self] in @@ -220,6 +230,14 @@ public final class StorySubscriptionsContext { self.isLoading = false if isRefresh { self.taskState.isRefreshScheduled = false + self.refreshTimerDisposable.set((Signal.complete() + |> suspendAwareDelay(60.0, queue: self.queue)).start(completed: { [weak self] in + guard let `self` = self else { + return + } + self.taskState.isRefreshScheduled = true + self.updateTasks() + })) } else { self.taskState.isLoadMoreScheduled = false } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift index ee4de749e3..cb321090ef 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift @@ -628,7 +628,7 @@ public extension TelegramEngine { var hasMoreToken: String? if let subscriptionsState = storiesStateView.value?.get(Stories.SubscriptionsState.self) { if subscriptionsState.hasMore { - hasMoreToken = subscriptionsState.opaqueState + hasMoreToken = subscriptionsState.opaqueState + "_\(subscriptionsState.refreshId)" } else { hasMoreToken = nil }