Skip to content

Commit c229c3c

Browse files
author
Isaac
committed
Stars ref
1 parent c49b242 commit c229c3c

File tree

11 files changed

+188
-91
lines changed

11 files changed

+188
-91
lines changed

submodules/StatisticsUI/Sources/ChannelStatsController.swift

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,8 @@ private func monetizationEntries(
15751575
premiumConfiguration: PremiumConfiguration,
15761576
monetizationConfiguration: MonetizationConfiguration,
15771577
canViewRevenue: Bool,
1578-
canViewStarsRevenue: Bool
1578+
canViewStarsRevenue: Bool,
1579+
canJoinRefPrograms: Bool
15791580
) -> [StatsEntry] {
15801581
var entries: [StatsEntry] = []
15811582

@@ -1700,8 +1701,10 @@ private func monetizationEntries(
17001701

17011702
if displayStarsTransactions {
17021703
if !addedTransactionsTabs {
1703-
//TODO:localize
1704-
entries.append(.earnStarsInfo)
1704+
if canJoinRefPrograms {
1705+
//TODO:localize
1706+
entries.append(.earnStarsInfo)
1707+
}
17051708

17061709
entries.append(.adsTransactionsTitle(presentationData.theme, presentationData.strings.Monetization_StarsTransactions.uppercased()))
17071710
}
@@ -1767,7 +1770,8 @@ private func channelStatsControllerEntries(
17671770
premiumConfiguration: PremiumConfiguration,
17681771
monetizationConfiguration: MonetizationConfiguration,
17691772
canViewRevenue: Bool,
1770-
canViewStarsRevenue: Bool
1773+
canViewStarsRevenue: Bool,
1774+
canJoinRefPrograms: Bool
17711775
) -> [StatsEntry] {
17721776
switch state.section {
17731777
case .stats:
@@ -1809,7 +1813,8 @@ private func channelStatsControllerEntries(
18091813
premiumConfiguration: premiumConfiguration,
18101814
monetizationConfiguration: monetizationConfiguration,
18111815
canViewRevenue: canViewRevenue,
1812-
canViewStarsRevenue: canViewStarsRevenue
1816+
canViewStarsRevenue: canViewStarsRevenue,
1817+
canJoinRefPrograms: canJoinRefPrograms
18131818
)
18141819
}
18151820
}
@@ -2157,6 +2162,15 @@ public func channelStatsController(
21572162
let (canViewStats, adsRestricted, _, canViewStarsRevenue) = peerData
21582163
var canViewRevenue = peerData.2
21592164

2165+
var canJoinRefPrograms = false
2166+
if let data = context.currentAppConfiguration.with({ $0 }).data, let value = data["starref_connect_allowed"] {
2167+
if let value = value as? Double {
2168+
canJoinRefPrograms = value != 0.0
2169+
} else if let value = value as? Bool {
2170+
canJoinRefPrograms = value
2171+
}
2172+
}
2173+
21602174
let _ = canViewStatsValue.swap(canViewStats)
21612175

21622176
var isGroup = false
@@ -2262,7 +2276,7 @@ public func channelStatsController(
22622276
}
22632277

22642278
let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: title, leftNavigationButton: leftNavigationButton, rightNavigationButton: nil, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back), animateChanges: true)
2265-
let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: channelStatsControllerEntries(presentationData: presentationData, state: state, peer: peer, data: data, messages: messages, stories: stories, interactions: interactions, boostData: boostData, boostersState: boostersState, giftsState: giftsState, giveawayAvailable: premiumConfiguration.giveawayGiftsPurchaseAvailable, isGroup: isGroup, boostsOnly: boostsOnly, revenueState: revenueState?.stats, revenueTransactions: revenueTransactions, starsState: starsState?.stats, starsTransactions: starsTransactions, adsRestricted: adsRestricted, premiumConfiguration: premiumConfiguration, monetizationConfiguration: monetizationConfiguration, canViewRevenue: canViewRevenue, canViewStarsRevenue: canViewStarsRevenue), style: .blocks, emptyStateItem: emptyStateItem, headerItem: headerItem, crossfadeState: previous == nil, animateChanges: false)
2279+
let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: channelStatsControllerEntries(presentationData: presentationData, state: state, peer: peer, data: data, messages: messages, stories: stories, interactions: interactions, boostData: boostData, boostersState: boostersState, giftsState: giftsState, giveawayAvailable: premiumConfiguration.giveawayGiftsPurchaseAvailable, isGroup: isGroup, boostsOnly: boostsOnly, revenueState: revenueState?.stats, revenueTransactions: revenueTransactions, starsState: starsState?.stats, starsTransactions: starsTransactions, adsRestricted: adsRestricted, premiumConfiguration: premiumConfiguration, monetizationConfiguration: monetizationConfiguration, canViewRevenue: canViewRevenue, canViewStarsRevenue: canViewStarsRevenue, canJoinRefPrograms: canJoinRefPrograms), style: .blocks, emptyStateItem: emptyStateItem, headerItem: headerItem, crossfadeState: previous == nil, animateChanges: false)
22662280

22672281
return (controllerState, (listState, arguments))
22682282
}

submodules/TelegramUI/Components/Chat/ChatMessageActionButtonsNode/Sources/ChatMessageActionButtonsNode.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ private final class ChatMessageActionButtonNode: ASDisplayNode {
180180
iconImage = incoming ? graphics.chatBubbleActionButtonIncomingMessageIconImage : graphics.chatBubbleActionButtonOutgoingMessageIconImage
181181
case let .url(value):
182182
var isApp = false
183-
if isTelegramMeLink(value), let internalUrl = parseFullInternalUrl(sharedContext: context.sharedContext, url: value) {
183+
if isTelegramMeLink(value), let internalUrl = parseFullInternalUrl(sharedContext: context.sharedContext, context: context, url: value) {
184184
if case .peer(_, .appStart) = internalUrl {
185185
isApp = true
186186
} else if case .peer(_, .attachBotStart) = internalUrl {

submodules/TelegramUI/Components/PeerInfo/AffiliateProgramSetupScreen/Sources/AffiliateProgramSetupScreen.swift

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ final class AffiliateProgramSetupScreenComponent: Component {
6565
return true
6666
}
6767

68+
private class ScrollView: UIScrollView {
69+
override func touchesShouldCancel(in view: UIView) -> Bool {
70+
return true
71+
}
72+
}
73+
6874
final class View: UIView, UIScrollViewDelegate {
6975
private let scrollView: UIScrollView
7076

@@ -119,7 +125,7 @@ final class AffiliateProgramSetupScreenComponent: Component {
119125
private var isSuggestedSortModeUpdating: Bool = false
120126

121127
override init(frame: CGRect) {
122-
self.scrollView = UIScrollView()
128+
self.scrollView = ScrollView()
123129
self.scrollView.showsVerticalScrollIndicator = true
124130
self.scrollView.showsHorizontalScrollIndicator = false
125131
self.scrollView.scrollsToTop = false
@@ -456,6 +462,20 @@ If you end your affiliate program:
456462
controller.presentInGlobalOverlay(contextController)
457463
}
458464

465+
private func openExistingAffiliatePrograms() {
466+
guard let component = self.component else {
467+
return
468+
}
469+
let _ = (component.context.sharedContext.makeAffiliateProgramSetupScreenInitialData(context: component.context, peerId: component.initialContent.peerId, mode: .connectedPrograms)
470+
|> deliverOnMainQueue).startStandalone(next: { [weak self] initialData in
471+
guard let self, let component = self.component else {
472+
return
473+
}
474+
let setupScreen = component.context.sharedContext.makeAffiliateProgramSetupScreen(context: component.context, initialData: initialData)
475+
self.environment?.controller()?.push(setupScreen)
476+
})
477+
}
478+
459479
func update(component: AffiliateProgramSetupScreenComponent, availableSize: CGSize, state: EmptyComponentState, environment: Environment<EnvironmentType>, transition: ComponentTransition) -> CGSize {
460480
self.isUpdating = true
461481
defer {
@@ -991,8 +1011,7 @@ If you end your affiliate program:
9911011
guard let self else {
9921012
return
9931013
}
994-
995-
let _ = self
1014+
self.openExistingAffiliatePrograms()
9961015
}
9971016
)))
9981017
],

submodules/TelegramUI/Components/PeerInfo/AffiliateProgramSetupScreen/Sources/JoinAffiliateProgramScreen.swift

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private final class JoinAffiliateProgramScreenComponent: Component {
9292

9393
private let linkIconBackground = ComponentView<Empty>()
9494
private let linkIcon = ComponentView<Empty>()
95-
private let linkIconBadge = ComponentView<Empty>()
95+
private var linkIconBadge: ComponentView<Empty>?
9696

9797
private let title = ComponentView<Empty>()
9898
private let subtitle = ComponentView<Empty>()
@@ -668,7 +668,17 @@ private final class JoinAffiliateProgramScreenComponent: Component {
668668
}
669669

670670
if active.bot.participants != 0 {
671-
let linkIconBadgeSize = self.linkIconBadge.update(
671+
let linkIconBadge: ComponentView<Empty>
672+
var linkIconBadgeTransition = transition
673+
if let current = self.linkIconBadge {
674+
linkIconBadge = current
675+
} else {
676+
linkIconBadgeTransition = linkIconBadgeTransition.withAnimation(.none)
677+
linkIconBadge = ComponentView()
678+
self.linkIconBadge = linkIconBadge
679+
}
680+
681+
let linkIconBadgeSize = linkIconBadge.update(
672682
transition: .immediate,
673683
component: AnyComponent(BorderedBadgeComponent(
674684
backgroundColor: UIColor(rgb: 0x34C759),
@@ -690,12 +700,15 @@ private final class JoinAffiliateProgramScreenComponent: Component {
690700
containerSize: CGSize(width: 100.0, height: 100.0)
691701
)
692702
let linkIconBadgeFrame = CGRect(origin: CGPoint(x: linkIconBackgroundFrame.minX + floor((linkIconBackgroundFrame.width - linkIconBadgeSize.width) * 0.5), y: linkIconBackgroundFrame.maxY - floor(linkIconBadgeSize.height * 0.5)), size: linkIconBadgeSize)
693-
if let linkIconBadgeView = self.linkIconBadge.view {
703+
if let linkIconBadgeView = linkIconBadge.view {
694704
if linkIconBadgeView.superview == nil {
695705
self.scrollContentView.addSubview(linkIconBadgeView)
696706
}
697-
transition.setFrame(view: linkIconBadgeView, frame: linkIconBadgeFrame)
707+
linkIconBadgeTransition.setFrame(view: linkIconBadgeView, frame: linkIconBadgeFrame)
698708
}
709+
} else if let linkIconBadge = self.linkIconBadge {
710+
self.linkIconBadge = nil
711+
linkIconBadge.view?.removeFromSuperview()
699712
}
700713

701714
contentHeight += linkIconBackgroundSize.height + 21.0
@@ -895,6 +908,7 @@ private final class JoinAffiliateProgramScreenComponent: Component {
895908
self.scrollContentView.addSubview(linkTextView)
896909
}
897910
transition.setFrame(view: linkTextView, frame: linkTextFrame)
911+
transition.setAlpha(view: linkTextView, alpha: self.isChangingTargetPeer ? 0.6 : 1.0)
898912
}
899913
contentHeight += linkTextSize.height
900914
contentHeight += 24.0

submodules/TelegramUI/Components/PeerInfo/PeerInfoScreen/Sources/PeerInfoScreen.swift

Lines changed: 58 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,17 +1430,28 @@ private func infoItems(data: PeerInfoScreenData?, context: AccountContext, prese
14301430
if let botInfo = user.botInfo, botInfo.flags.contains(.canEdit) {
14311431
} else {
14321432
if let starRefProgram = cachedData.starRefProgram, starRefProgram.endDate == nil {
1433-
if items[.botAffiliateProgram] == nil {
1434-
items[.botAffiliateProgram] = []
1435-
}
1436-
//TODO:localize
1437-
let programTitleValue: String
1438-
programTitleValue = "\(starRefProgram.commissionPermille / 10)%"
1439-
//TODO:localize
1440-
items[.botAffiliateProgram]!.append(PeerInfoScreenDisclosureItem(id: 0, label: .labelBadge(programTitleValue), additionalBadgeLabel: nil, text: "Affiliate Program", icon: PresentationResourcesSettings.affiliateProgram, action: {
1441-
interaction.editingOpenAffiliateProgram()
1442-
}))
1443-
items[.botAffiliateProgram]!.append(PeerInfoScreenCommentItem(id: 1, text: "Share a link to \(EnginePeer.user(user).compactDisplayTitle) with your friends and and earn \(starRefProgram.commissionPermille / 10)% of their spending there."))
1433+
var canJoinRefProgram = false
1434+
if let data = context.currentAppConfiguration.with({ $0 }).data, let value = data["starref_connect_allowed"] {
1435+
if let value = value as? Double {
1436+
canJoinRefProgram = value != 0.0
1437+
} else if let value = value as? Bool {
1438+
canJoinRefProgram = value
1439+
}
1440+
}
1441+
1442+
if canJoinRefProgram {
1443+
if items[.botAffiliateProgram] == nil {
1444+
items[.botAffiliateProgram] = []
1445+
}
1446+
//TODO:localize
1447+
let programTitleValue: String
1448+
programTitleValue = "\(starRefProgram.commissionPermille / 10)%"
1449+
//TODO:localize
1450+
items[.botAffiliateProgram]!.append(PeerInfoScreenDisclosureItem(id: 0, label: .labelBadge(programTitleValue), additionalBadgeLabel: nil, text: "Affiliate Program", icon: PresentationResourcesSettings.affiliateProgram, action: {
1451+
interaction.editingOpenAffiliateProgram()
1452+
}))
1453+
items[.botAffiliateProgram]!.append(PeerInfoScreenCommentItem(id: 1, text: "Share a link to \(EnginePeer.user(user).compactDisplayTitle) with your friends and and earn \(starRefProgram.commissionPermille / 10)% of their spending there."))
1454+
}
14441455
}
14451456
}
14461457
}
@@ -1938,16 +1949,28 @@ private func editingItems(data: PeerInfoScreenData?, state: PeerInfoState, chatL
19381949
items[.peerDataSettings]!.append(PeerInfoScreenDisclosureItem(id: ItemUsername, label: .text("@\(user.addressName ?? "")"), text: presentationData.strings.PeerInfo_Bot_Username, icon: PresentationResourcesSettings.bot, action: {
19391950
interaction.editingOpenPublicLinkSetup()
19401951
}))
1941-
//TODO:localize
1942-
let programTitleValue: PeerInfoScreenDisclosureItem.Label
1943-
if let cachedData = data.cachedData as? CachedUserData, let starRefProgram = cachedData.starRefProgram, starRefProgram.endDate == nil {
1944-
programTitleValue = .labelBadge("\(starRefProgram.commissionPermille / 10)%")
1945-
} else {
1946-
programTitleValue = .text("Off")
1952+
1953+
var canSetupRefProgram = false
1954+
if let data = context.currentAppConfiguration.with({ $0 }).data, let value = data["starref_program_allowed"] {
1955+
if let value = value as? Double {
1956+
canSetupRefProgram = value != 0.0
1957+
} else if let value = value as? Bool {
1958+
canSetupRefProgram = value
1959+
}
1960+
}
1961+
1962+
if canSetupRefProgram {
1963+
//TODO:localize
1964+
let programTitleValue: PeerInfoScreenDisclosureItem.Label
1965+
if let cachedData = data.cachedData as? CachedUserData, let starRefProgram = cachedData.starRefProgram, starRefProgram.endDate == nil {
1966+
programTitleValue = .labelBadge("\(starRefProgram.commissionPermille / 10)%")
1967+
} else {
1968+
programTitleValue = .text("Off")
1969+
}
1970+
items[.peerDataSettings]!.append(PeerInfoScreenDisclosureItem(id: ItemAffiliateProgram, label: programTitleValue, additionalBadgeLabel: presentationData.strings.Settings_New, text: "Affiliate Program", icon: PresentationResourcesSettings.affiliateProgram, action: {
1971+
interaction.editingOpenAffiliateProgram()
1972+
}))
19471973
}
1948-
items[.peerDataSettings]!.append(PeerInfoScreenDisclosureItem(id: ItemAffiliateProgram, label: programTitleValue, additionalBadgeLabel: presentationData.strings.Settings_New, text: "Affiliate Program", icon: PresentationResourcesSettings.affiliateProgram, action: {
1949-
interaction.editingOpenAffiliateProgram()
1950-
}))
19511974

19521975
items[.peerSettings]!.append(PeerInfoScreenActionItem(id: ItemIntro, text: presentationData.strings.PeerInfo_Bot_EditIntro, icon: UIImage(bundleImageName: "Peer Info/BotIntro"), action: {
19531976
interaction.openPeerMention("botfather", .withBotStartPayload(ChatControllerInitialBotStart(payload: "\(user.addressName ?? "")-intro", behavior: .interactive)))
@@ -2199,9 +2222,20 @@ private func editingItems(data: PeerInfoScreenData?, state: PeerInfoState, chatL
21992222
}
22002223

22012224
if channel.hasPermission(.changeInfo) {
2202-
items[.peerAdditionalSettings]!.append(PeerInfoScreenDisclosureItem(id: ItemAffiliatePrograms, label: .text(""), additionalBadgeLabel: presentationData.strings.Settings_New, text: "Affiliate Programs", icon: PresentationResourcesSettings.affiliateProgram, action: {
2203-
interaction.editingOpenAffiliateProgram()
2204-
}))
2225+
var canJoinRefProgram = false
2226+
if let data = context.currentAppConfiguration.with({ $0 }).data, let value = data["starref_connect_allowed"] {
2227+
if let value = value as? Double {
2228+
canJoinRefProgram = value != 0.0
2229+
} else if let value = value as? Bool {
2230+
canJoinRefProgram = value
2231+
}
2232+
}
2233+
2234+
if canJoinRefProgram {
2235+
items[.peerAdditionalSettings]!.append(PeerInfoScreenDisclosureItem(id: ItemAffiliatePrograms, label: .text(""), additionalBadgeLabel: presentationData.strings.Settings_New, text: "Affiliate Programs", icon: PresentationResourcesSettings.affiliateProgram, action: {
2236+
interaction.editingOpenAffiliateProgram()
2237+
}))
2238+
}
22052239
}
22062240

22072241
if isCreator { //if let cachedData = data.cachedData as? CachedChannelData, cachedData.flags.contains(.canDeleteHistory) {
@@ -8596,7 +8630,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
85968630
if let peer = self.data?.peer as? TelegramUser, let botInfo = peer.botInfo {
85978631
if botInfo.flags.contains(.canEdit) {
85988632
let _ = (self.context.sharedContext.makeAffiliateProgramSetupScreenInitialData(context: self.context, peerId: peer.id, mode: .editProgram)
8599-
|> deliverOnMainQueue).startStandalone(next: { [weak self] initialData in
8633+
|> deliverOnMainQueue).startStandalone(next: { [weak self] initialData in
86008634
guard let self else {
86018635
return
86028636
}

0 commit comments

Comments
 (0)