mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Fix link sharing
This commit is contained in:
parent
4ccd0bd804
commit
23fe769057
@ -2701,15 +2701,12 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func shareFolder(filterId: Int32, data: ChatListFilterData, title: String) {
|
private func shareFolder(filterId: Int32, data: ChatListFilterData, title: String) {
|
||||||
openCreateChatListFolderLink(context: self.context, folderId: filterId, title: title, peerIds: data.includePeers.peers, pushController: { [weak self] c in
|
openCreateChatListFolderLink(context: self.context, folderId: filterId, checkIfExists: true, title: title, peerIds: data.includePeers.peers, pushController: { [weak self] c in
|
||||||
self?.push(c)
|
self?.push(c)
|
||||||
}, presentController: { [weak self] c in
|
}, presentController: { [weak self] c in
|
||||||
self?.present(c, in: .window(.root))
|
self?.present(c, in: .window(.root))
|
||||||
}, linkUpdated: { _ in
|
}, linkUpdated: { _ in
|
||||||
})
|
})
|
||||||
|
|
||||||
/*self.push(folderInviteLinkListController(context: self.context, filterId: filterId, title: title, allPeerIds: data.includePeers.peers, currentInvitation: nil, linkUpdated: { _ in
|
|
||||||
}))*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func askForFilterRemoval(id: Int32) {
|
private func askForFilterRemoval(id: Int32) {
|
||||||
|
@ -1297,7 +1297,7 @@ func chatListFilterPresetController(context: AccountContext, currentPreset: Chat
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
openCreateChatListFolderLink(context: context, folderId: currentPreset.id, title: currentPreset.title, peerIds: state.additionallyIncludePeers, pushController: { c in
|
openCreateChatListFolderLink(context: context, folderId: currentPreset.id, checkIfExists: false, title: currentPreset.title, peerIds: state.additionallyIncludePeers, pushController: { c in
|
||||||
pushControllerImpl?(c)
|
pushControllerImpl?(c)
|
||||||
}, presentController: { c in
|
}, presentController: { c in
|
||||||
presentControllerImpl?(c, nil)
|
presentControllerImpl?(c, nil)
|
||||||
@ -1504,42 +1504,91 @@ func chatListFilterPresetController(context: AccountContext, currentPreset: Chat
|
|||||||
return controller
|
return controller
|
||||||
}
|
}
|
||||||
|
|
||||||
func openCreateChatListFolderLink(context: AccountContext, folderId: Int32, title: String, peerIds: [EnginePeer.Id], pushController: @escaping (ViewController) -> Void, presentController: @escaping (ViewController) -> Void, linkUpdated: @escaping (ExportedChatFolderLink?) -> Void) {
|
func openCreateChatListFolderLink(context: AccountContext, folderId: Int32, checkIfExists: Bool, title: String, peerIds: [EnginePeer.Id], pushController: @escaping (ViewController) -> Void, presentController: @escaping (ViewController) -> Void, linkUpdated: @escaping (ExportedChatFolderLink?) -> Void) {
|
||||||
if peerIds.isEmpty {
|
if peerIds.isEmpty {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let _ = (context.engine.data.get(
|
|
||||||
EngineDataList(peerIds.map(TelegramEngine.EngineData.Item.Peer.Peer.init(id:)))
|
let existingLink: Signal<ExportedChatFolderLink?, NoError>
|
||||||
)
|
if checkIfExists {
|
||||||
|> deliverOnMainQueue).start(next: { peers in
|
existingLink = combineLatest(
|
||||||
let peers = peers.compactMap({ $0 })
|
context.engine.peers.getExportedChatFolderLinks(id: folderId),
|
||||||
if peers.allSatisfy({ !canShareLinkToPeer(peer: $0) }) {
|
context.engine.data.get(
|
||||||
pushController(folderInviteLinkListController(context: context, filterId: folderId, title: title, allPeerIds: peerIds, currentInvitation: nil, linkUpdated: linkUpdated))
|
EngineDataList(peerIds.map(TelegramEngine.EngineData.Item.Peer.Peer.init(id:)))
|
||||||
} else {
|
)
|
||||||
let _ = (context.engine.peers.exportChatFolder(filterId: folderId, title: "", peerIds: peerIds)
|
)
|
||||||
|> deliverOnMainQueue).start(next: { link in
|
|> map { result, peers -> ExportedChatFolderLink? in
|
||||||
linkUpdated(link)
|
var enabledPeerIds: [EnginePeer.Id] = []
|
||||||
|
for peer in peers {
|
||||||
pushController(folderInviteLinkListController(context: context, filterId: folderId, title: title, allPeerIds: link.peerIds, currentInvitation: link, linkUpdated: linkUpdated))
|
if let peer, canShareLinkToPeer(peer: peer) {
|
||||||
}, error: { error in
|
enabledPeerIds.append(peer.id)
|
||||||
//TODO:localize
|
|
||||||
let text: String
|
|
||||||
switch error {
|
|
||||||
case .generic:
|
|
||||||
text = "An error occurred"
|
|
||||||
case let .limitExceeded(limit, premiumLimit):
|
|
||||||
if limit < premiumLimit {
|
|
||||||
let limitController = context.sharedContext.makePremiumLimitController(context: context, subject: .linksPerSharedFolder, count: limit, action: {
|
|
||||||
})
|
|
||||||
pushController(limitController)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
text = "You can't create more links."
|
|
||||||
}
|
}
|
||||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
}
|
||||||
presentController(standardTextAlertController(theme: AlertControllerTheme(presentationData: presentationData), title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]))
|
|
||||||
})
|
guard let result else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for link in result {
|
||||||
|
if Set(link.peerIds) == Set(enabledPeerIds) {
|
||||||
|
return link
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
existingLink = .single(nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
let _ = (existingLink
|
||||||
|
|> deliverOnMainQueue).start(next: { existingLink in
|
||||||
|
if let existingLink {
|
||||||
|
pushController(folderInviteLinkListController(context: context, filterId: folderId, title: title, allPeerIds: peerIds, currentInvitation: existingLink, linkUpdated: linkUpdated))
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let _ = (context.engine.data.get(
|
||||||
|
EngineDataList(peerIds.map(TelegramEngine.EngineData.Item.Peer.Peer.init(id:)))
|
||||||
|
)
|
||||||
|
|> deliverOnMainQueue).start(next: { peers in
|
||||||
|
let peers = peers.compactMap({ $0 })
|
||||||
|
if peers.allSatisfy({ !canShareLinkToPeer(peer: $0) }) {
|
||||||
|
pushController(folderInviteLinkListController(context: context, filterId: folderId, title: title, allPeerIds: peerIds, currentInvitation: nil, linkUpdated: linkUpdated))
|
||||||
|
} else {
|
||||||
|
var enabledPeerIds: [EnginePeer.Id] = []
|
||||||
|
for peer in peers {
|
||||||
|
if canShareLinkToPeer(peer: peer) {
|
||||||
|
enabledPeerIds.append(peer.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let _ = (context.engine.peers.exportChatFolder(filterId: folderId, title: "", peerIds: enabledPeerIds)
|
||||||
|
|> deliverOnMainQueue).start(next: { link in
|
||||||
|
linkUpdated(link)
|
||||||
|
|
||||||
|
pushController(folderInviteLinkListController(context: context, filterId: folderId, title: title, allPeerIds: peerIds, currentInvitation: link, linkUpdated: linkUpdated))
|
||||||
|
}, error: { error in
|
||||||
|
//TODO:localize
|
||||||
|
let text: String
|
||||||
|
switch error {
|
||||||
|
case .generic:
|
||||||
|
text = "An error occurred"
|
||||||
|
case let .limitExceeded(limit, premiumLimit):
|
||||||
|
if limit < premiumLimit {
|
||||||
|
let limitController = context.sharedContext.makePremiumLimitController(context: context, subject: .linksPerSharedFolder, count: limit, action: {
|
||||||
|
})
|
||||||
|
pushController(limitController)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
text = "You can't create more links."
|
||||||
|
}
|
||||||
|
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||||
|
presentController(standardTextAlertController(theme: AlertControllerTheme(presentationData: presentationData), title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user