Various improvements [skip ci]

This commit is contained in:
Ilya Laktyushin
2025-02-12 22:15:02 +04:00
parent 8c523ec741
commit 2f2a27f0d2
130 changed files with 5126 additions and 1700 deletions

View File

@@ -1212,10 +1212,13 @@ public final class ChatEmptyNodePremiumRequiredChatContent: ASDisplayNode, ChatE
private var currentTheme: PresentationTheme?
private var currentStrings: PresentationStrings?
public init(context: AccountContext, interaction: ChatPanelInterfaceInteraction?) {
private let stars: StarsAmount?
public init(context: AccountContext, interaction: ChatPanelInterfaceInteraction?, stars: StarsAmount?) {
let premiumConfiguration = PremiumConfiguration.with(appConfiguration: context.currentAppConfiguration.with { $0 })
self.isPremiumDisabled = premiumConfiguration.isPremiumDisabled
self.stars = stars
self.interaction = interaction
@@ -1254,7 +1257,11 @@ public final class ChatEmptyNodePremiumRequiredChatContent: ASDisplayNode, ChatE
@objc private func buttonPressed() {
if let interaction = self.interaction {
interaction.openPremiumRequiredForMessaging()
if let _ = self.stars {
interaction.openStarsPurchase(nil)
} else {
interaction.openPremiumRequiredForMessaging()
}
}
}
@@ -1277,23 +1284,46 @@ public final class ChatEmptyNodePremiumRequiredChatContent: ASDisplayNode, ChatE
peerTitle = " "
}
let text: String
if self.isPremiumDisabled {
text = interfaceState.strings.Chat_EmptyStateMessagingRestrictedToPremiumDisabled_Text(peerTitle).string
let text: NSAttributedString
let actionText: String
let attributes = MarkdownAttributes(
body: MarkdownAttributeSet(font: Font.regular(15.0), textColor: serviceColor.primaryText),
bold: MarkdownAttributeSet(font: Font.semibold(15.0), textColor: serviceColor.primaryText),
link: MarkdownAttributeSet(font: Font.regular(15.0), textColor: serviceColor.primaryText),
linkAttribute: { url in
return ("URL", url)
}
)
if let amount = self.stars {
let starsString = presentationStringsFormattedNumber(Int32(amount.value), interfaceState.dateTimeFormat.groupingSeparator)
let rawText: String
if self.isPremiumDisabled {
rawText = interfaceState.strings.Chat_EmptyStatePaidMessagingDisabled_Text(peerTitle, " $ \(starsString)").string
} else {
rawText = interfaceState.strings.Chat_EmptyStatePaidMessaging_Text(peerTitle, " $ \(starsString)").string
}
let attributedString = parseMarkdownIntoAttributedString(rawText, attributes: attributes).mutableCopy() as! NSMutableAttributedString
if let range = attributedString.string.range(of: "$") {
attributedString.addAttribute(.attachment, value: PresentationResourcesChat.chatEmptyStateStarIcon(interfaceState.theme)!, range: NSRange(range, in: attributedString.string))
attributedString.addAttribute(.foregroundColor, value: serviceColor.primaryText, range: NSRange(range, in: attributedString.string))
attributedString.addAttribute(.baselineOffset, value: 2.0, range: NSRange(range, in: attributedString.string))
}
text = attributedString
actionText = interfaceState.strings.Chat_EmptyStatePaidMessaging_Action
} else {
text = interfaceState.strings.Chat_EmptyStateMessagingRestrictedToPremium_Text(peerTitle).string
let rawText: String
if self.isPremiumDisabled {
rawText = interfaceState.strings.Chat_EmptyStateMessagingRestrictedToPremiumDisabled_Text(peerTitle).string
} else {
rawText = interfaceState.strings.Chat_EmptyStateMessagingRestrictedToPremium_Text(peerTitle).string
}
text = parseMarkdownIntoAttributedString(rawText, attributes: attributes)
actionText = interfaceState.strings.Chat_EmptyStateMessagingRestrictedToPremium_Action
}
let textSize = self.text.update(
transition: .immediate,
component: AnyComponent(BalancedTextComponent(
text: .markdown(text: text, attributes: MarkdownAttributes(
body: MarkdownAttributeSet(font: Font.regular(15.0), textColor: serviceColor.primaryText),
bold: MarkdownAttributeSet(font: Font.semibold(15.0), textColor: serviceColor.primaryText),
link: MarkdownAttributeSet(font: Font.regular(15.0), textColor: serviceColor.primaryText),
linkAttribute: { url in
return ("URL", url)
}
)),
text: .plain(text),
horizontalAlignment: .center,
maximumNumberOfLines: 0
)),
@@ -1304,7 +1334,7 @@ public final class ChatEmptyNodePremiumRequiredChatContent: ASDisplayNode, ChatE
let buttonTitleSize = self.buttonTitle.update(
transition: .immediate,
component: AnyComponent(MultilineTextComponent(
text: .plain(NSAttributedString(string: interfaceState.strings.Chat_EmptyStateMessagingRestrictedToPremium_Action, font: Font.semibold(15.0), textColor: serviceColor.primaryText))
text: .plain(NSAttributedString(string: actionText, font: Font.semibold(15.0), textColor: serviceColor.primaryText))
)),
environment: {},
containerSize: CGSize(width: 200.0, height: 100.0)
@@ -1396,6 +1426,7 @@ private enum ChatEmptyNodeContentType: Equatable {
case greeting
case topic
case premiumRequired
case starsRequired
}
private final class EmptyAttachedDescriptionNode: HighlightTrackingButtonNode {
@@ -1784,7 +1815,9 @@ public final class ChatEmptyNode: ASDisplayNode {
} else if let _ = interfaceState.peerNearbyData {
contentType = .peerNearby
} else if let peer = peer as? TelegramUser {
if interfaceState.isPremiumRequiredForMessaging {
if let _ = interfaceState.sendPaidMessageStars {
contentType = .starsRequired
} else if interfaceState.isPremiumRequiredForMessaging {
contentType = .premiumRequired
} else {
if peer.isDeleted || peer.botInfo != nil || peer.flags.contains(.isSupport) || peer.isScam || interfaceState.peerIsBlocked {
@@ -1847,7 +1880,9 @@ public final class ChatEmptyNode: ASDisplayNode {
case .topic:
node = ChatEmptyNodeTopicChatContent(context: self.context)
case .premiumRequired:
node = ChatEmptyNodePremiumRequiredChatContent(context: self.context, interaction: self.interaction)
node = ChatEmptyNodePremiumRequiredChatContent(context: self.context, interaction: self.interaction, stars: nil)
case .starsRequired:
node = ChatEmptyNodePremiumRequiredChatContent(context: self.context, interaction: self.interaction, stars: interfaceState.sendPaidMessageStars)
}
self.content = (contentType, node)
self.addSubnode(node)