mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-17 02:49:57 +00:00
66 lines
4.1 KiB
Swift
66 lines
4.1 KiB
Swift
import Foundation
|
|
#if os(macOS)
|
|
import PostboxMac
|
|
import SwiftSignalKitMac
|
|
import MtProtoKitMac
|
|
#else
|
|
import Postbox
|
|
import SwiftSignalKit
|
|
import MtProtoKitDynamic
|
|
#endif
|
|
|
|
func managedConfigurationUpdates(postbox: Postbox, network: Network) -> Signal<Void, NoError> {
|
|
let poll = Signal<Void, NoError> { subscriber in
|
|
return (network.request(Api.functions.help.getConfig()) |> retryRequest |> mapToSignal { result -> Signal<Void, NoError> in
|
|
return postbox.modify { modifier -> Void in
|
|
switch result {
|
|
case let .config(_, _, _, _, _, dcOptions, chatSizeMax, megagroupSizeMax, forwardedCountMax, _, _, _, onlineCloudTimeoutMs, notifyCloudDelayMs, notifyDefaultDelayMs, chatBigSize, pushChatPeriodMs, pushChatLimit, savedGifsLimit, editTimeLimit, revokeTimeLimit, revokePmTimeLimit, ratingEDecay, stickersRecentLimit, stickersFavedLimit, channelsReadMediaPeriod, tmpSessions, pinnedDialogsCountMax, callReceiveTimeoutMs, callRingTimeoutMs, callConnectTimeoutMs, callPacketTimeoutMs, meUrlPrefix, suggestedLangCode, langPackVersion):
|
|
var addressList: [Int: [MTDatacenterAddress]] = [:]
|
|
for option in dcOptions {
|
|
switch option {
|
|
case let .dcOption(flags, id, ipAddress, port):
|
|
let preferForMedia = (flags & (1 << 1)) != 0
|
|
if addressList[Int(id)] == nil {
|
|
addressList[Int(id)] = []
|
|
}
|
|
let restrictToTcp = (flags & (1 << 2)) != 0
|
|
let isCdn = (flags & (1 << 3)) != 0
|
|
let preferForProxy = (flags & (1 << 4)) != 0
|
|
addressList[Int(id)]!.append(MTDatacenterAddress(ip: ipAddress, port: UInt16(port), preferForMedia: preferForMedia, restrictToTcp: restrictToTcp, cdn: isCdn, preferForProxy: preferForProxy))
|
|
}
|
|
}
|
|
network.context.performBatchUpdates {
|
|
for (id, list) in addressList {
|
|
network.context.updateAddressSetForDatacenter(withId: id, addressSet: MTDatacenterAddressSet(addressList: list), forceUpdateSchemes: false)
|
|
}
|
|
}
|
|
|
|
modifier.updatePreferencesEntry(key: PreferencesKeys.suggestedLocalization, { entry in
|
|
var currentLanguageCode: String?
|
|
if let entry = entry as? SuggestedLocalizationEntry {
|
|
currentLanguageCode = entry.languageCode
|
|
}
|
|
if currentLanguageCode != suggestedLangCode {
|
|
if let suggestedLangCode = suggestedLangCode {
|
|
return SuggestedLocalizationEntry(languageCode: suggestedLangCode, isSeen: false)
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
return entry
|
|
})
|
|
|
|
updateLimitsConfiguration(modifier: modifier, configuration: LimitsConfiguration(maxGroupMemberCount: chatSizeMax, maxSupergroupMemberCount: megagroupSizeMax, maxMessageForwardBatchSize: forwardedCountMax, maxSavedGifCount: savedGifsLimit, maxRecentStickerCount: stickersRecentLimit, maxMessageEditingInterval: editTimeLimit))
|
|
|
|
let (_, version, _) = getLocalization(modifier)
|
|
if version != langPackVersion {
|
|
addSynchronizeLocalizationUpdatesOperation(modifier: modifier)
|
|
}
|
|
}
|
|
}
|
|
}).start()
|
|
}
|
|
|
|
return (poll |> then(.complete() |> delay(1.0 * 60.0 * 60.0, queue: Queue.concurrentDefaultQueue()))) |> restart
|
|
}
|