mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Folder improvements
This commit is contained in:
parent
515ef8cfc5
commit
0e1dd66b04
@ -2815,6 +2815,9 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
|
||||
return
|
||||
}
|
||||
|
||||
if self.chatListDisplayNode.inlineStackContainerNode != nil {
|
||||
self.setInlineChatList(location: nil)
|
||||
}
|
||||
if self.chatListDisplayNode.mainContainerNode.currentItemNode.chatListFilter?.id != folderId {
|
||||
self.chatListDisplayNode.mainContainerNode.switchToFilter(id: .filter(folderId), completion: {
|
||||
completion()
|
||||
|
@ -1053,16 +1053,26 @@ private extension ChatListFilter {
|
||||
}
|
||||
}
|
||||
|
||||
func chatListFilterPresetController(context: AccountContext, currentPreset: ChatListFilter?, updated: @escaping ([ChatListFilter]) -> Void) -> ViewController {
|
||||
var currentPreset = currentPreset
|
||||
|
||||
func chatListFilterPresetController(context: AccountContext, currentPreset initialPreset: ChatListFilter?, updated: @escaping ([ChatListFilter]) -> Void) -> ViewController {
|
||||
let initialName: String
|
||||
if let currentPreset = currentPreset {
|
||||
initialName = currentPreset.title
|
||||
if let initialPreset {
|
||||
initialName = initialPreset.title
|
||||
} else {
|
||||
initialName = ""
|
||||
}
|
||||
let initialState = ChatListFilterPresetControllerState(name: initialName, changedName: currentPreset != nil, includeCategories: currentPreset?.data?.categories ?? [], excludeMuted: currentPreset?.data?.excludeMuted ?? false, excludeRead: currentPreset?.data?.excludeRead ?? false, excludeArchived: currentPreset?.data?.excludeArchived ?? false, additionallyIncludePeers: currentPreset?.data?.includePeers.peers ?? [], additionallyExcludePeers: currentPreset?.data?.excludePeers ?? [], expandedSections: [])
|
||||
let initialState = ChatListFilterPresetControllerState(name: initialName, changedName: initialPreset != nil, includeCategories: initialPreset?.data?.categories ?? [], excludeMuted: initialPreset?.data?.excludeMuted ?? false, excludeRead: initialPreset?.data?.excludeRead ?? false, excludeArchived: initialPreset?.data?.excludeArchived ?? false, additionallyIncludePeers: initialPreset?.data?.includePeers.peers ?? [], additionallyExcludePeers: initialPreset?.data?.excludePeers ?? [], expandedSections: [])
|
||||
|
||||
let updatedCurrentPreset: Signal<ChatListFilter?, NoError>
|
||||
if let initialPreset {
|
||||
updatedCurrentPreset = context.engine.peers.updatedChatListFilters()
|
||||
|> map { filters -> ChatListFilter? in
|
||||
return filters.first(where: { $0.id == initialPreset.id })
|
||||
}
|
||||
|> distinctUntilChanged
|
||||
} else {
|
||||
updatedCurrentPreset = .single(nil)
|
||||
}
|
||||
|
||||
let stateValue = Atomic(value: initialState)
|
||||
let statePromise = ValuePromise(initialState, ignoreRepeated: true)
|
||||
let updateState: ((ChatListFilterPresetControllerState) -> ChatListFilterPresetControllerState) -> Void = { f in
|
||||
@ -1072,7 +1082,7 @@ func chatListFilterPresetController(context: AccountContext, currentPreset: Chat
|
||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||
var includePeers = ChatListFilterIncludePeers()
|
||||
includePeers.setPeers(state.additionallyIncludePeers)
|
||||
let filter: ChatListFilter = .filter(id: currentPreset?.id ?? -1, title: state.name, emoticon: currentPreset?.emoticon, data: ChatListFilterData(isShared: currentPreset?.data?.isShared ?? false, hasSharedLinks: currentPreset?.data?.hasSharedLinks ?? false, categories: state.includeCategories, excludeMuted: state.excludeMuted, excludeRead: state.excludeRead, excludeArchived: state.excludeArchived, includePeers: includePeers, excludePeers: state.additionallyExcludePeers))
|
||||
let filter: ChatListFilter = .filter(id: initialPreset?.id ?? -1, title: state.name, emoticon: initialPreset?.emoticon, data: ChatListFilterData(isShared: initialPreset?.data?.isShared ?? false, hasSharedLinks: initialPreset?.data?.hasSharedLinks ?? false, categories: state.includeCategories, excludeMuted: state.excludeMuted, excludeRead: state.excludeRead, excludeArchived: state.excludeArchived, includePeers: includePeers, excludePeers: state.additionallyExcludePeers))
|
||||
if let data = filter.data {
|
||||
switch chatListFilterType(data) {
|
||||
case .generic:
|
||||
@ -1114,8 +1124,8 @@ func chatListFilterPresetController(context: AccountContext, currentPreset: Chat
|
||||
var presentInGlobalOverlayImpl: ((ViewController) -> Void)?
|
||||
|
||||
let sharedLinks = Promise<[ExportedChatFolderLink]?>(nil)
|
||||
if let currentPreset {
|
||||
sharedLinks.set(Signal<[ExportedChatFolderLink]?, NoError>.single(nil) |> then(context.engine.peers.getExportedChatFolderLinks(id: currentPreset.id)))
|
||||
if let initialPreset {
|
||||
sharedLinks.set(Signal<[ExportedChatFolderLink]?, NoError>.single(nil) |> then(context.engine.peers.getExportedChatFolderLinks(id: initialPreset.id)))
|
||||
}
|
||||
|
||||
let currentPeers = Atomic<[PeerId: EngineRenderedPeer]>(value: [:])
|
||||
@ -1189,8 +1199,9 @@ func chatListFilterPresetController(context: AccountContext, currentPreset: Chat
|
||||
TelegramEngine.EngineData.Item.Configuration.UserLimits(isPremium: false),
|
||||
TelegramEngine.EngineData.Item.Configuration.UserLimits(isPremium: true)
|
||||
),
|
||||
stateWithPeers |> take(1)
|
||||
).start(next: { result, state in
|
||||
stateWithPeers |> take(1),
|
||||
updatedCurrentPreset |> take(1)
|
||||
).start(next: { result, state, currentPreset in
|
||||
let (accountPeer, limits, premiumLimits) = result
|
||||
let isPremium = accountPeer?.isPremium ?? false
|
||||
|
||||
@ -1238,27 +1249,31 @@ func chatListFilterPresetController(context: AccountContext, currentPreset: Chat
|
||||
})
|
||||
},
|
||||
openAddExcludePeer: {
|
||||
let state = stateValue.with { $0 }
|
||||
var includePeers = ChatListFilterIncludePeers()
|
||||
includePeers.setPeers(state.additionallyIncludePeers)
|
||||
let filter: ChatListFilter = .filter(id: currentPreset?.id ?? -1, title: state.name, emoticon: currentPreset?.emoticon, data: ChatListFilterData(isShared: currentPreset?.data?.isShared ?? false, hasSharedLinks: currentPreset?.data?.hasSharedLinks ?? false, categories: state.includeCategories, excludeMuted: state.excludeMuted, excludeRead: state.excludeRead, excludeArchived: state.excludeArchived, includePeers: includePeers, excludePeers: state.additionallyExcludePeers))
|
||||
|
||||
let _ = (context.engine.peers.currentChatListFilters()
|
||||
|> deliverOnMainQueue).start(next: { filters in
|
||||
let controller = internalChatListFilterExcludeChatsController(context: context, filter: filter, allFilters: filters, applyAutomatically: false, updated: { filter in
|
||||
skipStateAnimation = true
|
||||
updateState { state in
|
||||
var updatedState = state
|
||||
updatedState.additionallyIncludePeers = filter.data?.includePeers.peers ?? []
|
||||
updatedState.additionallyExcludePeers = filter.data?.excludePeers ?? []
|
||||
updatedState.includeCategories = filter.data?.categories ?? []
|
||||
updatedState.excludeRead = filter.data?.excludeRead ?? false
|
||||
updatedState.excludeMuted = filter.data?.excludeMuted ?? false
|
||||
updatedState.excludeArchived = filter.data?.excludeArchived ?? false
|
||||
return updatedState
|
||||
}
|
||||
let _ = (updatedCurrentPreset
|
||||
|> take(1)
|
||||
|> deliverOnMainQueue).start(next: { currentPreset in
|
||||
let state = stateValue.with { $0 }
|
||||
var includePeers = ChatListFilterIncludePeers()
|
||||
includePeers.setPeers(state.additionallyIncludePeers)
|
||||
let filter: ChatListFilter = .filter(id: currentPreset?.id ?? -1, title: state.name, emoticon: currentPreset?.emoticon, data: ChatListFilterData(isShared: currentPreset?.data?.isShared ?? false, hasSharedLinks: currentPreset?.data?.hasSharedLinks ?? false, categories: state.includeCategories, excludeMuted: state.excludeMuted, excludeRead: state.excludeRead, excludeArchived: state.excludeArchived, includePeers: includePeers, excludePeers: state.additionallyExcludePeers))
|
||||
|
||||
let _ = (context.engine.peers.currentChatListFilters()
|
||||
|> deliverOnMainQueue).start(next: { filters in
|
||||
let controller = internalChatListFilterExcludeChatsController(context: context, filter: filter, allFilters: filters, applyAutomatically: false, updated: { filter in
|
||||
skipStateAnimation = true
|
||||
updateState { state in
|
||||
var updatedState = state
|
||||
updatedState.additionallyIncludePeers = filter.data?.includePeers.peers ?? []
|
||||
updatedState.additionallyExcludePeers = filter.data?.excludePeers ?? []
|
||||
updatedState.includeCategories = filter.data?.categories ?? []
|
||||
updatedState.excludeRead = filter.data?.excludeRead ?? false
|
||||
updatedState.excludeMuted = filter.data?.excludeMuted ?? false
|
||||
updatedState.excludeArchived = filter.data?.excludeArchived ?? false
|
||||
return updatedState
|
||||
}
|
||||
})
|
||||
presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
||||
})
|
||||
presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
||||
})
|
||||
},
|
||||
deleteIncludePeer: { peerId in
|
||||
@ -1323,170 +1338,188 @@ func chatListFilterPresetController(context: AccountContext, currentPreset: Chat
|
||||
}
|
||||
},
|
||||
createLink: {
|
||||
if currentPreset == nil {
|
||||
if initialPreset == nil {
|
||||
//TODO:localize
|
||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||
let text = "Please finish creating this folder to share it."
|
||||
presentControllerImpl?(standardTextAlertController(theme: AlertControllerTheme(presentationData: presentationData), title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil)
|
||||
} else {
|
||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||
|
||||
let state = stateValue.with({ $0 })
|
||||
if state.additionallyIncludePeers.isEmpty {
|
||||
//TODO:localize
|
||||
let text = "Please add chats to this folder to share it."
|
||||
presentControllerImpl?(standardTextAlertController(theme: AlertControllerTheme(presentationData: presentationData), title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
let statusController = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: nil))
|
||||
presentControllerImpl?(statusController, nil)
|
||||
|
||||
applyImpl?(true, { [weak statusController] in
|
||||
let state = stateValue.with({ $0 })
|
||||
|
||||
if let currentPreset, let data = currentPreset.data {
|
||||
//TODO:localize
|
||||
var unavailableText: String?
|
||||
if !data.categories.isEmpty {
|
||||
unavailableText = "You can’t share folders which have chat types or excluded chats."
|
||||
} else if data.excludeArchived || data.excludeRead || data.excludeMuted {
|
||||
unavailableText = "You can’t share folders which have chat types or excluded chats."
|
||||
} else if !data.excludePeers.isEmpty {
|
||||
unavailableText = "You can’t share folders which have chat types or excluded chats."
|
||||
}
|
||||
if let unavailableText {
|
||||
statusController?.dismiss()
|
||||
|
||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||
presentControllerImpl?(standardTextAlertController(theme: AlertControllerTheme(presentationData: presentationData), title: nil, text: unavailableText, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
var statusController = statusController
|
||||
|
||||
var previousLink: ExportedChatFolderLink?
|
||||
openCreateChatListFolderLink(context: context, folderId: currentPreset.id, checkIfExists: false, title: currentPreset.title, peerIds: state.additionallyIncludePeers, pushController: { c in
|
||||
pushControllerImpl?(c)
|
||||
}, presentController: { c in
|
||||
presentControllerImpl?(c, nil)
|
||||
}, completed: {
|
||||
statusController?.dismiss()
|
||||
statusController = nil
|
||||
}, linkUpdated: { updatedLink in
|
||||
let previousLinkValue = previousLink
|
||||
previousLink = updatedLink
|
||||
|
||||
let _ = (sharedLinks.get() |> take(1) |> deliverOnMainQueue).start(next: { links in
|
||||
var links = links ?? []
|
||||
let _ = (updatedCurrentPreset |> take(1) |> deliverOnMainQueue).start(next: { currentPreset in
|
||||
if let currentPreset, let data = currentPreset.data {
|
||||
//TODO:localize
|
||||
var unavailableText: String?
|
||||
if !data.categories.isEmpty {
|
||||
unavailableText = "You can’t share folders which have chat types or excluded chats."
|
||||
} else if data.excludeArchived || data.excludeRead || data.excludeMuted {
|
||||
unavailableText = "You can’t share folders which have chat types or excluded chats."
|
||||
} else if !data.excludePeers.isEmpty {
|
||||
unavailableText = "You can’t share folders which have chat types or excluded chats."
|
||||
}
|
||||
if let unavailableText {
|
||||
statusController?.dismiss()
|
||||
|
||||
if let updatedLink {
|
||||
if let index = links.firstIndex(where: { $0.link == updatedLink.link }) {
|
||||
links[index] = updatedLink
|
||||
} else {
|
||||
links.insert(updatedLink, at: 0)
|
||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||
presentControllerImpl?(standardTextAlertController(theme: AlertControllerTheme(presentationData: presentationData), title: nil, text: unavailableText, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
var statusController = statusController
|
||||
|
||||
var previousLink: ExportedChatFolderLink?
|
||||
openCreateChatListFolderLink(context: context, folderId: currentPreset.id, checkIfExists: false, title: currentPreset.title, peerIds: state.additionallyIncludePeers, pushController: { c in
|
||||
pushControllerImpl?(c)
|
||||
}, presentController: { c in
|
||||
presentControllerImpl?(c, nil)
|
||||
}, completed: {
|
||||
statusController?.dismiss()
|
||||
statusController = nil
|
||||
}, linkUpdated: { updatedLink in
|
||||
let previousLinkValue = previousLink
|
||||
previousLink = updatedLink
|
||||
|
||||
let _ = (sharedLinks.get() |> take(1) |> deliverOnMainQueue).start(next: { links in
|
||||
var links = links ?? []
|
||||
|
||||
if let updatedLink {
|
||||
if let index = links.firstIndex(where: { $0.link == updatedLink.link }) {
|
||||
links[index] = updatedLink
|
||||
} else {
|
||||
links.insert(updatedLink, at: 0)
|
||||
}
|
||||
} else if let previousLinkValue {
|
||||
if let index = links.firstIndex(where: { $0.link == previousLinkValue.link }) {
|
||||
links.remove(at: index)
|
||||
}
|
||||
}
|
||||
} else if let previousLinkValue {
|
||||
if let index = links.firstIndex(where: { $0.link == previousLinkValue.link }) {
|
||||
links.remove(at: index)
|
||||
}
|
||||
}
|
||||
sharedLinks.set(.single(links))
|
||||
sharedLinks.set(.single(links))
|
||||
})
|
||||
})
|
||||
})
|
||||
} else {
|
||||
statusController?.dismiss()
|
||||
}
|
||||
} else {
|
||||
statusController?.dismiss()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}, openLink: { link in
|
||||
if let currentPreset, let _ = currentPreset.data {
|
||||
applyImpl?(false, {
|
||||
let state = stateValue.with({ $0 })
|
||||
pushControllerImpl?(folderInviteLinkListController(context: context, filterId: currentPreset.id, title: currentPreset.title, allPeerIds: state.additionallyIncludePeers, currentInvitation: link, linkUpdated: { updatedLink in
|
||||
if updatedLink != link {
|
||||
let _ = (sharedLinks.get() |> take(1) |> deliverOnMainQueue).start(next: { links in
|
||||
var links = links ?? []
|
||||
|
||||
if let updatedLink {
|
||||
if let index = links.firstIndex(where: { $0.link == link.link }) {
|
||||
links[index] = updatedLink
|
||||
} else {
|
||||
links.insert(updatedLink, at: 0)
|
||||
}
|
||||
sharedLinks.set(.single(links))
|
||||
} else {
|
||||
if let index = links.firstIndex(where: { $0.link == link.link }) {
|
||||
links.remove(at: index)
|
||||
let _ = (updatedCurrentPreset |> take(1) |> deliverOnMainQueue).start(next: { currentPreset in
|
||||
if let currentPreset, let _ = currentPreset.data {
|
||||
applyImpl?(false, {
|
||||
let state = stateValue.with({ $0 })
|
||||
pushControllerImpl?(folderInviteLinkListController(context: context, filterId: currentPreset.id, title: currentPreset.title, allPeerIds: state.additionallyIncludePeers, currentInvitation: link, linkUpdated: { updatedLink in
|
||||
if updatedLink != link {
|
||||
let _ = (sharedLinks.get() |> take(1) |> deliverOnMainQueue).start(next: { links in
|
||||
var links = links ?? []
|
||||
|
||||
if let updatedLink {
|
||||
if let index = links.firstIndex(where: { $0.link == link.link }) {
|
||||
links[index] = updatedLink
|
||||
} else {
|
||||
links.insert(updatedLink, at: 0)
|
||||
}
|
||||
sharedLinks.set(.single(links))
|
||||
} else {
|
||||
if let index = links.firstIndex(where: { $0.link == link.link }) {
|
||||
links.remove(at: index)
|
||||
sharedLinks.set(.single(links))
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}, presentController: { c in
|
||||
presentControllerImpl?(c, nil)
|
||||
}))
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}, presentController: { c in
|
||||
presentControllerImpl?(c, nil)
|
||||
}))
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
removeLink: { link in
|
||||
if let currentPreset {
|
||||
let _ = (sharedLinks.get() |> take(1) |> deliverOnMainQueue).start(next: { links in
|
||||
var links = links ?? []
|
||||
|
||||
if let index = links.firstIndex(where: { $0.link == link.link }) {
|
||||
links.remove(at: index)
|
||||
}
|
||||
sharedLinks.set(.single(links))
|
||||
|
||||
actionsDisposable.add(context.engine.peers.deleteChatFolderLink(filterId: currentPreset.id, link: link).start())
|
||||
})
|
||||
}
|
||||
let _ = (updatedCurrentPreset |> take(1) |> deliverOnMainQueue).start(next: { currentPreset in
|
||||
if let currentPreset {
|
||||
let _ = (sharedLinks.get() |> take(1) |> deliverOnMainQueue).start(next: { links in
|
||||
var links = links ?? []
|
||||
|
||||
if let index = links.firstIndex(where: { $0.link == link.link }) {
|
||||
links.remove(at: index)
|
||||
}
|
||||
sharedLinks.set(.single(links))
|
||||
|
||||
actionsDisposable.add(context.engine.peers.deleteChatFolderLink(filterId: currentPreset.id, link: link).start())
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
linkContextAction: { invite, node, gesture in
|
||||
guard let node = node as? ContextExtractedContentContainingNode, let controller = getControllerImpl?(), let invite = invite, let currentPreset else {
|
||||
return
|
||||
}
|
||||
|
||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||
var items: [ContextMenuItem] = []
|
||||
|
||||
items.append(.action(ContextMenuActionItem(text: presentationData.strings.InviteLink_ContextCopy, icon: { theme in
|
||||
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Copy"), color: theme.contextMenu.primaryColor)
|
||||
}, action: { _, f in
|
||||
f(.default)
|
||||
let _ = (updatedCurrentPreset |> take(1) |> deliverOnMainQueue).start(next: { currentPreset in
|
||||
guard let node = node as? ContextExtractedContentContainingNode, let controller = getControllerImpl?(), let invite = invite, let currentPreset else {
|
||||
return
|
||||
}
|
||||
|
||||
//dismissTooltipsImpl?()
|
||||
|
||||
UIPasteboard.general.string = invite.link
|
||||
|
||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||
presentControllerImpl?(UndoOverlayController(presentationData: presentationData, content: .linkCopied(text: presentationData.strings.InviteLink_InviteLinkCopiedText), elevatedLayout: false, animateInAsReplacement: false, action: { _ in return false }), nil)
|
||||
})))
|
||||
|
||||
items.append(.action(ContextMenuActionItem(text: presentationData.strings.InviteLink_ContextGetQRCode, icon: { theme in
|
||||
return generateTintedImage(image: UIImage(bundleImageName: "Settings/QrIcon"), color: theme.contextMenu.primaryColor)
|
||||
}, action: { _, f in
|
||||
f(.dismissWithoutContent)
|
||||
var items: [ContextMenuItem] = []
|
||||
|
||||
presentControllerImpl?(QrCodeScreen(context: context, updatedPresentationData: nil, subject: .chatFolder(slug: invite.slug)), nil)
|
||||
})))
|
||||
|
||||
items.append(.action(ContextMenuActionItem(text: presentationData.strings.InviteLink_ContextRevoke, textColor: .destructive, icon: { theme in
|
||||
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Delete"), color: theme.contextMenu.destructiveColor)
|
||||
}, action: { _, f in
|
||||
f(.dismissWithoutContent)
|
||||
items.append(.action(ContextMenuActionItem(text: presentationData.strings.InviteLink_ContextCopy, icon: { theme in
|
||||
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Copy"), color: theme.contextMenu.primaryColor)
|
||||
}, action: { _, f in
|
||||
f(.default)
|
||||
|
||||
//dismissTooltipsImpl?()
|
||||
|
||||
UIPasteboard.general.string = invite.link
|
||||
|
||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||
presentControllerImpl?(UndoOverlayController(presentationData: presentationData, content: .linkCopied(text: presentationData.strings.InviteLink_InviteLinkCopiedText), elevatedLayout: false, animateInAsReplacement: false, action: { _ in return false }), nil)
|
||||
})))
|
||||
|
||||
let _ = (sharedLinks.get() |> take(1) |> deliverOnMainQueue).start(next: { links in
|
||||
var links = links ?? []
|
||||
if let index = links.firstIndex(where: { $0.link == invite.link }) {
|
||||
links.remove(at: index)
|
||||
}
|
||||
sharedLinks.set(.single(links))
|
||||
})
|
||||
items.append(.action(ContextMenuActionItem(text: presentationData.strings.InviteLink_ContextGetQRCode, icon: { theme in
|
||||
return generateTintedImage(image: UIImage(bundleImageName: "Settings/QrIcon"), color: theme.contextMenu.primaryColor)
|
||||
}, action: { _, f in
|
||||
f(.dismissWithoutContent)
|
||||
|
||||
presentControllerImpl?(QrCodeScreen(context: context, updatedPresentationData: nil, subject: .chatFolder(slug: invite.slug)), nil)
|
||||
})))
|
||||
|
||||
let _ = (context.engine.peers.editChatFolderLink(filterId: currentPreset.id, link: invite, title: nil, peerIds: nil, revoke: true)
|
||||
|> deliverOnMainQueue).start(completed: {
|
||||
let _ = (context.engine.peers.deleteChatFolderLink(filterId: currentPreset.id, link: invite)
|
||||
|> deliverOnMainQueue).start(completed: {
|
||||
items.append(.action(ContextMenuActionItem(text: presentationData.strings.InviteLink_ContextRevoke, textColor: .destructive, icon: { theme in
|
||||
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Delete"), color: theme.contextMenu.destructiveColor)
|
||||
}, action: { _, f in
|
||||
f(.dismissWithoutContent)
|
||||
|
||||
let _ = (sharedLinks.get() |> take(1) |> deliverOnMainQueue).start(next: { links in
|
||||
var links = links ?? []
|
||||
if let index = links.firstIndex(where: { $0.link == invite.link }) {
|
||||
links.remove(at: index)
|
||||
}
|
||||
sharedLinks.set(.single(links))
|
||||
})
|
||||
})
|
||||
})))
|
||||
|
||||
let contextController = ContextController(account: context.account, presentationData: presentationData, source: .extracted(InviteLinkContextExtractedContentSource(controller: controller, sourceNode: node, keepInPlace: false, blurBackground: true)), items: .single(ContextController.Items(content: .list(items))), gesture: gesture)
|
||||
presentInGlobalOverlayImpl?(contextController)
|
||||
|
||||
let _ = (context.engine.peers.editChatFolderLink(filterId: currentPreset.id, link: invite, title: nil, peerIds: nil, revoke: true)
|
||||
|> deliverOnMainQueue).start(completed: {
|
||||
let _ = (context.engine.peers.deleteChatFolderLink(filterId: currentPreset.id, link: invite)
|
||||
|> deliverOnMainQueue).start(completed: {
|
||||
})
|
||||
})
|
||||
})))
|
||||
|
||||
let contextController = ContextController(account: context.account, presentationData: presentationData, source: .extracted(InviteLinkContextExtractedContentSource(controller: controller, sourceNode: node, keepInPlace: false, blurBackground: true)), items: .single(ContextController.Items(content: .list(items))), gesture: gesture)
|
||||
presentInGlobalOverlayImpl?(contextController)
|
||||
})
|
||||
},
|
||||
peerContextAction: { peer, node, gesture, location in
|
||||
let chatController = context.sharedContext.makeChatController(context: context, chatLocation: .peer(id: peer.id), subject: nil, botStart: nil, mode: .standard(previewing: true))
|
||||
@ -1516,62 +1549,64 @@ func chatListFilterPresetController(context: AccountContext, currentPreset: Chat
|
||||
}
|
||||
)
|
||||
|
||||
var attemptNavigationImpl: (() -> Bool)?
|
||||
var attemptNavigationImpl: ((@escaping (Bool) -> Void) -> Void)?
|
||||
applyImpl = { waitForSync, completed in
|
||||
let state = stateValue.with { $0 }
|
||||
|
||||
var includePeers = ChatListFilterIncludePeers()
|
||||
includePeers.setPeers(state.additionallyIncludePeers)
|
||||
|
||||
let _ = (context.engine.peers.updateChatListFiltersInteractively { filters in
|
||||
var filterId = currentPreset?.id ?? -1
|
||||
if currentPreset == nil {
|
||||
filterId = context.engine.peers.generateNewChatListFilterId(filters: filters)
|
||||
}
|
||||
var updatedFilter: ChatListFilter = .filter(id: filterId, title: state.name, emoticon: currentPreset?.emoticon, data: ChatListFilterData(isShared: currentPreset?.data?.isShared ?? false, hasSharedLinks: currentPreset?.data?.hasSharedLinks ?? false, categories: state.includeCategories, excludeMuted: state.excludeMuted, excludeRead: state.excludeRead, excludeArchived: state.excludeArchived, includePeers: includePeers, excludePeers: state.additionallyExcludePeers))
|
||||
let _ = (updatedCurrentPreset |> take(1) |> deliverOnMainQueue).start(next: { currentPreset in
|
||||
let state = stateValue.with { $0 }
|
||||
|
||||
var filters = filters
|
||||
if let _ = currentPreset {
|
||||
var found = false
|
||||
for i in 0 ..< filters.count {
|
||||
if filters[i].id == updatedFilter.id, case let .filter(_, _, _, data) = filters[i] {
|
||||
var updatedData = updatedFilter.data ?? data
|
||||
var includePeers = data.includePeers
|
||||
includePeers.setPeers(state.additionallyIncludePeers)
|
||||
updatedData.includePeers = includePeers
|
||||
updatedFilter = .filter(id: filterId, title: state.name, emoticon: currentPreset?.emoticon, data: updatedData)
|
||||
filters[i] = updatedFilter
|
||||
found = true
|
||||
}
|
||||
var includePeers = ChatListFilterIncludePeers()
|
||||
includePeers.setPeers(state.additionallyIncludePeers)
|
||||
|
||||
let _ = (context.engine.peers.updateChatListFiltersInteractively { filters in
|
||||
var filterId = currentPreset?.id ?? -1
|
||||
if currentPreset == nil {
|
||||
filterId = context.engine.peers.generateNewChatListFilterId(filters: filters)
|
||||
}
|
||||
if !found {
|
||||
filters = filters.filter { listFilter in
|
||||
if listFilter.title == updatedFilter.title && listFilter.data == updatedFilter.data {
|
||||
return false
|
||||
var updatedFilter: ChatListFilter = .filter(id: filterId, title: state.name, emoticon: currentPreset?.emoticon, data: ChatListFilterData(isShared: currentPreset?.data?.isShared ?? false, hasSharedLinks: currentPreset?.data?.hasSharedLinks ?? false, categories: state.includeCategories, excludeMuted: state.excludeMuted, excludeRead: state.excludeRead, excludeArchived: state.excludeArchived, includePeers: includePeers, excludePeers: state.additionallyExcludePeers))
|
||||
|
||||
var filters = filters
|
||||
if let _ = currentPreset {
|
||||
var found = false
|
||||
for i in 0 ..< filters.count {
|
||||
if filters[i].id == updatedFilter.id, case let .filter(_, _, _, data) = filters[i] {
|
||||
var updatedData = updatedFilter.data ?? data
|
||||
var includePeers = data.includePeers
|
||||
includePeers.setPeers(state.additionallyIncludePeers)
|
||||
updatedData.includePeers = includePeers
|
||||
updatedFilter = .filter(id: filterId, title: state.name, emoticon: currentPreset?.emoticon, data: updatedData)
|
||||
filters[i] = updatedFilter
|
||||
found = true
|
||||
}
|
||||
return true
|
||||
}
|
||||
if !found {
|
||||
filters = filters.filter { listFilter in
|
||||
if listFilter.title == updatedFilter.title && listFilter.data == updatedFilter.data {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
filters.append(updatedFilter)
|
||||
}
|
||||
//currentPreset = updatedFilter
|
||||
} else {
|
||||
filters.append(updatedFilter)
|
||||
}
|
||||
currentPreset = updatedFilter
|
||||
} else {
|
||||
filters.append(updatedFilter)
|
||||
return filters
|
||||
}
|
||||
return filters
|
||||
}
|
||||
|> deliverOnMainQueue).start(next: { filters in
|
||||
updated(filters)
|
||||
|
||||
if waitForSync {
|
||||
let _ = (context.engine.peers.chatListFiltersAreSynced()
|
||||
|> filter { $0 }
|
||||
|> take(1)
|
||||
|> deliverOnMainQueue).start(next: { _ in
|
||||
|> deliverOnMainQueue).start(next: { filters in
|
||||
updated(filters)
|
||||
|
||||
if waitForSync {
|
||||
let _ = (context.engine.peers.chatListFiltersAreSynced()
|
||||
|> filter { $0 }
|
||||
|> take(1)
|
||||
|> deliverOnMainQueue).start(next: { _ in
|
||||
completed()
|
||||
})
|
||||
} else {
|
||||
completed()
|
||||
})
|
||||
} else {
|
||||
completed()
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@ -1586,16 +1621,23 @@ func chatListFilterPresetController(context: AccountContext, currentPreset: Chat
|
||||
context.engine.data.get(
|
||||
TelegramEngine.EngineData.Item.Configuration.UserLimits(isPremium: true)
|
||||
),
|
||||
sharedLinks.get()
|
||||
sharedLinks.get(),
|
||||
updatedCurrentPreset
|
||||
)
|
||||
|> deliverOnMainQueue
|
||||
|> map { presentationData, stateWithPeers, peerView, premiumLimits, sharedLinks -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
|> map { presentationData, stateWithPeers, peerView, premiumLimits, sharedLinks, currentPreset -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
let (state, includePeers, excludePeers) = stateWithPeers
|
||||
|
||||
let isPremium = peerView.peers[peerView.peerId]?.isPremium ?? false
|
||||
|
||||
let leftNavigationButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Cancel), style: .regular, enabled: true, action: {
|
||||
if attemptNavigationImpl?() ?? true {
|
||||
if let attemptNavigationImpl {
|
||||
attemptNavigationImpl({ value in
|
||||
if value {
|
||||
dismissImpl?()
|
||||
}
|
||||
})
|
||||
} else {
|
||||
dismissImpl?()
|
||||
}
|
||||
})
|
||||
@ -1659,7 +1701,16 @@ func chatListFilterPresetController(context: AccountContext, currentPreset: Chat
|
||||
controller.view.endEditing(true)
|
||||
}
|
||||
controller.attemptNavigation = { _ in
|
||||
return attemptNavigationImpl?() ?? true
|
||||
if let attemptNavigationImpl {
|
||||
attemptNavigationImpl({ value in
|
||||
if value {
|
||||
dismissImpl?()
|
||||
}
|
||||
})
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
let displaySaveAlert: () -> Void = {
|
||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||
@ -1682,31 +1733,35 @@ func chatListFilterPresetController(context: AccountContext, currentPreset: Chat
|
||||
controller.presentInGlobalOverlay(c)
|
||||
}
|
||||
}
|
||||
attemptNavigationImpl = {
|
||||
let state = stateValue.with { $0 }
|
||||
if let currentPreset = currentPreset, case let .filter(currentId, currentTitle, currentEmoticon, currentData) = currentPreset {
|
||||
var currentPresetWithoutPinnedPeers = currentPreset
|
||||
|
||||
var currentIncludePeers = ChatListFilterIncludePeers()
|
||||
currentIncludePeers.setPeers(currentData.includePeers.peers)
|
||||
var currentPresetWithoutPinnedPeersData = currentData
|
||||
currentPresetWithoutPinnedPeersData.includePeers = currentIncludePeers
|
||||
currentPresetWithoutPinnedPeers = .filter(id: currentId, title: currentTitle, emoticon: currentEmoticon, data: currentPresetWithoutPinnedPeersData)
|
||||
|
||||
var includePeers = ChatListFilterIncludePeers()
|
||||
includePeers.setPeers(state.additionallyIncludePeers)
|
||||
let filter: ChatListFilter = .filter(id: currentPreset.id, title: state.name, emoticon: currentPreset.emoticon, data: ChatListFilterData(isShared: currentPreset.data?.isShared ?? false, hasSharedLinks: currentPreset.data?.hasSharedLinks ?? false, categories: state.includeCategories, excludeMuted: state.excludeMuted, excludeRead: state.excludeRead, excludeArchived: state.excludeArchived, includePeers: includePeers, excludePeers: state.additionallyExcludePeers))
|
||||
if currentPresetWithoutPinnedPeers != filter {
|
||||
displaySaveAlert()
|
||||
return false
|
||||
attemptNavigationImpl = { f in
|
||||
let _ = (updatedCurrentPreset |> take(1) |> deliverOnMainQueue).start(next: { currentPreset in
|
||||
let state = stateValue.with { $0 }
|
||||
if let currentPreset = currentPreset, case let .filter(currentId, currentTitle, currentEmoticon, currentData) = currentPreset {
|
||||
var currentPresetWithoutPinnedPeers = currentPreset
|
||||
|
||||
var currentIncludePeers = ChatListFilterIncludePeers()
|
||||
currentIncludePeers.setPeers(currentData.includePeers.peers)
|
||||
var currentPresetWithoutPinnedPeersData = currentData
|
||||
currentPresetWithoutPinnedPeersData.includePeers = currentIncludePeers
|
||||
currentPresetWithoutPinnedPeers = .filter(id: currentId, title: currentTitle, emoticon: currentEmoticon, data: currentPresetWithoutPinnedPeersData)
|
||||
|
||||
var includePeers = ChatListFilterIncludePeers()
|
||||
includePeers.setPeers(state.additionallyIncludePeers)
|
||||
let filter: ChatListFilter = .filter(id: currentPreset.id, title: state.name, emoticon: currentPreset.emoticon, data: ChatListFilterData(isShared: currentPreset.data?.isShared ?? false, hasSharedLinks: currentPreset.data?.hasSharedLinks ?? false, categories: state.includeCategories, excludeMuted: state.excludeMuted, excludeRead: state.excludeRead, excludeArchived: state.excludeArchived, includePeers: includePeers, excludePeers: state.additionallyExcludePeers))
|
||||
if currentPresetWithoutPinnedPeers != filter {
|
||||
displaySaveAlert()
|
||||
f(false)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if currentPreset != nil, state.isComplete {
|
||||
displaySaveAlert()
|
||||
f(false)
|
||||
return
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if currentPreset != nil, state.isComplete {
|
||||
displaySaveAlert()
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
f(true)
|
||||
})
|
||||
}
|
||||
|
||||
return controller
|
||||
|
@ -324,7 +324,7 @@ public func chatListFilterPresetListController(context: AccountContext, mode: Ch
|
||||
let _ = (context.engine.peers.updateChatListFiltersInteractively { filters in
|
||||
var filters = filters
|
||||
let id = context.engine.peers.generateNewChatListFilterId(filters: filters)
|
||||
filters.insert(.filter(id: id, title: title, emoticon: nil, data: data), at: 0)
|
||||
filters.append(.filter(id: id, title: title, emoticon: nil, data: data))
|
||||
return filters
|
||||
}
|
||||
|> deliverOnMainQueue).start(next: { _ in
|
||||
|
@ -684,7 +684,16 @@ public func folderInviteLinkListController(context: AccountContext, updatedPrese
|
||||
} else if state.isSaving {
|
||||
doneButton = ItemListNavigationButton(content: .none, style: .activity, enabled: true, action: {})
|
||||
} else {
|
||||
doneButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Save), style: .bold, enabled: !state.selectedPeerIds.isEmpty, action: {
|
||||
var saveEnabled = false
|
||||
if let currentLink = state.currentLink {
|
||||
if currentLink.title != state.title || Set(currentLink.peerIds) != state.selectedPeerIds {
|
||||
saveEnabled = true
|
||||
}
|
||||
} else {
|
||||
saveEnabled = true
|
||||
}
|
||||
|
||||
doneButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Save), style: .bold, enabled: !state.selectedPeerIds.isEmpty && saveEnabled, action: {
|
||||
applyChangesImpl?()
|
||||
})
|
||||
}
|
||||
@ -739,7 +748,7 @@ public func folderInviteLinkListController(context: AccountContext, updatedPrese
|
||||
f()
|
||||
dismissImpl?()
|
||||
}),
|
||||
TextAlertAction(type: .defaultAction, title: "Apply", action: {
|
||||
TextAlertAction(type: .defaultAction, title: state.selectedPeerIds.isEmpty ? "Continue" : "Apply", action: {
|
||||
applyChangesImpl?()
|
||||
})
|
||||
]), nil)
|
||||
|
@ -144,6 +144,10 @@ public class ItemListFolderInviteLinkListItemNode: ItemListRevealOptionsItemNode
|
||||
private var nonExtractedRect: CGRect?
|
||||
|
||||
private let offsetContainerNode: ASDisplayNode
|
||||
public override var controlsContainer: ASDisplayNode {
|
||||
//return super.controlsContainer
|
||||
return self.containerNode
|
||||
}
|
||||
|
||||
private let iconBackgroundNode: ASDisplayNode
|
||||
private let iconNode: ASImageNode
|
||||
@ -428,7 +432,9 @@ public class ItemListFolderInviteLinkListItemNode: ItemListRevealOptionsItemNode
|
||||
strongSelf.insertSubnode(strongSelf.bottomStripeNode, at: 2)
|
||||
}
|
||||
if strongSelf.maskNode.supernode == nil {
|
||||
strongSelf.insertSubnode(strongSelf.maskNode, at: 3)
|
||||
//strongSelf.insertSubnode(strongSelf.maskNode, at: 3)
|
||||
strongSelf.maskNode.isUserInteractionEnabled = false
|
||||
strongSelf.addSubnode(strongSelf.maskNode)
|
||||
}
|
||||
|
||||
let hasCorners = itemListHasRoundedBlockLayout(params)
|
||||
@ -581,7 +587,7 @@ public class ItemListFolderInviteLinkListItemNode: ItemListRevealOptionsItemNode
|
||||
override public func updateRevealOffset(offset: CGFloat, transition: ContainedViewLayoutTransition) {
|
||||
super.updateRevealOffset(offset: offset, transition: transition)
|
||||
|
||||
transition.updateSublayerTransformOffset(layer: self.containerNode.layer, offset: CGPoint(x: offset, y: 0.0))
|
||||
transition.updateSublayerTransformOffset(layer: self.offsetContainerNode.layer, offset: CGPoint(x: offset + (self.contextSourceNode.isExtractedToContextPreview ? 12.0 : 0.0), y: 0.0))
|
||||
}
|
||||
|
||||
override public func revealOptionSelected(_ option: ItemListRevealOption, animated: Bool) {
|
||||
|
@ -205,13 +205,17 @@ private final class ChatFolderLinkPreviewScreenComponent: Component {
|
||||
return
|
||||
}
|
||||
|
||||
var topOffset = -self.scrollView.bounds.minY + itemLayout.topInset
|
||||
if topOffset > 0.0 {
|
||||
topOffset = max(0.0, topOffset)
|
||||
|
||||
if topOffset < topOffsetDistance {
|
||||
targetContentOffset.pointee.y = scrollView.contentOffset.y
|
||||
scrollView.setContentOffset(CGPoint(x: 0.0, y: itemLayout.topInset), animated: true)
|
||||
if scrollView.contentOffset.y <= -100.0 && velocity.y <= -2.0 {
|
||||
self.environment?.controller()?.dismiss()
|
||||
} else {
|
||||
var topOffset = -self.scrollView.bounds.minY + itemLayout.topInset
|
||||
if topOffset > 0.0 {
|
||||
topOffset = max(0.0, topOffset)
|
||||
|
||||
if topOffset < topOffsetDistance {
|
||||
targetContentOffset.pointee.y = scrollView.contentOffset.y
|
||||
scrollView.setContentOffset(CGPoint(x: 0.0, y: itemLayout.topInset), animated: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -287,7 +291,10 @@ private final class ChatFolderLinkPreviewScreenComponent: Component {
|
||||
controller.updateModalStyleOverlayTransitionFactor(0.0, transition: .animated(duration: 0.3, curve: .easeInOut))
|
||||
}
|
||||
|
||||
let animateOffset: CGFloat = self.bounds.height - self.backgroundLayer.frame.minY
|
||||
var animateOffset: CGFloat = self.bounds.height - self.backgroundLayer.frame.minY
|
||||
if self.scrollView.contentOffset.y < 0.0 {
|
||||
animateOffset += -self.scrollView.contentOffset.y
|
||||
}
|
||||
|
||||
self.dimView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, removeOnCompletion: false)
|
||||
self.scrollContentClippingView.layer.animatePosition(from: CGPoint(), to: CGPoint(x: 0.0, y: animateOffset), duration: 0.3, timingFunction: CAMediaTimingFunctionName.easeInEaseOut.rawValue, removeOnCompletion: false, additive: true, completion: { _ in
|
||||
@ -698,10 +705,18 @@ private final class ChatFolderLinkPreviewScreenComponent: Component {
|
||||
}
|
||||
|
||||
var subtitle: String?
|
||||
if linkContents.alreadyMemberPeerIds.contains(peer.id) {
|
||||
subtitle = "You are already a member"
|
||||
} else if let memberCount = linkContents.memberCounts[peer.id] {
|
||||
subtitle = "\(memberCount) participants"
|
||||
if case let .channel(channel) = peer, case .broadcast = channel.info {
|
||||
if linkContents.alreadyMemberPeerIds.contains(peer.id) {
|
||||
subtitle = "You are already a subscriber"
|
||||
} else if let memberCount = linkContents.memberCounts[peer.id] {
|
||||
subtitle = "\(memberCount) subscribers"
|
||||
}
|
||||
} else {
|
||||
if linkContents.alreadyMemberPeerIds.contains(peer.id) {
|
||||
subtitle = "You are already a member"
|
||||
} else if let memberCount = linkContents.memberCounts[peer.id] {
|
||||
subtitle = "\(memberCount) participants"
|
||||
}
|
||||
}
|
||||
|
||||
let itemSize = item.update(
|
||||
|
Loading…
x
Reference in New Issue
Block a user