diff --git a/submodules/TelegramCore/TelegramCore/AddressNames.swift b/submodules/TelegramCore/TelegramCore/AddressNames.swift index 62c808f82d..94fbdbcd16 100644 --- a/submodules/TelegramCore/TelegramCore/AddressNames.swift +++ b/submodules/TelegramCore/TelegramCore/AddressNames.swift @@ -32,6 +32,7 @@ public enum AddressNameAvailability: Equatable { public enum AddressNameDomain { case account case peer(PeerId) + case theme(TelegramTheme) } public func checkAddressNameFormat(_ value: String, canEmpty: Bool = false) -> AddressNameFormatError? { @@ -106,6 +107,20 @@ public func addressNameAvailability(account: Account, domain: AddressNameDomain, } else { return .single(.invalid) } + case .theme: + return account.network.request(Api.functions.account.createTheme(slug: name, title: "", document: .inputDocumentEmpty)) + |> map { _ -> AddressNameAvailability in + return .available + } + |> `catch` { error -> Signal in + if error.errorDescription == "THEME_SLUG_OCCUPIED" { + return .single(.taken) + } else if error.errorDescription == "THEME_SLUG_INVALID" { + return .single(.invalid) + } else { + return .single(.available) + } + } } } |> switchToLatest } @@ -154,6 +169,15 @@ public func updateAddressName(account: Account, domain: AddressNameDomain, name: } else { return .fail(.generic) } + case let .theme(theme): + let flags: Int32 = 1 << 0 + return account.network.request(Api.functions.account.updateTheme(flags: flags, format: telegramThemeFormat, theme: .inputTheme(id: theme.id, accessHash: theme.accessHash), slug: nil, title: nil, document: nil)) + |> mapError { _ -> UpdateAddressNameError in + return .generic + } + |> map { _ in + return Void() + } } } |> mapError { _ -> UpdateAddressNameError in return .generic } |> switchToLatest } diff --git a/submodules/TelegramCore/TelegramCore/Themes.swift b/submodules/TelegramCore/TelegramCore/Themes.swift index 34a76d6f28..8aead71fd5 100644 --- a/submodules/TelegramCore/TelegramCore/Themes.swift +++ b/submodules/TelegramCore/TelegramCore/Themes.swift @@ -26,16 +26,16 @@ final class CachedThemesConfiguration: PostboxCoding { } #if os(macOS) -private let themeFormat = "macos" -private let themeFileExtension = "palette" +let telegramThemeFormat = "macos" +let telegramThemeFileExtension = "palette" #else -private let themeFormat = "ios" -private let themeFileExtension = "tgios-theme" +let telegramThemeFormat = "ios" +let telegramThemeFileExtension = "tgios-theme" #endif 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: themeFormat, hash: hash ?? 0)) + network.request(Api.functions.account.getThemes(format: telegramThemeFormat, hash: hash ?? 0)) |> retryRequest |> mapToSignal { result -> Signal<([TelegramTheme], Int32), NoError> in switch result { @@ -109,7 +109,7 @@ public enum GetThemeError { } public func getTheme(account: Account, slug: String) -> Signal { - return account.network.request(Api.functions.account.getTheme(format: themeFormat, theme: .inputThemeSlug(slug: slug), documentId: 0)) + return account.network.request(Api.functions.account.getTheme(format: telegramThemeFormat, theme: .inputThemeSlug(slug: slug), documentId: 0)) |> mapError { error -> GetThemeError in if error.errorDescription == "THEME_FORMAT_INVALID" { return .unsupported @@ -137,7 +137,7 @@ private func checkThemeUpdated(network: Network, theme: TelegramTheme) -> Signal guard let file = theme.file, let fileId = file.id?.id else { return .fail(.generic) } - return network.request(Api.functions.account.getTheme(format: themeFormat, theme: .inputTheme(id: theme.id, accessHash: theme.accessHash), documentId: fileId)) + return network.request(Api.functions.account.getTheme(format: telegramThemeFormat, theme: .inputTheme(id: theme.id, accessHash: theme.accessHash), documentId: fileId)) |> mapError { _ -> GetThemeError in return .generic } |> map { theme -> ThemeUpdatedResult in if let theme = TelegramTheme(apiTheme: theme) { @@ -192,7 +192,7 @@ private func installTheme(account: Account, theme: TelegramTheme?, autoNight: Bo inputTheme = nil } - return account.network.request(Api.functions.account.installTheme(flags: flags, format: themeFormat, theme: inputTheme)) + return account.network.request(Api.functions.account.installTheme(flags: flags, format: telegramThemeFormat, theme: inputTheme)) |> `catch` { _ -> Signal in return .complete() } @@ -240,8 +240,8 @@ private func uploadedThemeThumbnail(postbox: Postbox, network: Network, data: Da } private func uploadTheme(account: Account, resource: MediaResource, thumbnailData: Data? = nil) -> Signal { - let fileName = "theme.\(themeFileExtension)" - let mimeType = "application/x-tgtheme-\(themeFormat)" + let fileName = "theme.\(telegramThemeFileExtension)" + let mimeType = "application/x-tgtheme-\(telegramThemeFormat)" let uploadedThumbnail: Signal if let thumbnailData = thumbnailData { @@ -387,7 +387,7 @@ public func updateTheme(account: Account, accountManager: AccountManager, theme: inputDocument = nil } - return account.network.request(Api.functions.account.updateTheme(flags: flags, format: themeFormat, theme: .inputTheme(id: theme.id, accessHash: theme.accessHash), slug: slug, title: title, document: inputDocument)) + return account.network.request(Api.functions.account.updateTheme(flags: flags, format: telegramThemeFormat, theme: .inputTheme(id: theme.id, accessHash: theme.accessHash), slug: slug, title: title, document: inputDocument)) |> mapError { error in if error.errorDescription == "THEME_SLUG_INVALID" { return .slugInvalid