From 5385b67ce87fb99e91ea594187365d525ae3a440 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 17 Jan 2023 02:29:32 +0400 Subject: [PATCH] Various fixes --- .../Sources/AvatarEditorScreen.swift | 9 +++++++++ .../Sources/BackgroundColorComponent.swift | 14 ++++++++++---- .../Sources/ColorPickerComponent.swift | 12 ++++++++++++ .../Sources/EmojiPagerContentComponent.swift | 6 ++++-- submodules/TelegramUI/Sources/ChatController.swift | 10 +++++++--- 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/submodules/TelegramUI/Components/AvatarEditorScreen/Sources/AvatarEditorScreen.swift b/submodules/TelegramUI/Components/AvatarEditorScreen/Sources/AvatarEditorScreen.swift index 4083491d5f..7a7b1251c0 100644 --- a/submodules/TelegramUI/Components/AvatarEditorScreen/Sources/AvatarEditorScreen.swift +++ b/submodules/TelegramUI/Components/AvatarEditorScreen/Sources/AvatarEditorScreen.swift @@ -101,6 +101,9 @@ final class AvatarEditorScreenComponent: Component { var editingColor: Bool = false var previousColor: AvatarBackground + var previousCustomColor: AvatarBackground? + var customColor: AvatarBackground? + var isSearchActive: Bool = false init(context: AccountContext) { @@ -825,6 +828,7 @@ final class AvatarEditorScreenComponent: Component { theme: environment.theme, values: defaultBackgrounds, selectedValue: state.selectedBackground, + customValue: state.customColor, updateValue: { [weak state] value in if let state { state.selectedBackground = value @@ -835,6 +839,7 @@ final class AvatarEditorScreenComponent: Component { if let state { state.editingColor = true state.previousColor = state.selectedBackground + state.previousCustomColor = state.customColor state.updated(transition: .easeInOut(duration: 0.3)) } } @@ -857,9 +862,11 @@ final class AvatarEditorScreenComponent: Component { ColorPickerComponent( theme: environment.theme, strings: environment.strings, + isVisible: state.editingColor, colors: state.selectedBackground.colors, colorsChanged: { [weak state] colors in if let state { + state.customColor = .gradient(colors) state.selectedBackground = .gradient(colors) state.updated(transition: .immediate) } @@ -867,6 +874,7 @@ final class AvatarEditorScreenComponent: Component { cancel: { [weak state] in if let state { state.selectedBackground = state.previousColor + state.customColor = state.previousCustomColor state.editingColor = false state.updated(transition: .easeInOut(duration: 0.3)) } @@ -874,6 +882,7 @@ final class AvatarEditorScreenComponent: Component { done: { [weak state] in if let state { state.editingColor = false + state.customColor = state.selectedBackground state.updated(transition: .easeInOut(duration: 0.3)) } } diff --git a/submodules/TelegramUI/Components/AvatarEditorScreen/Sources/BackgroundColorComponent.swift b/submodules/TelegramUI/Components/AvatarEditorScreen/Sources/BackgroundColorComponent.swift index 90190a4217..4272226fd6 100644 --- a/submodules/TelegramUI/Components/AvatarEditorScreen/Sources/BackgroundColorComponent.swift +++ b/submodules/TelegramUI/Components/AvatarEditorScreen/Sources/BackgroundColorComponent.swift @@ -11,6 +11,7 @@ final class BackgroundColorComponent: Component { let theme: PresentationTheme let values: [AvatarBackground] let selectedValue: AvatarBackground + let customValue: AvatarBackground? let updateValue: (AvatarBackground) -> Void let openColorPicker: () -> Void @@ -18,12 +19,14 @@ final class BackgroundColorComponent: Component { theme: PresentationTheme, values: [AvatarBackground], selectedValue: AvatarBackground, + customValue: AvatarBackground?, updateValue: @escaping (AvatarBackground) -> Void, openColorPicker: @escaping () -> Void ) { self.theme = theme self.values = values self.selectedValue = selectedValue + self.customValue = customValue self.updateValue = updateValue self.openColorPicker = openColorPicker } @@ -38,6 +41,9 @@ final class BackgroundColorComponent: Component { if lhs.selectedValue != rhs.selectedValue { return false } + if lhs.customValue != rhs.customValue { + return false + } return true } @@ -62,8 +68,8 @@ final class BackgroundColorComponent: Component { self.state = state var values: [(AvatarBackground?, Bool)] = component.values.map { ($0, false) } - if !values.contains(where: { $0.0 == component.selectedValue }) { - values.append((component.selectedValue, true)) + if let customValue = component.customValue { + values.append((customValue, true)) } else { values.append((nil, true)) } @@ -91,9 +97,9 @@ final class BackgroundColorComponent: Component { isCustom: values[i].1, isSelected: component.selectedValue == values[i].0, action: { - if !values[i].1, let value = values[i].0 { + if let value = values[i].0, component.selectedValue != value { component.updateValue(value) - } else { + } else if values[i].1 { component.openColorPicker() } } diff --git a/submodules/TelegramUI/Components/AvatarEditorScreen/Sources/ColorPickerComponent.swift b/submodules/TelegramUI/Components/AvatarEditorScreen/Sources/ColorPickerComponent.swift index e5c25f9aba..851f611299 100644 --- a/submodules/TelegramUI/Components/AvatarEditorScreen/Sources/ColorPickerComponent.swift +++ b/submodules/TelegramUI/Components/AvatarEditorScreen/Sources/ColorPickerComponent.swift @@ -20,6 +20,7 @@ private struct WallpaperColorPanelNodeState: Equatable { final class ColorPickerComponent: Component { let theme: PresentationTheme let strings: PresentationStrings + let isVisible: Bool let colors: [UInt32] let colorsChanged: ([UInt32]) -> Void let cancel: () -> Void @@ -28,6 +29,7 @@ final class ColorPickerComponent: Component { init( theme: PresentationTheme, strings: PresentationStrings, + isVisible: Bool, colors: [UInt32], colorsChanged: @escaping ([UInt32]) -> Void, cancel: @escaping () -> Void, @@ -35,6 +37,7 @@ final class ColorPickerComponent: Component { ) { self.theme = theme self.strings = strings + self.isVisible = isVisible self.colors = colors self.colorsChanged = colorsChanged self.cancel = cancel @@ -48,6 +51,9 @@ final class ColorPickerComponent: Component { if lhs.strings !== rhs.strings { return false } + if lhs.isVisible != rhs.isVisible { + return false + } if lhs.colors != rhs.colors { return false } @@ -381,6 +387,7 @@ final class ColorPickerComponent: Component { private var component: ColorPickerComponent? func update(component: ColorPickerComponent, availableSize: CGSize, transition: Transition) -> CGSize { let themeChanged = self.component?.theme !== component.theme + let previousIsVisible = self.component?.isVisible ?? false self.component = component let buttonHeight: CGFloat = 44.0 @@ -412,6 +419,11 @@ final class ColorPickerComponent: Component { self.updateState({ current in var updated = current updated.colors = component.colors.map { HSBColor(rgb: $0) } + + if component.isVisible != previousIsVisible && component.isVisible { + updated.selection = 0 + } + return updated }, updateLayout: true, notify: false, animated: false) diff --git a/submodules/TelegramUI/Components/EntityKeyboard/Sources/EmojiPagerContentComponent.swift b/submodules/TelegramUI/Components/EntityKeyboard/Sources/EmojiPagerContentComponent.swift index f5a2aa0b4f..27cbc2912b 100644 --- a/submodules/TelegramUI/Components/EntityKeyboard/Sources/EmojiPagerContentComponent.swift +++ b/submodules/TelegramUI/Components/EntityKeyboard/Sources/EmojiPagerContentComponent.swift @@ -7243,13 +7243,15 @@ public final class EmojiPagerContentComponent: Component { return combineLatest( context.account.postbox.itemCollectionsView(orderedItemListCollectionIds: stickerOrderedItemListCollectionIds, namespaces: stickerNamespaces, aroundIndex: nil, count: 10000000), - forceHasPremium ? .single(true) : hasPremium(context: context, chatPeerId: chatPeerId, premiumIfSavedMessages: false), + hasPremium(context: context, chatPeerId: chatPeerId, premiumIfSavedMessages: false), hasTrending ? context.account.viewTracker.featuredStickerPacks() : .single([]), context.engine.data.get(TelegramEngine.EngineData.Item.ItemCache.Item(collectionId: Namespaces.CachedItemCollection.featuredStickersConfiguration, id: ValueBoxKey(length: 0))), ApplicationSpecificNotice.dismissedTrendingStickerPacks(accountManager: context.sharedContext.accountManager), peerSpecificPack ) |> map { view, hasPremium, featuredStickerPacks, featuredStickersConfiguration, dismissedTrendingStickerPacks, peerSpecificPack -> EmojiPagerContentComponent in + let actuallyHasPremium = hasPremium + let hasPremium = forceHasPremium || hasPremium struct ItemGroup { var supergroupId: AnyHashable var id: AnyHashable @@ -7435,7 +7437,7 @@ public final class EmojiPagerContentComponent: Component { } } - if let cloudPremiumStickers = cloudPremiumStickers, !cloudPremiumStickers.items.isEmpty { + if let cloudPremiumStickers = cloudPremiumStickers, !cloudPremiumStickers.items.isEmpty, actuallyHasPremium { premiumStickers.append(contentsOf: cloudPremiumStickers.items.compactMap { item -> StickerPackItem? in guard let item = item.contents.get(RecentMediaItem.self) else { return nil } diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index cbc27cb27f..6d7b66f68e 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -2391,7 +2391,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G strongSelf.chatDisplayNode.dismissInput() strongSelf.present(controller, in: .window(.root)) case let .accepted(url): - strongSelf.openUrl(url, concealed: false, skipUrlAuth: true) + strongSelf.openUrl(url, concealed: false, forceExternal: true, skipUrlAuth: true) } } })) @@ -15691,10 +15691,14 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } }) } else { - self.effectiveNavigationController?.pushViewController(ChatControllerImpl(context: self.context, chatLocation: .peer(id: peer.id), subject: subject)) + if case let .channel(channel) = peer, channel.flags.contains(.isForum) { + self.effectiveNavigationController?.pushViewController(ChatListControllerImpl(context: self.context, location: .forum(peerId: channel.id), controlsHistoryPreload: false, enableDebugActions: false)) + } else { + self.effectiveNavigationController?.pushViewController(ChatControllerImpl(context: self.context, chatLocation: .peer(id: peer.id), subject: subject)) + } } case let .withBotStartPayload(botStart): - self.effectiveNavigationController?.pushViewController(ChatControllerImpl(context: self.context, chatLocation: .peer(id: peer.id), botStart: botStart)) + self.effectiveNavigationController?.pushViewController(ChatControllerImpl(context: self.context, chatLocation: .peer(id: peer.id), botStart: botStart)) case let .withAttachBot(attachBotStart): if let navigationController = self.effectiveNavigationController { self.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: self.context, chatLocation: .peer(peer), attachBotStart: attachBotStart))