Skip to content

Commit

Permalink
Various improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
laktyushin committed Aug 11, 2024
1 parent 83c7fdd commit fc6b6b7
Show file tree
Hide file tree
Showing 19 changed files with 136 additions and 47 deletions.
9 changes: 9 additions & 0 deletions Telegram/Telegram-iOS/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -12768,3 +12768,12 @@ Sorry for the inconvenience.";
"InviteLink.Create.RequestApprovalFeeUnavailable" = "You can't enable admin approval for links that require a monthly fee.";

"WebApp.PrivacyPolicy_URL" = "https://telegram.org/privacy-tpa";

"ChatList.SubscriptionsLowBalance.Stars_1" = "%@ Star needed";
"ChatList.SubscriptionsLowBalance.Stars_any" = "%@ Stars needed";

"ChatList.SubscriptionsLowBalance.Single.Title" = "%1$@ for %@$@";
"ChatList.SubscriptionsLowBalance.Single.Text" = "Insufficient funds to cover your subscription.";

"ChatList.SubscriptionsLowBalance.Multiple.Title" = "%@ for your subscriptions";
"ChatList.SubscriptionsLowBalance.Multiple.Text" = "Insufficient funds to cover your subscriptions.";
18 changes: 17 additions & 1 deletion submodules/ChatListUI/Sources/ChatListControllerNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,28 @@ public final class ChatListContainerNode: ASDisplayNode, ASGestureRecognizerDele
var openBirthdaySetup: (() -> Void)?
var openPremiumManagement: (() -> Void)?
var openStories: ((ChatListNode.OpenStoriesSubject, ASDisplayNode?) -> Void)?
var openStarsTopup: ((Int64?) -> Void)?
var addedVisibleChatsWithPeerIds: (([EnginePeer.Id]) -> Void)?
var didBeginSelectingChats: (() -> Void)?
var canExpandHiddenItems: (() -> Bool)?
public var displayFilterLimit: (() -> Void)?

public init(context: AccountContext, controller: ChatListControllerImpl?, location: ChatListControllerLocation, chatListMode: ChatListNodeMode = .chatList(appendContacts: true), previewing: Bool, controlsHistoryPreload: Bool, isInlineMode: Bool, presentationData: PresentationData, animationCache: AnimationCache, animationRenderer: MultiAnimationRenderer, filterBecameEmpty: @escaping (ChatListFilter?) -> Void, filterEmptyAction: @escaping (ChatListFilter?) -> Void, secondaryEmptyAction: @escaping () -> Void, openArchiveSettings: @escaping () -> Void) {
public init(
context: AccountContext,
controller: ChatListControllerImpl?,
location: ChatListControllerLocation,
chatListMode: ChatListNodeMode = .chatList(appendContacts: true),
previewing: Bool,
controlsHistoryPreload: Bool,
isInlineMode: Bool,
presentationData: PresentationData,
animationCache: AnimationCache,
animationRenderer: MultiAnimationRenderer,
filterBecameEmpty: @escaping (ChatListFilter?) -> Void,
filterEmptyAction: @escaping (ChatListFilter?) -> Void,
secondaryEmptyAction: @escaping () -> Void,
openArchiveSettings: @escaping () -> Void)
{
self.context = context
self.controller = controller
self.location = location
Expand Down
12 changes: 2 additions & 10 deletions submodules/ChatListUI/Sources/ChatListSearchListPaneNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2825,6 +2825,7 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
if let sourceNode = sourceNode as? ChatListItemNode {
self.interaction.openStories?(id, sourceNode.avatarNode)
}
}, openStarsTopup: { _ in
}, dismissNotice: { _ in
}, editPeer: { _ in
})
Expand Down Expand Up @@ -3658,19 +3659,9 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
} else if case .apps = key {
if let navigationController = self.navigationController {
if isRecommended {
#if DEBUG
let _ = (self.context.sharedContext.makeMiniAppListScreenInitialData(context: self.context)
|> deliverOnMainQueue).startStandalone(next: { [weak self] initialData in
guard let self, let navigationController = self.navigationController else {
return
}
navigationController.pushViewController(self.context.sharedContext.makeMiniAppListScreen(context: self.context, initialData: initialData))
})
#else
if let peerInfoScreen = self.context.sharedContext.makePeerInfoController(context: self.context, updatedPresentationData: nil, peer: peer._asPeer(), mode: .generic, avatarInitiallyExpanded: false, fromChat: false, requestsContext: nil) {
navigationController.pushViewController(peerInfoScreen)
}
#endif
} else if case let .user(user) = peer, let botInfo = user.botInfo, botInfo.flags.contains(.hasWebApp), let parentController = self.parentController {
self.context.sharedContext.openWebApp(
context: self.context,
Expand Down Expand Up @@ -4659,6 +4650,7 @@ public final class ChatListSearchShimmerNode: ASDisplayNode {
}, performActiveSessionAction: { _, _ in
}, openChatFolderUpdates: {}, hideChatFolderUpdates: {
}, openStories: { _, _ in
}, openStarsTopup: { _ in
}, dismissNotice: { _ in
}, editPeer: { _ in
})
Expand Down
3 changes: 2 additions & 1 deletion submodules/ChatListUI/Sources/ChatListShimmerNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ public final class ChatListShimmerNode: ASDisplayNode {
let interaction = ChatListNodeInteraction(context: context, animationCache: animationCache, animationRenderer: animationRenderer, activateSearch: {}, peerSelected: { _, _, _, _ in }, disabledPeerSelected: { _, _, _ in }, togglePeerSelected: { _, _ in }, togglePeersSelection: { _, _ in }, additionalCategorySelected: { _ in
}, messageSelected: { _, _, _, _ in}, groupSelected: { _ in }, addContact: { _ in }, setPeerIdWithRevealedOptions: { _, _ in }, setItemPinned: { _, _ in }, setPeerMuted: { _, _ in }, setPeerThreadMuted: { _, _, _ in }, deletePeer: { _, _ in }, deletePeerThread: { _, _ in }, setPeerThreadStopped: { _, _, _ in }, setPeerThreadPinned: { _, _, _ in }, setPeerThreadHidden: { _, _, _ in }, updatePeerGrouping: { _, _ in }, togglePeerMarkedUnread: { _, _ in}, toggleArchivedFolderHiddenByDefault: {}, toggleThreadsSelection: { _, _ in }, hidePsa: { _ in }, activateChatPreview: { _, _, _, gesture, _ in
gesture?.cancel()
}, present: { _ in }, openForumThread: { _, _ in }, openStorageManagement: {}, openPasswordSetup: {}, openPremiumIntro: {}, openPremiumGift: { _ in }, openPremiumManagement: {}, openActiveSessions: {}, openBirthdaySetup: {}, performActiveSessionAction: { _, _ in }, openChatFolderUpdates: {}, hideChatFolderUpdates: {}, openStories: { _, _ in }, dismissNotice: { _ in
}, present: { _ in }, openForumThread: { _, _ in }, openStorageManagement: {}, openPasswordSetup: {}, openPremiumIntro: {}, openPremiumGift: { _ in }, openPremiumManagement: {}, openActiveSessions: {}, openBirthdaySetup: {}, performActiveSessionAction: { _, _ in }, openChatFolderUpdates: {}, hideChatFolderUpdates: {}, openStories: { _, _ in }, openStarsTopup: { _ in
}, dismissNotice: { _ in
}, editPeer: { _ in
})
interaction.isInlineMode = isInlineMode
Expand Down
43 changes: 36 additions & 7 deletions submodules/ChatListUI/Sources/Node/ChatListNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public final class ChatListNodeInteraction {
let openChatFolderUpdates: () -> Void
let hideChatFolderUpdates: () -> Void
let openStories: (ChatListNode.OpenStoriesSubject, ASDisplayNode?) -> Void
let openStarsTopup: (Int64?) -> Void
let dismissNotice: (ChatListNotice) -> Void
let editPeer: (ChatListItem) -> Void

Expand Down Expand Up @@ -164,6 +165,7 @@ public final class ChatListNodeInteraction {
openChatFolderUpdates: @escaping () -> Void,
hideChatFolderUpdates: @escaping () -> Void,
openStories: @escaping (ChatListNode.OpenStoriesSubject, ASDisplayNode?) -> Void,
openStarsTopup: @escaping (Int64?) -> Void,
dismissNotice: @escaping (ChatListNotice) -> Void,
editPeer: @escaping (ChatListItem) -> Void
) {
Expand Down Expand Up @@ -206,6 +208,7 @@ public final class ChatListNodeInteraction {
self.openChatFolderUpdates = openChatFolderUpdates
self.hideChatFolderUpdates = hideChatFolderUpdates
self.openStories = openStories
self.openStarsTopup = openStarsTopup
self.dismissNotice = dismissNotice
self.editPeer = editPeer
}
Expand Down Expand Up @@ -747,8 +750,8 @@ private func mappedInsertEntries(context: AccountContext, nodeInteraction: ChatL
nodeInteraction?.openPremiumGift(birthdays)
case .reviewLogin:
break
case .starsSubscriptionLowBalance:
break
case let .starsSubscriptionLowBalance(amount, _):
nodeInteraction?.openStarsTopup(amount)
}
case .hide:
nodeInteraction?.dismissNotice(notice)
Expand Down Expand Up @@ -1087,8 +1090,8 @@ private func mappedUpdateEntries(context: AccountContext, nodeInteraction: ChatL
nodeInteraction?.openPremiumGift(birthdays)
case .reviewLogin:
break
case .starsSubscriptionLowBalance:
break
case let .starsSubscriptionLowBalance(amount, _):
nodeInteraction?.openStarsTopup(amount)
}
case .hide:
nodeInteraction?.dismissNotice(notice)
Expand Down Expand Up @@ -1208,6 +1211,7 @@ public final class ChatListNode: ListView {
public var openStories: ((ChatListNode.OpenStoriesSubject, ASDisplayNode?) -> Void)?
public var openBirthdaySetup: (() -> Void)?
public var openPremiumManagement: (() -> Void)?
public var openStarsTopup: ((Int64?) -> Void)?

private var theme: PresentationTheme

Expand Down Expand Up @@ -1809,6 +1813,11 @@ public final class ChatListNode: ListView {
return
}
self.openStories?(subject, itemNode)
}, openStarsTopup: { [weak self] amount in
guard let self else {
return
}
self.openStarsTopup?(amount)
}, dismissNotice: { [weak self] notice in
guard let self else {
return
Expand Down Expand Up @@ -1910,6 +1919,8 @@ public final class ChatListNode: ListView {
} else {
displayArchiveIntro = .single(false)
}

let starsSubscriptionsContextPromise = Promise<StarsSubscriptionsContext?>(nil)

self.updateIsMainTabDisposable = (self.isMainTab.get()
|> deliverOnMainQueue).startStrict(next: { [weak self] isMainTab in
Expand All @@ -1932,9 +1943,10 @@ public final class ChatListNode: ListView {
twoStepData,
newSessionReviews(postbox: context.account.postbox),
context.engine.data.subscribe(TelegramEngine.EngineData.Item.Peer.Birthday(id: context.account.peerId)),
context.account.stateManager.contactBirthdays
context.account.stateManager.contactBirthdays,
starsSubscriptionsContextPromise.get()
)
|> mapToSignal { suggestions, dismissedSuggestions, configuration, newSessionReviews, birthday, birthdays -> Signal<ChatListNotice?, NoError> in
|> mapToSignal { suggestions, dismissedSuggestions, configuration, newSessionReviews, birthday, birthdays, starsSubscriptionsContext -> Signal<ChatListNotice?, NoError> in
if let newSessionReview = newSessionReviews.first {
return .single(.reviewLogin(newSessionReview: newSessionReview, totalCount: newSessionReviews.count))
}
Expand Down Expand Up @@ -1968,7 +1980,24 @@ public final class ChatListNode: ListView {
todayBirthdayPeerIds = []
}

if suggestions.contains(.gracePremium) {
if suggestions.contains(.starsSubscriptionLowBalance) {
if let starsSubscriptionsContext {
return starsSubscriptionsContext.state
|> map { state in
if state.balance > 0 {
return .starsSubscriptionLowBalance(
amount: state.balance,
peers: state.subscriptions.map { $0.peer }
)
} else {
return nil
}
}
} else {
starsSubscriptionsContextPromise.set(.single(context.engine.payments.peerStarsSubscriptionsContext(starsContext: nil, missingBalance: true)))
return .single(nil)
}
} else if suggestions.contains(.gracePremium) {
return .single(.premiumGrace)
} else if suggestions.contains(.setupBirthday) && birthday == nil {
return .single(.setupBirthday)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public enum ChatListNotice: Equatable {
case birthdayPremiumGift(peers: [EnginePeer], birthdays: [EnginePeer.Id: TelegramBirthday])
case reviewLogin(newSessionReview: NewSessionReview, totalCount: Int)
case premiumGrace
case starsSubscriptionLowBalance(amount: Int64)
case starsSubscriptionLowBalance(amount: Int64, peers: [EnginePeer])
}

enum ChatListNodeEntry: Comparable, Identifiable {
Expand Down
Loading

0 comments on commit fc6b6b7

Please sign in to comment.