Theme file reference invalidation

This commit is contained in:
Ilya Laktyushin
2019-12-25 13:16:21 +03:00
parent 2f1e573cbf
commit f13301f7d0
6 changed files with 100 additions and 24 deletions

View File

@@ -13,7 +13,7 @@ let telegramThemeFormat = "ios"
let telegramThemeFileExtension = "tgios-theme"
#endif
public func telegramThemes(postbox: Postbox, network: Network, accountManager: AccountManager, forceUpdate: Bool = false) -> Signal<[TelegramTheme], NoError> {
public func telegramThemes(postbox: Postbox, network: Network, accountManager: AccountManager?, forceUpdate: Bool = false) -> Signal<[TelegramTheme], NoError> {
let fetch: ([TelegramTheme]?, Int32?) -> Signal<[TelegramTheme], NoError> = { current, hash in
network.request(Api.functions.account.getThemes(format: telegramThemeFormat, hash: hash ?? 0))
|> retryRequest
@@ -31,18 +31,20 @@ public func telegramThemes(postbox: Postbox, network: Network, accountManager: A
}
}
|> mapToSignal { items, hash -> Signal<[TelegramTheme], NoError> in
let _ = accountManager.transaction { transaction in
transaction.updateSharedData(SharedDataKeys.themeSettings, { current in
var updated = current as? ThemeSettings ?? ThemeSettings(currentTheme: nil)
for theme in items {
if theme.id == updated.currentTheme?.id {
updated = ThemeSettings(currentTheme: theme)
break
if let accountManager = accountManager {
let _ = accountManager.transaction { transaction in
transaction.updateSharedData(SharedDataKeys.themeSettings, { current in
var updated = current as? ThemeSettings ?? ThemeSettings(currentTheme: nil)
for theme in items {
if theme.id == updated.currentTheme?.id {
updated = ThemeSettings(currentTheme: theme)
break
}
}
}
return updated
})
}.start()
return updated
})
}.start()
}
return postbox.transaction { transaction -> [TelegramTheme] in
var entries: [OrderedItemListEntry] = []