From 0e3fbeb08b62e48542434984f70d81107014a3b8 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Thu, 30 Mar 2023 18:15:46 +0400 Subject: [PATCH] Folder improvements --- .../Sources/ChatListController.swift | 92 +++++++++++-------- .../ChatListFilterPresetListController.swift | 68 ++++++++------ .../Sources/SolidRoundedButtonNode.swift | 13 +++ .../TelegramEngine/Peers/Communities.swift | 4 + 4 files changed, 113 insertions(+), 64 deletions(-) diff --git a/submodules/ChatListUI/Sources/ChatListController.swift b/submodules/ChatListUI/Sources/ChatListController.swift index 9c20cd9993..94fc682352 100644 --- a/submodules/ChatListUI/Sources/ChatListController.swift +++ b/submodules/ChatListUI/Sources/ChatListController.swift @@ -2751,53 +2751,69 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController } if case let .filter(_, title, _, data) = filter, data.isShared { - let _ = (self.context.engine.data.get( - EngineDataList(data.includePeers.peers.map(TelegramEngine.EngineData.Item.Peer.Peer.init(id:))) + let _ = (combineLatest( + self.context.engine.data.get( + EngineDataList(data.includePeers.peers.map(TelegramEngine.EngineData.Item.Peer.Peer.init(id:))) + ), + self.context.engine.peers.getExportedChatFolderLinks(id: id) ) - |> deliverOnMainQueue).start(next: { [weak self] peers in + |> deliverOnMainQueue).start(next: { [weak self] peers, links in guard let self else { return } let presentationData = self.presentationData - //TODO:localize - self.present(standardTextAlertController(theme: AlertControllerTheme(presentationData: presentationData), title: "Delete Folder", text: "Are you sure you want to delete this folder? This will also deactivate all the invite links used to share this folder.", actions: [ - TextAlertAction(type: .destructiveAction, title: presentationData.strings.Common_Delete, action: { [weak self] in - guard let self else { - return - } - - let previewScreen = ChatFolderLinkPreviewScreen( - context: self.context, - subject: .remove(folderId: id), - contents: ChatFolderLinkContents( - localFilterId: id, - title: title, - peers: peers.compactMap { $0 }.filter { peer in - if case .channel = peer { - return true - } else { - return false - } - }, - alreadyMemberPeerIds: Set() - ), - completion: { [weak self] in - guard let self else { - return - } - if self.chatListDisplayNode.mainContainerNode.currentItemNode.chatListFilter?.id == id { - self.chatListDisplayNode.mainContainerNode.switchToFilter(id: .all, completion: { - }) + var hasLinks = false + if let links, !links.isEmpty { + hasLinks = true + } + + let confirmDeleteFolder: () -> Void = { [weak self] in + guard let self else { + return + } + + let previewScreen = ChatFolderLinkPreviewScreen( + context: self.context, + subject: .remove(folderId: id), + contents: ChatFolderLinkContents( + localFilterId: id, + title: title, + peers: peers.compactMap { $0 }.filter { peer in + if case .channel = peer { + return true + } else { + return false } + }, + alreadyMemberPeerIds: Set() + ), + completion: { [weak self] in + guard let self else { + return } - ) - self.push(previewScreen) - }), - TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_Cancel, action: { - }) - ]), in: .window(.root)) + if self.chatListDisplayNode.mainContainerNode.currentItemNode.chatListFilter?.id == id { + self.chatListDisplayNode.mainContainerNode.switchToFilter(id: .all, completion: { + }) + } + } + ) + self.push(previewScreen) + } + + if hasLinks { + //TODO:localize + self.present(standardTextAlertController(theme: AlertControllerTheme(presentationData: presentationData), title: "Delete Folder", text: "Are you sure you want to delete this folder? This will also deactivate all the invite links used to share this folder.", actions: [ + TextAlertAction(type: .destructiveAction, title: presentationData.strings.Common_Delete, action: { + confirmDeleteFolder() + }), + TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_Cancel, action: { + }) + ]), in: .window(.root)) + } else { + confirmDeleteFolder() + } }) } else { let actionSheet = ActionSheetController(presentationData: self.presentationData) diff --git a/submodules/ChatListUI/Sources/ChatListFilterPresetListController.swift b/submodules/ChatListUI/Sources/ChatListFilterPresetListController.swift index 2ae9924667..e1125a549a 100644 --- a/submodules/ChatListUI/Sources/ChatListFilterPresetListController.swift +++ b/submodules/ChatListUI/Sources/ChatListFilterPresetListController.swift @@ -391,36 +391,52 @@ public func chatListFilterPresetListController(context: AccountContext, mode: Ch let presentationData = context.sharedContext.currentPresentationData.with { $0 } if case let .filter(_, title, _, data) = filter, data.isShared { - let _ = (context.engine.data.get( - EngineDataList(data.includePeers.peers.map(TelegramEngine.EngineData.Item.Peer.Peer.init(id:))) + let _ = (combineLatest( + context.engine.data.get( + EngineDataList(data.includePeers.peers.map(TelegramEngine.EngineData.Item.Peer.Peer.init(id:))) + ), + context.engine.peers.getExportedChatFolderLinks(id: id) ) - |> deliverOnMainQueue).start(next: { peers in + |> deliverOnMainQueue).start(next: { peers, links in let presentationData = context.sharedContext.currentPresentationData.with { $0 } - //TODO:localize - presentControllerImpl?(standardTextAlertController(theme: AlertControllerTheme(presentationData: presentationData), title: "Delete Folder", text: "Are you sure you want to delete this folder? This will also deactivate all the invite links used to share this folder.", actions: [ - TextAlertAction(type: .destructiveAction, title: presentationData.strings.Common_Delete, action: { - let previewScreen = ChatFolderLinkPreviewScreen( - context: context, - subject: .remove(folderId: id), - contents: ChatFolderLinkContents( - localFilterId: id, - title: title, - peers: peers.compactMap { $0 }.filter { peer in - if case .channel = peer { - return true - } else { - return false - } - }, - alreadyMemberPeerIds: Set() - ) + var hasLinks = false + if let links, !links.isEmpty { + hasLinks = true + } + + let confirmDeleteFolder: () -> Void = { + let previewScreen = ChatFolderLinkPreviewScreen( + context: context, + subject: .remove(folderId: id), + contents: ChatFolderLinkContents( + localFilterId: id, + title: title, + peers: peers.compactMap { $0 }.filter { peer in + if case .channel = peer { + return true + } else { + return false + } + }, + alreadyMemberPeerIds: Set() ) - pushControllerImpl?(previewScreen) - }), - TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_Cancel, action: { - }) - ])) + ) + pushControllerImpl?(previewScreen) + } + + if hasLinks { + //TODO:localize + presentControllerImpl?(standardTextAlertController(theme: AlertControllerTheme(presentationData: presentationData), title: "Delete Folder", text: "Are you sure you want to delete this folder? This will also deactivate all the invite links used to share this folder.", actions: [ + TextAlertAction(type: .destructiveAction, title: presentationData.strings.Common_Delete, action: { + confirmDeleteFolder() + }), + TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_Cancel, action: { + }) + ])) + } else { + confirmDeleteFolder() + } }) } else { let actionSheet = ActionSheetController(presentationData: presentationData) diff --git a/submodules/SolidRoundedButtonNode/Sources/SolidRoundedButtonNode.swift b/submodules/SolidRoundedButtonNode/Sources/SolidRoundedButtonNode.swift index 6ab27211ad..7b0864eb3b 100644 --- a/submodules/SolidRoundedButtonNode/Sources/SolidRoundedButtonNode.swift +++ b/submodules/SolidRoundedButtonNode/Sources/SolidRoundedButtonNode.swift @@ -840,6 +840,9 @@ public final class SolidRoundedButtonNode: ASDisplayNode { self.subtitleNode.alpha = 0.0 self.subtitleNode.layer.animateAlpha(from: 0.55, to: 0.0, duration: 0.2) + self.badgeNode?.alpha = 0.0 + self.badgeNode?.layer.animateAlpha(from: 0.55, to: 0.0, duration: 0.2) + self.shimmerView?.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false) self.borderShimmerView?.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false) } @@ -873,6 +876,9 @@ public final class SolidRoundedButtonNode: ASDisplayNode { self.subtitleNode.alpha = 1.0 self.subtitleNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) + self.badgeNode?.alpha = 1.0 + self.badgeNode?.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) + self.shimmerView?.layer.removeAllAnimations() self.shimmerView?.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) self.borderShimmerView?.layer.removeAllAnimations() @@ -1282,6 +1288,9 @@ public final class SolidRoundedButtonView: UIView { self.subtitleNode.alpha = 0.0 self.subtitleNode.layer.animateAlpha(from: 0.55, to: 0.0, duration: 0.2) + self.badgeNode?.alpha = 0.0 + self.badgeNode?.layer.animateAlpha(from: 0.55, to: 0.0, duration: 0.2) + self.shimmerView?.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false) self.borderShimmerView?.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false) } @@ -1315,6 +1324,9 @@ public final class SolidRoundedButtonView: UIView { self.subtitleNode.alpha = 1.0 self.subtitleNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) + self.badgeNode?.alpha = 1.0 + self.badgeNode?.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) + self.shimmerView?.layer.removeAllAnimations() self.shimmerView?.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) self.borderShimmerView?.layer.removeAllAnimations() @@ -1475,6 +1487,7 @@ public final class SolidRoundedButtonView: UIView { badgeNode = current } else { badgeNode = BadgeNode(fillColor: self.theme.foregroundColor, strokeColor: .clear, textColor: self.theme.backgroundColor) + badgeNode.alpha = self.titleNode.alpha self.badgeNode = badgeNode self.addSubnode(badgeNode) } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/Communities.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/Communities.swift index f72b981d49..4dcf2471cf 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/Communities.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/Communities.swift @@ -12,6 +12,10 @@ public func canShareLinkToPeer(peer: EnginePeer) -> Bool { } else if channel.username != nil { isEnabled = true } + case let .legacyGroup(group): + if !group.hasBannedPermission(.banAddMembers) { + isEnabled = true + } default: break }