mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-08 08:31:13 +00:00
Cloud Themes: wallpaper by slug support
This commit is contained in:
parent
77adf1f381
commit
c05c59a1b7
@ -176,12 +176,11 @@ private struct EditThemeControllerState: Equatable {
|
|||||||
var mode: EditThemeControllerMode
|
var mode: EditThemeControllerMode
|
||||||
var title: String
|
var title: String
|
||||||
var slug: String
|
var slug: String
|
||||||
var previewTheme: PresentationTheme
|
|
||||||
var updatedTheme: PresentationTheme?
|
var updatedTheme: PresentationTheme?
|
||||||
var updating: Bool
|
var updating: Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
private func editThemeControllerEntries(presentationData: PresentationData, state: EditThemeControllerState) -> [EditThemeControllerEntry] {
|
private func editThemeControllerEntries(presentationData: PresentationData, state: EditThemeControllerState, previewTheme: PresentationTheme) -> [EditThemeControllerEntry] {
|
||||||
var entries: [EditThemeControllerEntry] = []
|
var entries: [EditThemeControllerEntry] = []
|
||||||
|
|
||||||
var isCreate = false
|
var isCreate = false
|
||||||
@ -196,7 +195,7 @@ private func editThemeControllerEntries(presentationData: PresentationData, stat
|
|||||||
}
|
}
|
||||||
|
|
||||||
entries.append(.chatPreviewHeader(presentationData.theme, presentationData.strings.EditTheme_Preview.uppercased()))
|
entries.append(.chatPreviewHeader(presentationData.theme, presentationData.strings.EditTheme_Preview.uppercased()))
|
||||||
entries.append(.chatPreview(presentationData.theme, state.previewTheme, state.previewTheme.chat.defaultWallpaper, presentationData.fontSize, presentationData.strings, presentationData.dateTimeFormat, presentationData.nameDisplayOrder))
|
entries.append(.chatPreview(presentationData.theme, previewTheme, previewTheme.chat.defaultWallpaper, presentationData.fontSize, presentationData.strings, presentationData.dateTimeFormat, presentationData.nameDisplayOrder))
|
||||||
|
|
||||||
let uploadText: String
|
let uploadText: String
|
||||||
let uploadInfo: String
|
let uploadInfo: String
|
||||||
@ -221,18 +220,26 @@ private func editThemeControllerEntries(presentationData: PresentationData, stat
|
|||||||
|
|
||||||
public func editThemeController(context: AccountContext, mode: EditThemeControllerMode, navigateToChat: ((PeerId) -> Void)? = nil) -> ViewController {
|
public func editThemeController(context: AccountContext, mode: EditThemeControllerMode, navigateToChat: ((PeerId) -> Void)? = nil) -> ViewController {
|
||||||
let initialState: EditThemeControllerState
|
let initialState: EditThemeControllerState
|
||||||
|
let previewThemePromise = Promise<PresentationTheme>()
|
||||||
switch mode {
|
switch mode {
|
||||||
case .create:
|
case .create:
|
||||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||||
initialState = EditThemeControllerState(mode: mode, title: "", slug: "", previewTheme: presentationData.theme.withUpdated(name: "", author: nil, defaultWallpaper: presentationData.chatWallpaper), updatedTheme: nil, updating: false)
|
initialState = EditThemeControllerState(mode: mode, title: "", slug: "", updatedTheme: nil, updating: false)
|
||||||
|
previewThemePromise.set(.single(presentationData.theme.withUpdated(name: "", author: nil, defaultWallpaper: presentationData.chatWallpaper)))
|
||||||
case let .edit(theme):
|
case let .edit(theme):
|
||||||
let previewTheme: PresentationTheme
|
if let file = theme.theme.file, let path = context.sharedContext.accountManager.mediaBox.completedResourcePath(file.resource), let data = try? Data(contentsOf: URL(fileURLWithPath: path)), let theme = makePresentationTheme(data: data) {
|
||||||
if let file = theme.theme.file, let path = context.sharedContext.accountManager.mediaBox.completedResourcePath(file.resource), let data = try? Data(contentsOf: URL(fileURLWithPath: path)), let theme = makePresentationTheme(data: data, resolvedWallpaper: theme.resolvedWallpaper) {
|
if case let .file(file) = theme.chat.defaultWallpaper, file.id == 0 {
|
||||||
previewTheme = theme
|
previewThemePromise.set(cachedWallpaper(account: context.account, slug: file.slug)
|
||||||
|
|> map ({ wallpaper -> PresentationTheme in
|
||||||
|
return theme.withUpdated(name: nil, author: nil, defaultWallpaper: wallpaper?.wallpaper)
|
||||||
|
}))
|
||||||
} else {
|
} else {
|
||||||
previewTheme = context.sharedContext.currentPresentationData.with { $0 }.theme
|
previewThemePromise.set(.single(theme))
|
||||||
}
|
}
|
||||||
initialState = EditThemeControllerState(mode: mode, title: theme.theme.title, slug: theme.theme.slug, previewTheme: previewTheme, updatedTheme: nil, updating: false)
|
} else {
|
||||||
|
previewThemePromise.set(.single(context.sharedContext.currentPresentationData.with { $0 }.theme))
|
||||||
|
}
|
||||||
|
initialState = EditThemeControllerState(mode: mode, title: theme.theme.title, slug: theme.theme.slug, updatedTheme: nil, updating: false)
|
||||||
}
|
}
|
||||||
let statePromise = ValuePromise(initialState, ignoreRepeated: true)
|
let statePromise = ValuePromise(initialState, ignoreRepeated: true)
|
||||||
let stateValue = Atomic(value: initialState)
|
let stateValue = Atomic(value: initialState)
|
||||||
@ -249,22 +256,50 @@ public func editThemeController(context: AccountContext, mode: EditThemeControll
|
|||||||
}, openFile: {
|
}, openFile: {
|
||||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||||
let controller = legacyICloudFilePicker(theme: presentationData.theme, mode: .import, documentTypes: ["org.telegram.Telegram-iOS.theme"], completion: { urls in
|
let controller = legacyICloudFilePicker(theme: presentationData.theme, mode: .import, documentTypes: ["org.telegram.Telegram-iOS.theme"], completion: { urls in
|
||||||
if let url = urls.first, let data = try? Data(contentsOf: url), let theme = makePresentationTheme(data: data) {
|
if let url = urls.first{
|
||||||
|
if let data = try? Data(contentsOf: url), let theme = makePresentationTheme(data: data) {
|
||||||
|
if case let .file(file) = theme.chat.defaultWallpaper, file.id == 0 {
|
||||||
|
let _ = (cachedWallpaper(account: context.account, slug: file.slug)
|
||||||
|
|> mapToSignal { wallpaper -> Signal<TelegramWallpaper?, NoError> in
|
||||||
|
if let wallpaper = wallpaper, case let .file(file) = wallpaper.wallpaper {
|
||||||
|
var convertedRepresentations: [ImageRepresentationWithReference] = []
|
||||||
|
convertedRepresentations.append(ImageRepresentationWithReference(representation: TelegramMediaImageRepresentation(dimensions: CGSize(width: 100.0, height: 100.0), resource: file.file.resource), reference: .wallpaper(resource: file.file.resource)))
|
||||||
|
return wallpaperImage(account: context.account, accountManager: context.sharedContext.accountManager, fileReference: .standalone(media: file.file), representations: convertedRepresentations, alwaysShowThumbnailFirst: false, thumbnail: false, onlyFullSize: true, autoFetchFullSize: true, synchronousLoad: false)
|
||||||
|
|> map { _ -> TelegramWallpaper? in
|
||||||
|
return wallpaper.wallpaper
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return .single(nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|> deliverOnMainQueue).start(next: { wallpaper in
|
||||||
|
let updatedTheme = theme.withUpdated(name: nil, author: nil, defaultWallpaper: wallpaper)
|
||||||
updateState { current in
|
updateState { current in
|
||||||
var state = current
|
var state = current
|
||||||
state.previewTheme = theme
|
previewThemePromise.set(.single(updatedTheme))
|
||||||
|
state.updatedTheme = updatedTheme
|
||||||
|
return state
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
updateState { current in
|
||||||
|
var state = current
|
||||||
|
previewThemePromise.set(.single(theme))
|
||||||
state.updatedTheme = theme
|
state.updatedTheme = theme
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
presentControllerImpl?(textAlertController(context: context, title: nil, text: presentationData.strings.EditTheme_FileReadError, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil)
|
presentControllerImpl?(textAlertController(context: context, title: nil, text: presentationData.strings.EditTheme_FileReadError, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
presentControllerImpl?(controller, nil)
|
presentControllerImpl?(controller, nil)
|
||||||
})
|
})
|
||||||
|
|
||||||
let signal = combineLatest(queue: .mainQueue(), context.sharedContext.presentationData, statePromise.get())
|
let signal = combineLatest(queue: .mainQueue(), context.sharedContext.presentationData, statePromise.get(), previewThemePromise.get())
|
||||||
|> map { presentationData, state -> (ItemListControllerState, (ItemListNodeState<EditThemeControllerEntry>, EditThemeControllerEntry.ItemGenerationArguments)) in
|
|> map { presentationData, state, previewTheme -> (ItemListControllerState, (ItemListNodeState<EditThemeControllerEntry>, EditThemeControllerEntry.ItemGenerationArguments)) in
|
||||||
let leftNavigationButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Cancel), style: .regular, enabled: true, action: {
|
let leftNavigationButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Cancel), style: .regular, enabled: true, action: {
|
||||||
dismissImpl?()
|
dismissImpl?()
|
||||||
})
|
})
|
||||||
@ -293,6 +328,8 @@ public func editThemeController(context: AccountContext, mode: EditThemeControll
|
|||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let _ = (previewThemePromise.get()
|
||||||
|
|> deliverOnMainQueue).start(next: { previewTheme in
|
||||||
let saveThemeTemplateFile: (String, LocalFileMediaResource, @escaping () -> Void) -> Void = { title, resource, completion in
|
let saveThemeTemplateFile: (String, LocalFileMediaResource, @escaping () -> Void) -> Void = { title, resource, completion in
|
||||||
let file = TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: resource.fileId), partialReference: nil, resource: resource, previewRepresentations: [], immediateThumbnailData: nil, mimeType: "application/x-tgtheme-ios", size: nil, attributes: [.FileName(fileName: "\(title).tgios-theme")])
|
let file = TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: resource.fileId), partialReference: nil, resource: resource, previewRepresentations: [], immediateThumbnailData: nil, mimeType: "application/x-tgtheme-ios", size: nil, attributes: [.FileName(fileName: "\(title).tgios-theme")])
|
||||||
let message = EnqueueMessage.message(text: "", attributes: [], mediaReference: .standalone(media: file), replyToMessageId: nil, localGroupingKey: nil)
|
let message = EnqueueMessage.message(text: "", attributes: [], mediaReference: .standalone(media: file), replyToMessageId: nil, localGroupingKey: nil)
|
||||||
@ -321,7 +358,7 @@ public func editThemeController(context: AccountContext, mode: EditThemeControll
|
|||||||
theme = nil
|
theme = nil
|
||||||
hasCustomFile = true
|
hasCustomFile = true
|
||||||
} else {
|
} else {
|
||||||
theme = state.previewTheme.withUpdated(name: state.title, author: "", defaultWallpaper: nil)
|
theme = previewTheme.withUpdated(name: state.title, author: "", defaultWallpaper: nil)
|
||||||
hasCustomFile = false
|
hasCustomFile = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -449,6 +486,7 @@ public func editThemeController(context: AccountContext, mode: EditThemeControll
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
let title: String
|
let title: String
|
||||||
@ -463,7 +501,7 @@ public func editThemeController(context: AccountContext, mode: EditThemeControll
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let controllerState = ItemListControllerState(theme: presentationData.theme, title: .text(title), leftNavigationButton: leftNavigationButton, rightNavigationButton: rightNavigationButton, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back), animateChanges: false)
|
let controllerState = ItemListControllerState(theme: presentationData.theme, title: .text(title), leftNavigationButton: leftNavigationButton, rightNavigationButton: rightNavigationButton, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back), animateChanges: false)
|
||||||
let listState = ItemListNodeState(entries: editThemeControllerEntries(presentationData: presentationData, state: state), style: .blocks, focusItemTag: focusItemTag, emptyStateItem: nil, animateChanges: false)
|
let listState = ItemListNodeState(entries: editThemeControllerEntries(presentationData: presentationData, state: state, previewTheme: previewTheme), style: .blocks, focusItemTag: focusItemTag, emptyStateItem: nil, animateChanges: false)
|
||||||
|
|
||||||
return (controllerState, (listState, arguments))
|
return (controllerState, (listState, arguments))
|
||||||
}
|
}
|
||||||
|
@ -124,9 +124,6 @@ class ThemeSettingsChatPreviewItemNode: ListViewItemNode {
|
|||||||
let replyMessageId = MessageId(peerId: peerId, namespace: 0, id: 3)
|
let replyMessageId = MessageId(peerId: peerId, namespace: 0, id: 3)
|
||||||
messages[replyMessageId] = Message(stableId: 3, stableVersion: 0, id: replyMessageId, globallyUniqueId: nil, groupingKey: nil, groupInfo: nil, timestamp: 66000, flags: [.Incoming], tags: [], globalTags: [], localTags: [], forwardInfo: nil, author: peers[peerId], text: item.strings.Appearance_PreviewReplyText, attributes: [], media: [], peers: peers, associatedMessages: SimpleDictionary(), associatedMessageIds: [])
|
messages[replyMessageId] = Message(stableId: 3, stableVersion: 0, id: replyMessageId, globallyUniqueId: nil, groupingKey: nil, groupInfo: nil, timestamp: 66000, flags: [.Incoming], tags: [], globalTags: [], localTags: [], forwardInfo: nil, author: peers[peerId], text: item.strings.Appearance_PreviewReplyText, attributes: [], media: [], peers: peers, associatedMessages: SimpleDictionary(), associatedMessageIds: [])
|
||||||
|
|
||||||
//let chatPresentationData = ChatPresentationData(theme: ChatPresentationThemeData(theme: item.componentTheme, wallpaper: item.wallpaper), fontSize: item.fontSize, strings: item.strings, dateTimeFormat: item.dateTimeFormat, nameDisplayOrder: item.nameDisplayOrder, disableAnimations: false, largeEmoji: false)
|
|
||||||
|
|
||||||
//let item2: ChatMessageItem = ChatMessageItem(presentationData: chatPresentationData, context: item.context, chatLocation: .peer(peerId), associatedData: ChatMessageItemAssociatedData(automaticDownloadPeerType: .contact, automaticDownloadNetworkType: .cellular, isRecentActions: false), controllerInteraction: controllerInteraction, content: .message(message: Message(stableId: 1, stableVersion: 0, id: MessageId(peerId: peerId, namespace: 0, id: 1), globallyUniqueId: nil, groupingKey: nil, groupInfo: nil, timestamp: 66000, flags: [.Incoming], tags: [], globalTags: [], localTags: [], forwardInfo: nil, author: nil, text: item.strings.Appearance_PreviewIncomingText, attributes: [ReplyMessageAttribute(messageId: replyMessageId)], media: [], peers: peers, associatedMessages: messages, associatedMessageIds: []), read: true, selection: .none, attributes: ChatMessageEntryAttributes()), disableDate: true)
|
|
||||||
let message2 = Message(stableId: 1, stableVersion: 0, id: MessageId(peerId: peerId, namespace: 0, id: 1), globallyUniqueId: nil, groupingKey: nil, groupInfo: nil, timestamp: 66000, flags: [.Incoming], tags: [], globalTags: [], localTags: [], forwardInfo: nil, author: nil, text: item.strings.Appearance_PreviewIncomingText, attributes: [ReplyMessageAttribute(messageId: replyMessageId)], media: [], peers: peers, associatedMessages: messages, associatedMessageIds: [])
|
let message2 = Message(stableId: 1, stableVersion: 0, id: MessageId(peerId: peerId, namespace: 0, id: 1), globallyUniqueId: nil, groupingKey: nil, groupInfo: nil, timestamp: 66000, flags: [.Incoming], tags: [], globalTags: [], localTags: [], forwardInfo: nil, author: nil, text: item.strings.Appearance_PreviewIncomingText, attributes: [ReplyMessageAttribute(messageId: replyMessageId)], media: [], peers: peers, associatedMessages: messages, associatedMessageIds: [])
|
||||||
let message1 = Message(stableId: 2, stableVersion: 0, id: MessageId(peerId: peerId, namespace: 0, id: 2), globallyUniqueId: nil, groupingKey: nil, groupInfo: nil, timestamp: 66001, flags: [], tags: [], globalTags: [], localTags: [], forwardInfo: nil, author: TelegramUser(id: item.context.account.peerId, accessHash: nil, firstName: "", lastName: "", username: nil, phone: nil, photo: [], botInfo: nil, restrictionInfo: nil, flags: []), text: item.strings.Appearance_PreviewOutgoingText, attributes: [], media: [], peers: peers, associatedMessages: messages, associatedMessageIds: [])
|
let message1 = Message(stableId: 2, stableVersion: 0, id: MessageId(peerId: peerId, namespace: 0, id: 2), globallyUniqueId: nil, groupingKey: nil, groupInfo: nil, timestamp: 66001, flags: [], tags: [], globalTags: [], localTags: [], forwardInfo: nil, author: TelegramUser(id: item.context.account.peerId, accessHash: nil, firstName: "", lastName: "", username: nil, phone: nil, photo: [], botInfo: nil, restrictionInfo: nil, flags: []), text: item.strings.Appearance_PreviewOutgoingText, attributes: [], media: [], peers: peers, associatedMessages: messages, associatedMessageIds: [])
|
||||||
|
|
||||||
|
@ -260,6 +260,7 @@ private func uploadTheme(account: Account, resource: MediaResource, thumbnailDat
|
|||||||
|
|
||||||
public enum CreateThemeError {
|
public enum CreateThemeError {
|
||||||
case generic
|
case generic
|
||||||
|
case slugOccupied
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum CreateThemeResult {
|
public enum CreateThemeResult {
|
||||||
@ -319,6 +320,7 @@ public func updateTheme(account: Account, theme: TelegramTheme, title: String?,
|
|||||||
}
|
}
|
||||||
let uploadSignal: Signal<UploadThemeResult?, UploadThemeError>
|
let uploadSignal: Signal<UploadThemeResult?, UploadThemeError>
|
||||||
if let resource = resource {
|
if let resource = resource {
|
||||||
|
flags |= 1 << 2
|
||||||
uploadSignal = uploadTheme(account: account, resource: resource, thumbnailData: thumbnailData)
|
uploadSignal = uploadTheme(account: account, resource: resource, thumbnailData: thumbnailData)
|
||||||
|> map(Optional.init)
|
|> map(Optional.init)
|
||||||
} else {
|
} else {
|
||||||
@ -346,7 +348,12 @@ public func updateTheme(account: Account, theme: TelegramTheme, title: String?,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return account.network.request(Api.functions.account.updateTheme(flags: flags, theme: .inputTheme(id: theme.id, accessHash: theme.accessHash), slug: slug, title: title, document: inputDocument))
|
return account.network.request(Api.functions.account.updateTheme(flags: flags, theme: .inputTheme(id: theme.id, accessHash: theme.accessHash), slug: slug, title: title, document: inputDocument))
|
||||||
|> mapError { _ in return CreateThemeError.generic }
|
|> mapError { error -> CreateThemeError in
|
||||||
|
if error.errorDescription.hasPrefix("THEME_SLUG_OCCUPIED") {
|
||||||
|
return .slugOccupied
|
||||||
|
}
|
||||||
|
return .generic
|
||||||
|
}
|
||||||
|> mapToSignal { apiTheme -> Signal<CreateThemeResult, CreateThemeError> in
|
|> mapToSignal { apiTheme -> Signal<CreateThemeResult, CreateThemeError> in
|
||||||
if let result = TelegramTheme(apiTheme: apiTheme) {
|
if let result = TelegramTheme(apiTheme: apiTheme) {
|
||||||
return account.postbox.transaction { transaction -> CreateThemeResult in
|
return account.postbox.transaction { transaction -> CreateThemeResult in
|
||||||
|
@ -8,6 +8,7 @@ import LocalMediaResources
|
|||||||
import WebSearchUI
|
import WebSearchUI
|
||||||
import InstantPageCache
|
import InstantPageCache
|
||||||
import SettingsUI
|
import SettingsUI
|
||||||
|
import WallpaperResources
|
||||||
|
|
||||||
private var telegramUIDeclaredEncodables: Void = {
|
private var telegramUIDeclaredEncodables: Void = {
|
||||||
declareEncodable(InAppNotificationSettings.self, f: { InAppNotificationSettings(decoder: $0) })
|
declareEncodable(InAppNotificationSettings.self, f: { InAppNotificationSettings(decoder: $0) })
|
||||||
@ -40,6 +41,7 @@ private var telegramUIDeclaredEncodables: Void = {
|
|||||||
declareEncodable(InstantPageStoredState.self, f: { InstantPageStoredState(decoder: $0) })
|
declareEncodable(InstantPageStoredState.self, f: { InstantPageStoredState(decoder: $0) })
|
||||||
declareEncodable(InstantPageStoredDetailsState.self, f: { InstantPageStoredDetailsState(decoder: $0) })
|
declareEncodable(InstantPageStoredDetailsState.self, f: { InstantPageStoredDetailsState(decoder: $0) })
|
||||||
declareEncodable(CachedInstantPage.self, f: { CachedInstantPage(decoder: $0) })
|
declareEncodable(CachedInstantPage.self, f: { CachedInstantPage(decoder: $0) })
|
||||||
|
declareEncodable(CachedWallpaper.self, f: { CachedWallpaper(decoder: $0) })
|
||||||
declareEncodable(WatchPresetSettings.self, f: { WatchPresetSettings(decoder: $0) })
|
declareEncodable(WatchPresetSettings.self, f: { WatchPresetSettings(decoder: $0) })
|
||||||
declareEncodable(WebSearchSettings.self, f: { WebSearchSettings(decoder: $0) })
|
declareEncodable(WebSearchSettings.self, f: { WebSearchSettings(decoder: $0) })
|
||||||
declareEncodable(RecentWebSearchQueryItem.self, f: { RecentWebSearchQueryItem(decoder: $0) })
|
declareEncodable(RecentWebSearchQueryItem.self, f: { RecentWebSearchQueryItem(decoder: $0) })
|
||||||
|
@ -462,9 +462,8 @@ func openChatTheme(context: AccountContext, message: Message, present: @escaping
|
|||||||
if let webpage = media as? TelegramMediaWebpage, case let .Loaded(content) = webpage.content {
|
if let webpage = media as? TelegramMediaWebpage, case let .Loaded(content) = webpage.content {
|
||||||
let _ = (context.sharedContext.resolveUrl(account: context.account, url: content.url)
|
let _ = (context.sharedContext.resolveUrl(account: context.account, url: content.url)
|
||||||
|> deliverOnMainQueue).start(next: { resolvedUrl in
|
|> deliverOnMainQueue).start(next: { resolvedUrl in
|
||||||
if case let .theme(slug) = resolvedUrl {
|
if case let .theme(slug) = resolvedUrl, let files = content.files {
|
||||||
let file = content.files!.first!
|
if let file = files.filter({ $0.mimeType == "application/x-tgtheme-ios" }).first, let path = context.sharedContext.accountManager.mediaBox.completedResourcePath(file.resource), let data = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedRead), let theme = makePresentationTheme(data: data) {
|
||||||
if let path = context.account.postbox.mediaBox.completedResourcePath(file.resource), let data = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedRead), let theme = makePresentationTheme(data: data) {
|
|
||||||
let controller = ThemePreviewController(context: context, previewTheme: theme, source: .slug(slug, file))
|
let controller = ThemePreviewController(context: context, previewTheme: theme, source: .slug(slug, file))
|
||||||
present(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
present(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import PhotoResources
|
|||||||
import LocalMediaResources
|
import LocalMediaResources
|
||||||
import TelegramPresentationData
|
import TelegramPresentationData
|
||||||
|
|
||||||
private func wallpaperDatas(account: Account, accountManager: AccountManager, fileReference: FileMediaReference? = nil, representations: [ImageRepresentationWithReference], alwaysShowThumbnailFirst: Bool = false, thumbnail: Bool = false, autoFetchFullSize: Bool = false, synchronousLoad: Bool = false) -> Signal<(Data?, Data?, Bool), NoError> {
|
private func wallpaperDatas(account: Account, accountManager: AccountManager, fileReference: FileMediaReference? = nil, representations: [ImageRepresentationWithReference], alwaysShowThumbnailFirst: Bool = false, thumbnail: Bool = false, onlyFullSize: Bool = false, autoFetchFullSize: Bool = false, synchronousLoad: Bool = false) -> Signal<(Data?, Data?, Bool), NoError> {
|
||||||
if let smallestRepresentation = smallestImageRepresentation(representations.map({ $0.representation })), let largestRepresentation = largestImageRepresentation(representations.map({ $0.representation })), let smallestIndex = representations.firstIndex(where: { $0.representation == smallestRepresentation }), let largestIndex = representations.firstIndex(where: { $0.representation == largestRepresentation }) {
|
if let smallestRepresentation = smallestImageRepresentation(representations.map({ $0.representation })), let largestRepresentation = largestImageRepresentation(representations.map({ $0.representation })), let smallestIndex = representations.firstIndex(where: { $0.representation == smallestRepresentation }), let largestIndex = representations.firstIndex(where: { $0.representation == largestRepresentation }) {
|
||||||
|
|
||||||
let maybeFullSize: Signal<MediaResourceData, NoError>
|
let maybeFullSize: Signal<MediaResourceData, NoError>
|
||||||
@ -143,7 +143,11 @@ private func wallpaperDatas(account: Account, accountManager: AccountManager, fi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if onlyFullSize {
|
||||||
|
return fullSizeData |> map { (fullSizeData, complete) in
|
||||||
|
return (nil, fullSizeData, complete)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
return thumbnailData |> mapToSignal { thumbnailData in
|
return thumbnailData |> mapToSignal { thumbnailData in
|
||||||
return fullSizeData |> map { (fullSizeData, complete) in
|
return fullSizeData |> map { (fullSizeData, complete) in
|
||||||
return (thumbnailData, fullSizeData, complete)
|
return (thumbnailData, fullSizeData, complete)
|
||||||
@ -151,6 +155,7 @@ private func wallpaperDatas(account: Account, accountManager: AccountManager, fi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} |> filter({ $0.0 != nil || $0.1 != nil })
|
} |> filter({ $0.0 != nil || $0.1 != nil })
|
||||||
return signal
|
return signal
|
||||||
} else {
|
} else {
|
||||||
@ -158,11 +163,14 @@ private func wallpaperDatas(account: Account, accountManager: AccountManager, fi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func wallpaperImage(account: Account, accountManager: AccountManager, fileReference: FileMediaReference? = nil, representations: [ImageRepresentationWithReference], alwaysShowThumbnailFirst: Bool = false, thumbnail: Bool = false, autoFetchFullSize: Bool = false, synchronousLoad: Bool = false) -> Signal<(TransformImageArguments) -> DrawingContext?, NoError> {
|
public func wallpaperImage(account: Account, accountManager: AccountManager, fileReference: FileMediaReference? = nil, representations: [ImageRepresentationWithReference], alwaysShowThumbnailFirst: Bool = false, thumbnail: Bool = false, onlyFullSize: Bool = false, autoFetchFullSize: Bool = false, synchronousLoad: Bool = false) -> Signal<(TransformImageArguments) -> DrawingContext?, NoError> {
|
||||||
let signal = wallpaperDatas(account: account, accountManager: accountManager, fileReference: fileReference, representations: representations, alwaysShowThumbnailFirst: alwaysShowThumbnailFirst, thumbnail: thumbnail, autoFetchFullSize: autoFetchFullSize, synchronousLoad: synchronousLoad)
|
let signal = wallpaperDatas(account: account, accountManager: accountManager, fileReference: fileReference, representations: representations, alwaysShowThumbnailFirst: alwaysShowThumbnailFirst, thumbnail: thumbnail, onlyFullSize: onlyFullSize, autoFetchFullSize: autoFetchFullSize, synchronousLoad: synchronousLoad)
|
||||||
|
|
||||||
return signal
|
return signal
|
||||||
|> map { (thumbnailData, fullSizeData, fullSizeComplete) in
|
|> map { (thumbnailData, fullSizeData, fullSizeComplete) in
|
||||||
|
if let fullSizeData = fullSizeData, let fileReference = fileReference {
|
||||||
|
accountManager.mediaBox.storeResourceData(fileReference.media.resource.id, data: fullSizeData)
|
||||||
|
}
|
||||||
return { arguments in
|
return { arguments in
|
||||||
let drawingRect = arguments.drawingRect
|
let drawingRect = arguments.drawingRect
|
||||||
var fittedSize = arguments.imageSize
|
var fittedSize = arguments.imageSize
|
||||||
|
Loading…
x
Reference in New Issue
Block a user