Refactoring

This commit is contained in:
Ali
2023-04-17 20:21:14 +04:00
parent afe568c41f
commit 6e3cc4a6e9
81 changed files with 311 additions and 435 deletions

View File

@@ -661,7 +661,7 @@ public class ShareRootControllerImpl {
|> deliverOnMainQueue).start(next: { parseInfo in
switch parseInfo {
case let .group(groupTitle):
var attemptSelectionImpl: ((Peer) -> Void)?
var attemptSelectionImpl: ((EnginePeer) -> Void)?
var createNewGroupImpl: (() -> Void)?
let controller = context.sharedContext.makePeerSelectionController(PeerSelectionControllerParams(context: context, filter: [.onlyGroups, .onlyManageable, .excludeDisabled, .doNotSearchMessages], hasContactSelector: false, hasGlobalSearch: false, title: presentationData.strings.ChatImport_Title, attemptSelection: { peer, _ in
attemptSelectionImpl?(peer)
@@ -688,12 +688,12 @@ public class ShareRootControllerImpl {
attemptSelectionImpl = { peer in
var errorText: String?
if let channel = peer as? TelegramChannel {
if case let .channel(channel) = peer {
if channel.hasPermission(.changeInfo), (channel.flags.contains(.isCreator) || channel.adminRights != nil) {
} else {
errorText = presentationData.strings.ChatImport_SelectionErrorNotAdmin
}
} else if let group = peer as? TelegramGroup {
} else if case let .legacyGroup(group) = peer {
switch group.role {
case .creator:
break
@@ -718,19 +718,19 @@ public class ShareRootControllerImpl {
let presentationData = internalContext.sharedContext.currentPresentationData.with { $0 }
var errorText: String?
if let channel = peer as? TelegramChannel {
if case let .channel(channel) = peer {
if channel.hasPermission(.changeInfo), (channel.flags.contains(.isCreator) || channel.adminRights != nil) {
} else {
errorText = presentationData.strings.ChatImport_SelectionErrorNotAdmin
}
} else if let group = peer as? TelegramGroup {
} else if case let .legacyGroup(group) = peer {
switch group.role {
case .creator:
break
default:
errorText = presentationData.strings.ChatImport_SelectionErrorNotAdmin
}
} else if let _ = peer as? TelegramUser {
} else if case .user = peer {
} else {
errorText = presentationData.strings.ChatImport_SelectionErrorGroupGeneric
}
@@ -838,7 +838,7 @@ public class ShareRootControllerImpl {
case let .privateChat(title):
let presentationData = internalContext.sharedContext.currentPresentationData.with { $0 }
var attemptSelectionImpl: ((Peer) -> Void)?
var attemptSelectionImpl: ((EnginePeer) -> Void)?
let controller = context.sharedContext.makePeerSelectionController(PeerSelectionControllerParams(context: context, filter: [.onlyPrivateChats, .excludeDisabled, .doNotSearchMessages, .excludeSecretChats], hasChatListSelector: false, hasContactSelector: true, hasGlobalSearch: false, title: presentationData.strings.ChatImport_Title, attemptSelection: { peer, _ in
attemptSelectionImpl?(peer)
}, pretendPresentedInModal: true, selectForumThreads: true))
@@ -871,9 +871,9 @@ public class ShareRootControllerImpl {
switch result {
case .allowed:
if let title = title {
text = presentationData.strings.ChatImport_SelectionConfirmationUserWithTitle(title, EnginePeer(peer).displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder)).string
text = presentationData.strings.ChatImport_SelectionConfirmationUserWithTitle(title, peer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder)).string
} else {
text = presentationData.strings.ChatImport_SelectionConfirmationUserWithoutTitle(EnginePeer(peer).displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder)).string
text = presentationData.strings.ChatImport_SelectionConfirmationUserWithoutTitle(peer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder)).string
}
case let .alert(textValue):
text = textValue
@@ -910,7 +910,7 @@ public class ShareRootControllerImpl {
navigationController.viewControllers = [controller]
case let .unknown(peerTitle):
var attemptSelectionImpl: ((Peer) -> Void)?
var attemptSelectionImpl: ((EnginePeer) -> Void)?
var createNewGroupImpl: (() -> Void)?
let controller = context.sharedContext.makePeerSelectionController(PeerSelectionControllerParams(context: context, filter: [.excludeDisabled, .doNotSearchMessages], hasContactSelector: true, hasGlobalSearch: false, title: presentationData.strings.ChatImport_Title, attemptSelection: { peer, _ in
attemptSelectionImpl?(peer)
@@ -928,7 +928,7 @@ public class ShareRootControllerImpl {
controller.navigationPresentation = .default
let beginWithPeer: (PeerId) -> Void = { peerId in
let beginWithPeer: (EnginePeer.Id) -> Void = { peerId in
navigationController.view.endEditing(true)
navigationController.pushViewController(ChatImportActivityScreen(context: context, cancel: {
self?.getExtensionContext()?.completeRequest(returningItems: nil, completionHandler: nil)
@@ -944,19 +944,19 @@ public class ShareRootControllerImpl {
let presentationData = internalContext.sharedContext.currentPresentationData.with { $0 }
var errorText: String?
if let channel = peer as? TelegramChannel {
if case let .channel(channel) = peer {
if channel.hasPermission(.changeInfo), (channel.flags.contains(.isCreator) || channel.adminRights != nil) {
} else {
errorText = presentationData.strings.ChatImport_SelectionErrorNotAdmin
}
} else if let group = peer as? TelegramGroup {
} else if case let .legacyGroup(group) = peer {
switch group.role {
case .creator:
break
default:
errorText = presentationData.strings.ChatImport_SelectionErrorNotAdmin
}
} else if let _ = peer as? TelegramUser {
} else if case .user = peer {
} else {
errorText = presentationData.strings.ChatImport_SelectionErrorGroupGeneric
}
@@ -968,14 +968,14 @@ public class ShareRootControllerImpl {
strongSelf.mainWindow?.present(controller, on: .root)
} else {
let presentationData = internalContext.sharedContext.currentPresentationData.with { $0 }
if let _ = peer as? TelegramUser {
if case .user = peer {
let text: String
switch result {
case .allowed:
if let title = peerTitle {
text = presentationData.strings.ChatImport_SelectionConfirmationUserWithTitle(title, EnginePeer(peer).displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder)).string
text = presentationData.strings.ChatImport_SelectionConfirmationUserWithTitle(title, peer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder)).string
} else {
text = presentationData.strings.ChatImport_SelectionConfirmationUserWithoutTitle(EnginePeer(peer).displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder)).string
text = presentationData.strings.ChatImport_SelectionConfirmationUserWithoutTitle(peer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder)).string
}
case let .alert(textValue):
text = textValue