This commit is contained in:
Isaac
2025-10-24 20:09:32 +04:00
parent 5633833085
commit fcdfd8e00f
16 changed files with 915 additions and 42 deletions

View File

@@ -18,8 +18,11 @@ import TelegramNotices
import GlassBackgroundComponent
import ComponentFlow
import ComponentDisplayAdapters
import GlassControls
import BundleIconComponent
import MultilineTextComponent
private enum SubscriberAction: Equatable {
private enum SubscriberAction: Equatable, Hashable {
case join
case joinGroup
case applyToJoin
@@ -143,7 +146,10 @@ private func actionForPeer(context: AccountContext, peer: Peer, interfaceState:
private let badgeFont = Font.regular(14.0)
public final class ChatChannelSubscriberInputPanelNode: ChatInputPanelNode {
private let buttonBackgroundView: GlassBackgroundView
private let panelContainer = UIView()
private let panel = ComponentView<Empty>()
/*private let buttonBackgroundView: GlassBackgroundView
private let button: HighlightableButton
private let buttonTitle: ImmediateTextNode
private let buttonTintTitle: ImmediateTextNode
@@ -158,7 +164,7 @@ public final class ChatChannelSubscriberInputPanelNode: ChatInputPanelNode {
private let suggestedPostButtonBackgroundView: GlassBackgroundView
private let suggestedPostButton: HighlightableButton
private let suggestedPostButtonIconView: UIImageView
private let suggestedPostButtonIconView: UIImageView*/
private var action: SubscriberAction?
@@ -171,7 +177,7 @@ public final class ChatChannelSubscriberInputPanelNode: ChatInputPanelNode {
private var layoutData: (CGFloat, CGFloat, CGFloat, CGFloat, UIEdgeInsets, CGFloat, CGFloat, Bool, LayoutMetrics)?
public override init() {
self.button = HighlightableButton()
/*self.button = HighlightableButton()
self.buttonBackgroundView = GlassBackgroundView()
self.buttonBackgroundView.isUserInteractionEnabled = false
self.buttonTitle = ImmediateTextNode()
@@ -203,18 +209,20 @@ public final class ChatChannelSubscriberInputPanelNode: ChatInputPanelNode {
self.suggestedPostButtonIconView = GlassBackgroundView.ContentImageView()
self.suggestedPostButtonBackgroundView.contentView.addSubview(self.suggestedPostButtonIconView)
self.suggestedPostButtonBackgroundView.contentView.addSubview(self.suggestedPostButton)
self.suggestedPostButtonBackgroundView.isHidden = true
self.suggestedPostButtonBackgroundView.isHidden = true*/
super.init()
self.view.addSubview(self.buttonBackgroundView)
/*self.view.addSubview(self.buttonBackgroundView)
self.view.addSubview(self.helpButtonBackgroundView)
self.view.addSubview(self.giftButtonBackgroundView)
self.view.addSubview(self.suggestedPostButtonBackgroundView)
self.button.addTarget(self, action: #selector(self.buttonPressed), for: .touchUpInside)
self.helpButton.addTarget(self, action: #selector(self.helpPressed), for: .touchUpInside)
self.giftButton.addTarget(self, action: #selector(self.giftPressed), for: .touchUpInside)
self.suggestedPostButton.addTarget(self, action: #selector(self.suggestedPostPressed), for: .touchUpInside)
self.suggestedPostButton.addTarget(self, action: #selector(self.suggestedPostPressed), for: .touchUpInside)*/
self.view.addSubview(self.panelContainer)
}
deinit {
@@ -330,11 +338,17 @@ public final class ChatChannelSubscriberInputPanelNode: ChatInputPanelNode {
}
#endif*/
if giftCount < 2 && !self.giftButton.isHidden {
let giftItemView = (self.panel.view as? GlassControlPanelComponent.View)?.leftItemView?.itemView(id: AnyHashable("gift"))
let suggestPostItemView = (self.panel.view as? GlassControlPanelComponent.View)?.leftItemView?.itemView(id: AnyHashable("suggestPost"))
if giftCount < 2, let giftItemView {
let _ = ApplicationSpecificNotice.incrementChannelSendGiftTooltip(accountManager: context.sharedContext.accountManager).start()
Queue.mainQueue().after(0.4, {
let absoluteFrame = self.giftButton.convert(self.giftButton.bounds, to: parentController.view)
Queue.mainQueue().after(0.4, { [weak giftItemView] in
guard let giftItemView else {
return
}
let absoluteFrame = giftItemView.convert(giftItemView.bounds, to: parentController.view)
let location = CGRect(origin: CGPoint(x: absoluteFrame.midX, y: absoluteFrame.minY), size: CGSize())
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
@@ -357,11 +371,14 @@ public final class ChatChannelSubscriberInputPanelNode: ChatInputPanelNode {
)
self.interfaceInteraction?.presentControllerInCurrent(tooltipController, nil)
})
} else if suggestCount < 2 && !self.suggestedPostButton.isHidden {
} else if suggestCount < 2, let suggestPostItemView {
let _ = ApplicationSpecificNotice.incrementChannelSuggestTooltip(accountManager: context.sharedContext.accountManager).start()
Queue.mainQueue().after(0.4, {
let absoluteFrame = self.suggestedPostButton.convert(self.suggestedPostButton.bounds, to: parentController.view)
Queue.mainQueue().after(0.4, { [weak suggestPostItemView] in
guard let suggestPostItemView else {
return
}
let absoluteFrame = suggestPostItemView.convert(suggestPostItemView.bounds, to: parentController.view)
let location = CGRect(origin: CGPoint(x: absoluteFrame.midX, y: absoluteFrame.minY), size: CGSize())
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
@@ -394,7 +411,133 @@ public final class ChatChannelSubscriberInputPanelNode: ChatInputPanelNode {
let isFirstTime = self.layoutData == nil
self.layoutData = (width, leftInset, rightInset, bottomInset, additionalSideInsets, maxHeight, maxOverlayHeight, isSecondary, metrics)
if self.presentationInterfaceState != interfaceState || force {
var transition = transition
if !isFirstTime && !transition.isAnimated {
transition = .animated(duration: 0.4, curve: .spring)
}
self.presentationInterfaceState = interfaceState
var centerAction: (title: String, isAccent: Bool)?
if let context = self.context, let peer = interfaceState.renderedPeer?.peer, let action = actionForPeer(context: context, peer: peer, interfaceState: interfaceState, isJoining: self.isJoining, isMuted: interfaceState.peerIsMuted) {
self.action = action
let (title, _) = titleAndColorForAction(action, theme: interfaceState.theme, strings: interfaceState.strings)
var isAccent = false
if case .join = self.action {
isAccent = true
}
centerAction = (title, isAccent)
}
var displayGift = false
var displaySuggestPost = false
var displayHelp = false
if let peer = interfaceState.renderedPeer?.peer as? TelegramChannel {
if case .broadcast = peer.info, interfaceState.starGiftsAvailable {
displayGift = true
}
if case let .broadcast(broadcastInfo) = peer.info, broadcastInfo.flags.contains(.hasMonoforum) {
displaySuggestPost = true
}
if peer.flags.contains(.isGigagroup), self.action == .muteNotifications || self.action == .unmuteNotifications {
displayHelp = true
}
}
var leftInset = leftInset + 8.0
var rightInset = rightInset + 8.0
if bottomInset <= 32.0 {
leftInset += 18.0
rightInset += 18.0
}
var leftPanelItems: [GlassControlGroupComponent.Item] = []
if displaySuggestPost {
leftPanelItems.append(GlassControlGroupComponent.Item(
id: "suggestPost",
content: .icon("Chat/Input/Accessory Panels/SuggestPost"),
action: { [weak self] in
self?.suggestedPostPressed()
}
))
}
if displayGift {
leftPanelItems.append(GlassControlGroupComponent.Item(
id: "gift",
content: .icon("Chat/Input/Accessory Panels/Gift"),
action: { [weak self] in
self?.giftPressed()
}
))
}
if displayHelp {
leftPanelItems.append(GlassControlGroupComponent.Item(
id: "help",
content: .icon("Chat/Input/Accessory Panels/Help"),
action: { [weak self] in
self?.helpPressed()
}
))
}
var centerPanelItem: GlassControlPanelComponent.Item?
if let centerAction {
centerPanelItem = GlassControlPanelComponent.Item(
items: [GlassControlGroupComponent.Item(
id: 0,
content: .text(centerAction.title),
action: { [weak self] in
self?.buttonPressed()
}
)],
background: centerAction.isAccent ? .activeTint : .panel
)
}
var rightPanelItems: [GlassControlGroupComponent.Item] = []
rightPanelItems.append(GlassControlGroupComponent.Item(
id: "search",
content: .icon("Chat List/SearchIcon"),
action: { [weak self] in
guard let self else {
return
}
self.interfaceInteraction?.beginMessageSearch(.everything, "")
}
))
let panelHeight = defaultHeight(metrics: metrics)
let _ = isFirstTime
let panelFrame = CGRect(origin: CGPoint(x: leftInset, y: 0.0), size: CGSize(width: width - leftInset - rightInset, height: panelHeight))
let _ = self.panel.update(
transition: ComponentTransition(transition),
component: AnyComponent(GlassControlPanelComponent(
theme: interfaceState.theme,
leftItem: leftPanelItems.isEmpty ? nil : GlassControlPanelComponent.Item(
items: leftPanelItems,
background: .panel
),
centralItem: centerPanelItem,
rightItem: rightPanelItems.isEmpty ? nil : GlassControlPanelComponent.Item(
items: rightPanelItems,
background: .panel
)
)),
environment: {},
containerSize: panelFrame.size
)
if let panelView = self.panel.view {
if panelView.superview == nil {
self.panelContainer.addSubview(panelView)
}
transition.updateFrame(view: self.panelContainer, frame: panelFrame)
transition.updateFrame(view: panelView, frame: CGRect(origin: CGPoint(), size: panelFrame.size))
}
/*if self.presentationInterfaceState != interfaceState || force {
let previousState = self.presentationInterfaceState
self.presentationInterfaceState = interfaceState
@@ -504,7 +647,7 @@ public final class ChatChannelSubscriberInputPanelNode: ChatInputPanelNode {
transition.updateFrame(view: self.suggestedPostButtonIconView, frame: image.size.centered(in: CGRect(origin: CGPoint(), size: suggestedPostButtonFrame.size)))
}
transition.updateFrame(view: self.suggestedPostButton, frame: CGRect(origin: CGPoint(), size: suggestedPostButtonFrame.size))
self.suggestedPostButtonBackgroundView.update(size: suggestedPostButtonFrame.size, cornerRadius: suggestedPostButtonFrame.height * 0.5, isDark: interfaceState.theme.overallDarkAppearance, tintColor: .init(kind: .panel, color: interfaceState.theme.chat.inputPanel.inputBackgroundColor.withMultipliedAlpha(0.7)), isInteractive: true, transition: ComponentTransition(transition))
self.suggestedPostButtonBackgroundView.update(size: suggestedPostButtonFrame.size, cornerRadius: suggestedPostButtonFrame.height * 0.5, isDark: interfaceState.theme.overallDarkAppearance, tintColor: .init(kind: .panel, color: interfaceState.theme.chat.inputPanel.inputBackgroundColor.withMultipliedAlpha(0.7)), isInteractive: true, transition: ComponentTransition(transition))*/
return panelHeight
}