Always request folder updates after restart

This commit is contained in:
Ali 2023-03-30 16:50:32 +04:00
parent 0912b07b8f
commit 3076a576dd

View File

@ -448,23 +448,36 @@ public final class ChatFolderUpdates: Equatable {
} }
} }
private struct FirstTimeFolderUpdatesKey: Hashable {
var accountId: AccountRecordId
var folderId: Int32
}
private var firstTimeFolderUpdates = Set<FirstTimeFolderUpdatesKey>()
func _internal_pollChatFolderUpdatesOnce(account: Account, folderId: Int32) -> Signal<Never, NoError> { func _internal_pollChatFolderUpdatesOnce(account: Account, folderId: Int32) -> Signal<Never, NoError> {
return account.postbox.transaction { transaction -> ChatListFiltersState in return account.postbox.transaction { transaction -> ChatListFiltersState in
return _internal_currentChatListFiltersState(transaction: transaction) return _internal_currentChatListFiltersState(transaction: transaction)
} }
|> mapToSignal { state -> Signal<Never, NoError> in |> mapToSignal { state -> Signal<Never, NoError> in
let timestamp = Int32(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970) let timestamp = Int32(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970)
if let current = state.updates.first(where: { $0.folderId == folderId }) { let key = FirstTimeFolderUpdatesKey(accountId: account.id, folderId: folderId)
let updateInterval: Int32
#if DEBUG if firstTimeFolderUpdates.contains(key) {
updateInterval = 5 if let current = state.updates.first(where: { $0.folderId == folderId }) {
#else let updateInterval: Int32
updateInterval = 60 * 60 #if DEBUG
#endif updateInterval = 5
#else
if current.timestamp + updateInterval >= timestamp { updateInterval = 60 * 60
return .complete() #endif
if current.timestamp + updateInterval >= timestamp {
return .complete()
}
} }
} else {
firstTimeFolderUpdates.insert(key)
} }
return account.network.request(Api.functions.communities.getCommunityUpdates(community: .inputCommunityDialogFilter(filterId: folderId))) return account.network.request(Api.functions.communities.getCommunityUpdates(community: .inputCommunityDialogFilter(filterId: folderId)))