Merge commit '0c091f6c1b8d1ced7e95e4c53b5525bf62aa0557'

# Conflicts:
#	submodules/ContactListUI/Sources/ContactsControllerNode.swift
#	submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift
This commit is contained in:
Ali
2023-06-23 18:15:23 +03:00
13 changed files with 676 additions and 130 deletions

View File

@@ -159,6 +159,9 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
private var clearUnseenDownloadsTimer: SwiftSignalKit.Timer?
private(set) var isPremium: Bool = false
private(set) var storyPostingAvailability: StoriesConfiguration.PostingAvailability = .disabled
private var storiesPostingAvailabilityDisposable: Disposable?
private let storyPostingAvailabilityValue = ValuePromise<StoriesConfiguration.PostingAvailability>(.disabled)
private var didSetupTabs = false
@@ -245,7 +248,15 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
parentController: self,
hideNetworkActivityStatus: self.hideNetworkActivityStatus,
containerNode: self.chatListDisplayNode.mainContainerNode,
isReorderingTabs: self.isReorderingTabsValue.get()
isReorderingTabs: self.isReorderingTabsValue.get(),
storyPostingAvailable: self.storyPostingAvailabilityValue.get() |> map { availability -> Bool in
switch availability {
case .enabled, .premium:
return true
default:
return false
}
}
)
self.primaryContext = primaryContext
self.primaryInfoReady.set(primaryContext.ready.get())
@@ -697,6 +708,24 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
self.reloadFilters()
}
self.storiesPostingAvailabilityDisposable = (self.context.account.postbox.preferencesView(keys: [PreferencesKeys.appConfiguration])
|> map { view -> AppConfiguration in
let appConfiguration: AppConfiguration = view.values[PreferencesKeys.appConfiguration]?.get(AppConfiguration.self) ?? AppConfiguration.defaultValue
return appConfiguration
}
|> distinctUntilChanged
|> map { appConfiguration -> StoriesConfiguration.PostingAvailability in
let storiesConfiguration = StoriesConfiguration.with(appConfiguration: appConfiguration)
return storiesConfiguration.posting
}
|> deliverOnMainQueue
).start(next: { [weak self] postingAvailability in
if let self {
self.storyPostingAvailability = postingAvailability
self.storyPostingAvailabilityValue.set(postingAvailability)
}
})
self.updateNavigationMetadata()
}
@@ -725,6 +754,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
self.storySubscriptionsDisposable?.dispose()
self.preloadStorySubscriptionsDisposable?.dispose()
self.storyProgressDisposable?.dispose()
self.storiesPostingAvailabilityDisposable?.dispose()
}
private func updateNavigationMetadata() {
@@ -2341,19 +2371,27 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
}
fileprivate func openStoryCamera() {
guard self.isPremium else {
let context = self.context
var replaceImpl: ((ViewController) -> Void)?
let controller = context.sharedContext.makePremiumDemoController(context: self.context, subject: .stories, action: {
let controller = context.sharedContext.makePremiumIntroController(context: context, source: .stories)
replaceImpl?(controller)
})
replaceImpl = { [weak controller] c in
controller?.replace(with: c)
switch self.storyPostingAvailability {
case .premium:
guard self.isPremium else {
let context = self.context
var replaceImpl: ((ViewController) -> Void)?
let controller = context.sharedContext.makePremiumDemoController(context: self.context, subject: .stories, action: {
let controller = context.sharedContext.makePremiumIntroController(context: context, source: .stories)
replaceImpl?(controller)
})
replaceImpl = { [weak controller] c in
controller?.replace(with: c)
}
self.push(controller)
return
}
self.push(controller)
case .disabled:
return
default:
break
}
var cameraTransitionIn: StoryCameraTransitionIn?
if let componentView = self.chatListHeaderView() {
if let (transitionView, _) = componentView.storyPeerListView()?.transitionViewForItem(peerId: self.context.account.peerId) {
@@ -2780,7 +2818,8 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
parentController: self,
hideNetworkActivityStatus: false,
containerNode: inlineNode,
isReorderingTabs: .single(false)
isReorderingTabs: .single(false),
storyPostingAvailable: .single(false)
)
self.pendingSecondaryContext = pendingSecondaryContext
let _ = (pendingSecondaryContext.ready.get()
@@ -4770,7 +4809,6 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
let (accountPeer, limits, _) = result
let isPremium = accountPeer?.isPremium ?? false
let _ = strongSelf.context.engine.peers.markChatListFeaturedFiltersAsSeen().start()
let (_, filterItems) = filterItemsAndTotalCount
@@ -4923,6 +4961,17 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
self.storyCameraTransitionInCoordinator = nil
}
}
var isStoryPostingAvailable: Bool {
switch self.storyPostingAvailability {
case .enabled:
return true
case .premium:
return self.isPremium
case .disabled:
return false
}
}
}
private final class ChatListTabBarContextExtractedContentSource: ContextExtractedContentSource {
@@ -5047,7 +5096,8 @@ private final class ChatListLocationContext {
parentController: ChatListControllerImpl,
hideNetworkActivityStatus: Bool,
containerNode: ChatListContainerNode,
isReorderingTabs: Signal<Bool, NoError>
isReorderingTabs: Signal<Bool, NoError>,
storyPostingAvailable: Signal<Bool, NoError>
) {
self.context = context
self.location = location
@@ -5102,8 +5152,9 @@ private final class ChatListLocationContext {
containerNode.currentItemState,
isReorderingTabs,
peerStatus,
parentController.updatedPresentationData.1
).start(next: { [weak self] networkState, proxy, passcode, stateAndFilterId, isReorderingTabs, peerStatus, presentationData in
parentController.updatedPresentationData.1,
storyPostingAvailable
).start(next: { [weak self] networkState, proxy, passcode, stateAndFilterId, isReorderingTabs, peerStatus, presentationData, storyPostingAvailable in
guard let self else {
return
}
@@ -5114,7 +5165,8 @@ private final class ChatListLocationContext {
stateAndFilterId: stateAndFilterId,
isReorderingTabs: isReorderingTabs,
peerStatus: peerStatus,
presentationData: presentationData
presentationData: presentationData,
storyPostingAvailable: storyPostingAvailable
)
})
} else {
@@ -5324,7 +5376,8 @@ private final class ChatListLocationContext {
stateAndFilterId: (state: ChatListNodeState, filterId: Int32?),
isReorderingTabs: Bool,
peerStatus: NetworkStatusTitle.Status?,
presentationData: PresentationData
presentationData: PresentationData,
storyPostingAvailable: Bool
) {
let defaultTitle: String
switch location {
@@ -5431,15 +5484,19 @@ private final class ChatListLocationContext {
}
}
self.storyButton = AnyComponentWithIdentity(id: "story", component: AnyComponent(NavigationButtonComponent(
content: .icon(imageName: "Chat List/AddStoryIcon"),
pressed: { [weak self] _ in
guard let self, let parentController = self.parentController else {
return
if storyPostingAvailable {
self.storyButton = AnyComponentWithIdentity(id: "story", component: AnyComponent(NavigationButtonComponent(
content: .icon(imageName: "Chat List/AddStoryIcon"),
pressed: { [weak self] _ in
guard let self, let parentController = self.parentController else {
return
}
parentController.openStoryCamera()
}
parentController.openStoryCamera()
}
)))
)))
} else {
self.storyButton = nil
}
} else {
self.rightButton = AnyComponentWithIdentity(id: "edit", component: AnyComponent(NavigationButtonComponent(
content: .text(title: presentationData.strings.Common_Edit, isBold: false),