[WIP] Folders

This commit is contained in:
Ali
2023-03-21 23:38:48 +04:00
parent cd70df2448
commit c0dbb68a3c
23 changed files with 1817 additions and 97 deletions

View File

@@ -43,6 +43,7 @@ import PeerInfoUI
import ComponentDisplayAdapters
import ChatListHeaderComponent
import ChatListTitleView
import InviteLinksUI
private func fixListNodeScrolling(_ listNode: ListView, searchNode: NavigationBarSearchContentNode) -> Bool {
if listNode.scroller.isDragging {
@@ -1539,6 +1540,28 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
})
})))
}
//TODO:localize
for filter in filters {
if filter.id == filterId, case let .filter(_, _, _, data) = filter {
if !data.includePeers.peers.isEmpty {
items.append(.action(ContextMenuActionItem(text: "Share", textColor: .primary, icon: { theme in
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Share"), color: theme.contextMenu.primaryColor)
}, action: { c, f in
c.dismiss(completion: {
guard let strongSelf = self else {
return
}
strongSelf.shareFolder(filterId: filterId, data: data)
})
})))
}
break
}
}
break
}
}
@@ -2676,6 +2699,11 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
}
}
private func shareFolder(filterId: Int32, data: ChatListFilterData) {
self.push(folderInviteLinkListController(context: self.context, filterId: filterId, allPeerIds: data.includePeers.peers, currentInvitation: nil, linkUpdated: { _ in
}))
}
private func askForFilterRemoval(id: Int32) {
let actionSheet = ActionSheetController(presentationData: self.presentationData)

View File

@@ -188,7 +188,7 @@ private enum ChatListFilterPresetEntrySortId: Comparable {
case let .inviteLink(rhsIndex):
return lhsIndex < rhsIndex
case .inviteLinkFooter:
return false
return true
}
case .inviteLinkFooter:
switch rhs {
@@ -1059,8 +1059,8 @@ func chatListFilterPresetController(context: AccountContext, currentPreset: Chat
let sharedLinks = Promise<[ExportedChatFolderLink]?>(nil)
if let currentPreset {
sharedLinks.set(context.engine.peers.getExportedChatLinks(id: currentPreset.id)
|> map(Optional.init))
sharedLinks.set(Signal<[ExportedChatFolderLink]?, NoError>.single(nil) |> then(context.engine.peers.getExportedChatFolderLinks(id: currentPreset.id)
|> map(Optional.init)))
}
let currentPeers = Atomic<[PeerId: EngineRenderedPeer]>(value: [:])
@@ -1266,20 +1266,43 @@ func chatListFilterPresetController(context: AccountContext, currentPreset: Chat
},
createLink: {
if let currentPreset, let data = currentPreset.data, !data.includePeers.peers.isEmpty {
pushControllerImpl?(folderInviteLinkListController(context: context, filterId: currentPreset.id, allPeerIds: data.includePeers.peers, currentInvitation: nil))
/*if data.isShared {
} else {
let _ = (context.engine.peers.exportChatFolder(filterId: currentPreset.id, title: "Link", peerIds: data.includePeers.peers)
|> deliverOnMainQueue).start(completed: {
dismissImpl?()
pushControllerImpl?(folderInviteLinkListController(context: context, filterId: currentPreset.id, allPeerIds: data.includePeers.peers, currentInvitation: nil, linkUpdated: { updatedLink in
let _ = (sharedLinks.get() |> take(1) |> deliverOnMainQueue).start(next: { links in
guard var links else {
return
}
if let updatedLink {
links.insert(updatedLink, at: 0)
sharedLinks.set(.single(links))
}
})
}*/
}))
}
}, openLink: { link in
if let currentPreset, let data = currentPreset.data {
pushControllerImpl?(folderInviteLinkListController(context: context, filterId: currentPreset.id, allPeerIds: data.includePeers.peers, currentInvitation: link))
pushControllerImpl?(folderInviteLinkListController(context: context, filterId: currentPreset.id, allPeerIds: data.includePeers.peers, currentInvitation: link, linkUpdated: { updatedLink in
if updatedLink != link {
let _ = (sharedLinks.get() |> take(1) |> deliverOnMainQueue).start(next: { links in
guard var links else {
return
}
if let updatedLink {
if let index = links.firstIndex(where: { $0 == link }) {
links.remove(at: index)
}
links.insert(updatedLink, at: 0)
sharedLinks.set(.single(links))
} else {
if let index = links.firstIndex(where: { $0 == link }) {
links.remove(at: index)
sharedLinks.set(.single(links))
}
}
})
}
}))
}
}
)