diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Data/PeersData.swift b/submodules/TelegramCore/Sources/TelegramEngine/Data/PeersData.swift index 5c1b992508..f8538240fb 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Data/PeersData.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Data/PeersData.swift @@ -521,6 +521,34 @@ public extension TelegramEngine.EngineData.Item { } } + public struct CanSetStickerPack: TelegramEngineDataItem, TelegramEngineMapKeyDataItem, PostboxViewDataItem { + public typealias Result = Bool + + fileprivate var id: EnginePeer.Id + public var mapKey: EnginePeer.Id { + return self.id + } + + public init(id: EnginePeer.Id) { + self.id = id + } + + var key: PostboxViewKey { + return .cachedPeerData(peerId: self.id) + } + + func extract(view: PostboxView) -> Result { + guard let view = view as? CachedPeerDataView else { + preconditionFailure() + } + if let cachedData = view.cachedPeerData as? CachedChannelData { + return cachedData.flags.contains(.canSetStickerSet) + } else { + return false + } + } + } + public struct StickerPack: TelegramEngineDataItem, TelegramEngineMapKeyDataItem, PostboxViewDataItem { public typealias Result = StickerPackCollectionInfo? diff --git a/submodules/TelegramUI/Components/EmojiActionIconComponent/Sources/EmojiActionIconComponent.swift b/submodules/TelegramUI/Components/EmojiActionIconComponent/Sources/EmojiActionIconComponent.swift index 8151591b78..6bee0832ad 100644 --- a/submodules/TelegramUI/Components/EmojiActionIconComponent/Sources/EmojiActionIconComponent.swift +++ b/submodules/TelegramUI/Components/EmojiActionIconComponent/Sources/EmojiActionIconComponent.swift @@ -46,8 +46,20 @@ public final class EmojiActionIconComponent: Component { func update(component: EmojiActionIconComponent, availableSize: CGSize, state: EmptyComponentState, environment: Environment, transition: Transition) -> CGSize { let size = CGSize(width: 24.0, height: 24.0) - if let fileId = component.fileId { - var iconSize = size + var iconSize = size + let content: EmojiStatusComponent.AnimationContent? + if let file = component.file { + if let dimensions = file.dimensions { + iconSize = dimensions.cgSize.aspectFitted(size) + } + content = .file(file: file) + } else if let fileId = component.fileId { + content = .customEmoji(fileId: fileId) + } else { + content = nil + } + + if let content { let icon: ComponentView if let current = self.icon { icon = current @@ -55,15 +67,7 @@ public final class EmojiActionIconComponent: Component { icon = ComponentView() self.icon = icon } - let content: EmojiStatusComponent.AnimationContent - if let file = component.file { - if let dimensions = file.dimensions { - iconSize = dimensions.cgSize.aspectFitted(size) - } - content = .file(file: file) - } else { - content = .customEmoji(fileId: fileId) - } + let _ = icon.update( transition: .immediate, component: AnyComponent(EmojiStatusComponent( diff --git a/submodules/TelegramUI/Components/PeerInfo/PeerInfoScreen/Sources/PeerInfoScreen.swift b/submodules/TelegramUI/Components/PeerInfo/PeerInfoScreen/Sources/PeerInfoScreen.swift index 0fb1d0616c..3abe8d18e5 100644 --- a/submodules/TelegramUI/Components/PeerInfo/PeerInfoScreen/Sources/PeerInfoScreen.swift +++ b/submodules/TelegramUI/Components/PeerInfo/PeerInfoScreen/Sources/PeerInfoScreen.swift @@ -1966,7 +1966,6 @@ private func editingItems(data: PeerInfoScreenData?, state: PeerInfoState, chatL let ItemInviteLinks = 102 let ItemLinkedChannel = 103 let ItemPreHistory = 104 - let ItemStickerPack = 105 let ItemMembers = 106 let ItemPermissions = 107 let ItemAdmins = 108 @@ -2135,13 +2134,7 @@ private func editingItems(data: PeerInfoScreenData?, state: PeerInfoState, chatL interaction.editingOpenPreHistorySetup() })) } - - if cachedData.flags.contains(.canSetStickerSet) && canEditPeerInfo(context: context, peer: channel, chatLocation: chatLocation, threadData: data.threadData) { - items[.peerDataSettings]!.append(PeerInfoScreenDisclosureItem(id: ItemStickerPack, label: .text(cachedData.stickerPack?.title ?? presentationData.strings.GroupInfo_SharedMediaNone), text: presentationData.strings.Stickers_GroupStickers, icon: UIImage(bundleImageName: "Settings/Menu/Stickers"), action: { - interaction.editingOpenStickerPackSetup() - })) - } - + if isCreator, let appConfiguration = data.appConfiguration { var minParticipants = 200 if let data = appConfiguration.data, let value = data["forum_upgrade_participants_min"] as? Double { diff --git a/submodules/TelegramUI/Components/Settings/PeerNameColorScreen/Sources/ChannelAppearanceScreen.swift b/submodules/TelegramUI/Components/Settings/PeerNameColorScreen/Sources/ChannelAppearanceScreen.swift index e98d2b47b1..c7204300d0 100644 --- a/submodules/TelegramUI/Components/Settings/PeerNameColorScreen/Sources/ChannelAppearanceScreen.swift +++ b/submodules/TelegramUI/Components/Settings/PeerNameColorScreen/Sources/ChannelAppearanceScreen.swift @@ -72,13 +72,17 @@ final class ChannelAppearanceScreenComponent: Component { let peer: EnginePeer? let peerWallpaper: TelegramWallpaper? let peerEmojiPack: StickerPackCollectionInfo? + let canSetStickerPack: Bool + let peerStickerPack: StickerPackCollectionInfo? let subscriberCount: Int? let availableThemes: [TelegramTheme] - init(peer: EnginePeer?, peerWallpaper: TelegramWallpaper?, peerEmojiPack: StickerPackCollectionInfo?, subscriberCount: Int?, availableThemes: [TelegramTheme]) { + init(peer: EnginePeer?, peerWallpaper: TelegramWallpaper?, peerEmojiPack: StickerPackCollectionInfo?, canSetStickerPack: Bool, peerStickerPack: StickerPackCollectionInfo?, subscriberCount: Int?, availableThemes: [TelegramTheme]) { self.peer = peer self.peerWallpaper = peerWallpaper self.peerEmojiPack = peerEmojiPack + self.canSetStickerPack = canSetStickerPack + self.peerStickerPack = peerStickerPack self.subscriberCount = subscriberCount self.availableThemes = availableThemes } @@ -89,16 +93,20 @@ final class ChannelAppearanceScreenComponent: Component { TelegramEngine.EngineData.Item.Peer.Peer(id: peerId), TelegramEngine.EngineData.Item.Peer.ParticipantCount(id: peerId), TelegramEngine.EngineData.Item.Peer.EmojiPack(id: peerId), + TelegramEngine.EngineData.Item.Peer.CanSetStickerPack(id: peerId), + TelegramEngine.EngineData.Item.Peer.StickerPack(id: peerId), TelegramEngine.EngineData.Item.Peer.Wallpaper(id: peerId) ), telegramThemes(postbox: context.account.postbox, network: context.account.network, accountManager: context.sharedContext.accountManager) ) |> map { peerData, cloudThemes -> ContentsData in - let (peer, subscriberCount, emojiPack, wallpaper) = peerData + let (peer, subscriberCount, emojiPack, canSetStickerPack, stickerPack, wallpaper) = peerData return ContentsData( peer: peer, peerWallpaper: wallpaper, peerEmojiPack: emojiPack, + canSetStickerPack: canSetStickerPack, + peerStickerPack: stickerPack, subscriberCount: subscriberCount, availableThemes: cloudThemes ) @@ -178,6 +186,7 @@ final class ChannelAppearanceScreenComponent: Component { private let resetColorSection = ComponentView() private let emojiStatusSection = ComponentView() private let emojiPackSection = ComponentView() + private let stickerPackSection = ComponentView() private var chatPreviewItemNode: PeerNameColorChatPreviewItemNode? @@ -652,6 +661,15 @@ final class ChannelAppearanceScreenComponent: Component { self.environment?.controller()?.push(controller) } + private func openStickerPackSetup() { + guard let component = self.component, let environment = self.environment, let contentsData = self.contentsData else { + return + } + + let controller = groupStickerPackSetupController(context: component.context, peerId: component.peerId, currentPackInfo: contentsData.peerStickerPack) + environment.controller()?.push(controller) + } + private func openEmojiPackSetup() { guard let component = self.component, let environment = self.environment, let resolvedState = self.resolveState() else { return @@ -1290,7 +1308,6 @@ final class ChannelAppearanceScreenComponent: Component { )))) } - var emojiPackFile: TelegramMediaFile? if let thumbnail = emojiPack?.thumbnail { emojiPackFile = TelegramMediaFile(fileId: MediaId(namespace: 0, id: 0), partialReference: nil, resource: thumbnail.resource, previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: thumbnail.immediateThumbnailData, mimeType: "", size: nil, attributes: []) @@ -1408,6 +1425,70 @@ final class ChannelAppearanceScreenComponent: Component { contentHeight += emojiStatusSectionSize.height contentHeight += sectionSpacing + if isGroup && contentsData.canSetStickerPack { + var stickerPackContents: [AnyComponentWithIdentity] = [] + stickerPackContents.append(AnyComponentWithIdentity(id: 0, component: AnyComponent(MultilineTextComponent( + text: .plain(NSAttributedString( + string: environment.strings.Stickers_GroupStickers, + font: Font.regular(presentationData.listsFontSize.baseDisplaySize), + textColor: environment.theme.list.itemPrimaryTextColor + )), + maximumNumberOfLines: 0 + )))) + + var stickerPackFile: TelegramMediaFile? + if let peerStickerPack = contentsData.peerStickerPack, let thumbnail = peerStickerPack.thumbnail { + stickerPackFile = TelegramMediaFile(fileId: MediaId(namespace: 0, id: peerStickerPack.id.id), partialReference: nil, resource: thumbnail.resource, previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: thumbnail.immediateThumbnailData, mimeType: "", size: nil, attributes: []) + } + + let stickerPackSectionSize = self.stickerPackSection.update( + transition: transition, + component: AnyComponent(ListSectionComponent( + theme: environment.theme, + header: nil, + footer: AnyComponent(MultilineTextComponent( + text: .plain(NSAttributedString( + string: environment.strings.Stickers_GroupStickersHelp, + font: Font.regular(presentationData.listsFontSize.itemListBaseHeaderFontSize), + textColor: environment.theme.list.freeTextColor + )), + maximumNumberOfLines: 0 + )), + items: [ + AnyComponentWithIdentity(id: 0, component: AnyComponent(ListActionItemComponent( + theme: environment.theme, + title: AnyComponent(HStack(stickerPackContents, spacing: 6.0)), + icon: ListActionItemComponent.Icon(component: AnyComponentWithIdentity(id: 0, component: AnyComponent(EmojiActionIconComponent( + context: component.context, + color: environment.theme.list.itemAccentColor, + fileId: nil, + file: stickerPackFile + )))), + action: { [weak self] view in + guard let self else { + return + } + self.openStickerPackSetup() + } + ))) + ], + displaySeparators: false, + extendsItemHighlightToSection: true + )), + environment: {}, + containerSize: CGSize(width: availableSize.width - sideInset * 2.0, height: 1000.0) + ) + let stickerPackSectionFrame = CGRect(origin: CGPoint(x: sideInset, y: contentHeight), size: stickerPackSectionSize) + if let stickerPackSectionView = self.stickerPackSection.view { + if stickerPackSectionView.superview == nil { + self.scrollView.addSubview(stickerPackSectionView) + } + transition.setFrame(view: stickerPackSectionView, frame: stickerPackSectionFrame) + } + contentHeight += stickerPackSectionSize.height + contentHeight += sectionSpacing + } + var chatPreviewTheme: PresentationTheme = environment.theme var chatPreviewWallpaper: TelegramWallpaper = presentationData.chatWallpaper if let updatedWallpaper = self.updatedPeerWallpaper, case .remove = updatedWallpaper {