(open)Id/Dc/CreationDate/RegDate(ContextMenu)

This commit is contained in:
levochkaa 2025-05-04 22:59:01 +04:00
parent 9694b55c10
commit 37c605a981

View File

@ -498,7 +498,6 @@ private enum PeerInfoMemberAction {
private enum PeerInfoContextSubject { private enum PeerInfoContextSubject {
case copy(String) case copy(String)
case aboutDC
case bio case bio
case phone(String) case phone(String)
case link(customLink: String?) case link(customLink: String?)
@ -624,6 +623,10 @@ private final class PeerInfoInteraction {
let openWorkingHoursContextMenu: (ASDisplayNode, ContextGesture?) -> Void let openWorkingHoursContextMenu: (ASDisplayNode, ContextGesture?) -> Void
let openBusinessLocationContextMenu: (ASDisplayNode, ContextGesture?) -> Void let openBusinessLocationContextMenu: (ASDisplayNode, ContextGesture?) -> Void
let openBirthdayContextMenu: (ASDisplayNode, ContextGesture?) -> Void let openBirthdayContextMenu: (ASDisplayNode, ContextGesture?) -> Void
let openIdContextMenu: (ASDisplayNode, ContextGesture?, String) -> Void
let openDcContextMenu: (ASDisplayNode, ContextGesture?) -> Void
let openCreationDateContextMenu: (ASDisplayNode, ContextGesture?, String) -> Void
let openRegDateContextMenu: (ASDisplayNode, ContextGesture?, String) -> Void
let editingOpenAffiliateProgram: () -> Void let editingOpenAffiliateProgram: () -> Void
let editingOpenVerifyAccounts: () -> Void let editingOpenVerifyAccounts: () -> Void
let editingToggleAutoTranslate: (Bool) -> Void let editingToggleAutoTranslate: (Bool) -> Void
@ -698,6 +701,10 @@ private final class PeerInfoInteraction {
openWorkingHoursContextMenu: @escaping (ASDisplayNode, ContextGesture?) -> Void, openWorkingHoursContextMenu: @escaping (ASDisplayNode, ContextGesture?) -> Void,
openBusinessLocationContextMenu: @escaping (ASDisplayNode, ContextGesture?) -> Void, openBusinessLocationContextMenu: @escaping (ASDisplayNode, ContextGesture?) -> Void,
openBirthdayContextMenu: @escaping (ASDisplayNode, ContextGesture?) -> Void, openBirthdayContextMenu: @escaping (ASDisplayNode, ContextGesture?) -> Void,
openIdContextMenu: @escaping (ASDisplayNode, ContextGesture?, String) -> Void,
openDcContextMenu: @escaping (ASDisplayNode, ContextGesture?) -> Void,
openCreationDateContextMenu: @escaping (ASDisplayNode, ContextGesture?, String) -> Void,
openRegDateContextMenu: @escaping (ASDisplayNode, ContextGesture?, String) -> Void,
editingOpenAffiliateProgram: @escaping () -> Void, editingOpenAffiliateProgram: @escaping () -> Void,
editingOpenVerifyAccounts: @escaping () -> Void, editingOpenVerifyAccounts: @escaping () -> Void,
editingToggleAutoTranslate: @escaping (Bool) -> Void, editingToggleAutoTranslate: @escaping (Bool) -> Void,
@ -771,6 +778,10 @@ private final class PeerInfoInteraction {
self.openWorkingHoursContextMenu = openWorkingHoursContextMenu self.openWorkingHoursContextMenu = openWorkingHoursContextMenu
self.openBusinessLocationContextMenu = openBusinessLocationContextMenu self.openBusinessLocationContextMenu = openBusinessLocationContextMenu
self.openBirthdayContextMenu = openBirthdayContextMenu self.openBirthdayContextMenu = openBirthdayContextMenu
self.openIdContextMenu = openIdContextMenu
self.openDcContextMenu = openDcContextMenu
self.openCreationDateContextMenu = openCreationDateContextMenu
self.openRegDateContextMenu = openRegDateContextMenu
self.editingOpenAffiliateProgram = editingOpenAffiliateProgram self.editingOpenAffiliateProgram = editingOpenAffiliateProgram
self.editingOpenVerifyAccounts = editingOpenVerifyAccounts self.editingOpenVerifyAccounts = editingOpenVerifyAccounts
self.editingToggleAutoTranslate = editingToggleAutoTranslate self.editingToggleAutoTranslate = editingToggleAutoTranslate
@ -1357,6 +1368,18 @@ private func infoItems(nearestChatParticipant: (String?, Int32?), showProfileId:
let birthdayContextAction: (ASDisplayNode, ContextGesture?, CGPoint?) -> Void = { node, gesture, _ in let birthdayContextAction: (ASDisplayNode, ContextGesture?, CGPoint?) -> Void = { node, gesture, _ in
interaction.openBirthdayContextMenu(node, gesture) interaction.openBirthdayContextMenu(node, gesture)
} }
let openIdContextMenu: (ASDisplayNode, ContextGesture?, String) -> Void = { node, gesture, id in
interaction.openIdContextMenu(node, gesture, id)
}
let openDcContextMenu: (ASDisplayNode, ContextGesture?) -> Void = { node, gesture in
interaction.openDcContextMenu(node, gesture)
}
let openRegDateContextMenu: (ASDisplayNode, ContextGesture?, String) -> Void = { node, gesture, regDate in
interaction.openRegDateContextMenu(node, gesture, regDate)
}
let openCreationDateContextMenu: (ASDisplayNode, ContextGesture?, String) -> Void = { node, gesture, creationDate in
interaction.openCreationDateContextMenu(node, gesture, creationDate)
}
if let user = data.peer as? TelegramUser { if let user = data.peer as? TelegramUser {
// MARK: Swiftgram // MARK: Swiftgram
@ -2105,11 +2128,11 @@ private func infoItems(nearestChatParticipant: (String?, Int32?), showProfileId:
// MARK: Swiftgram // MARK: Swiftgram
if showProfileId { if showProfileId {
items[.swiftgram]!.append(PeerInfoScreenLabeledValueItem(id: sgItemId, label: "id: \(idText)", text: "", textColor: .primary, action: nil, longTapAction: { sourceNode in items[.swiftgram]!.append(PeerInfoScreenLabeledValueItem(id: sgItemId, context: context, label: "id", text: idText, textColor: .primary, leftIcon: nil, icon: nil, action: { node, _ in
interaction.openPeerInfoContextMenu(.copy(idText), sourceNode, nil) openIdContextMenu(node, nil, idText)
}, requestLayout: { _ in }, longTapAction: nil, iconAction: nil, contextAction: { node, gesture, _ in
interaction.requestLayout(false) openIdContextMenu(node, gesture, idText)
})) }, requestLayout: { _ in }))
sgItemId += 1 sgItemId += 1
} }
@ -2119,7 +2142,7 @@ private func infoItems(nearestChatParticipant: (String?, Int32?), showProfileId:
var phoneCountryText = "" var phoneCountryText = ""
var dcLabel = "" var dcLabel = ""
var dcText: String = "" // var dcText: String = ""
if let cachedData = data.cachedData as? CachedUserData, let phoneCountry = cachedData.peerStatusSettings?.phoneCountry { if let cachedData = data.cachedData as? CachedUserData, let phoneCountry = cachedData.peerStatusSettings?.phoneCountry {
var countryName = "" var countryName = ""
@ -2153,25 +2176,25 @@ private func infoItems(nearestChatParticipant: (String?, Int32?), showProfileId:
} }
if let dcId = dcId { if let dcId = dcId {
dcLabel = "dc: \(dcId)" dcLabel = "\(dcId)"
if phoneCountryText.isEmpty { // if phoneCountryText.isEmpty {
// if !dcLocation.isEmpty { // if !dcLocation.isEmpty {
// dcLabel += " \(dcLocation)" // dcLabel += " \(dcLocation)"
// } // }
} else { // } else {
dcText = "\(phoneCountryText)" // dcText = "\(phoneCountryText)"
} // }
} else if !phoneCountryText.isEmpty { } else if !phoneCountryText.isEmpty {
dcLabel = "dc: ?" dcLabel = "?"
dcText = phoneCountryText // dcText = phoneCountryText
} }
if !dcText.isEmpty || !dcLabel.isEmpty { if !dcLabel.isEmpty {
items[.swiftgram]!.append(PeerInfoScreenLabeledValueItem(id: sgItemId, label: dcLabel, text: dcText, textColor: .primary, action: nil, longTapAction: { sourceNode in items[.swiftgram]!.append(PeerInfoScreenLabeledValueItem(id: sgItemId, context: context, label: "dc", text: dcLabel, textColor: .primary, leftIcon: nil, icon: nil, action: { node, _ in
interaction.openPeerInfoContextMenu(.aboutDC, sourceNode, nil) openDcContextMenu(node, nil)
}, requestLayout: { _ in }, longTapAction: nil, iconAction: nil, contextAction: { node, gesture, _ in
interaction.requestLayout(false) openDcContextMenu(node, gesture)
})) }, requestLayout: { _ in }))
sgItemId += 1 sgItemId += 1
} }
} }
@ -2179,11 +2202,11 @@ private func infoItems(nearestChatParticipant: (String?, Int32?), showProfileId:
if SGSimpleSettings.shared.showCreationDate { if SGSimpleSettings.shared.showCreationDate {
if let channelCreationTimestamp = data.channelCreationTimestamp { if let channelCreationTimestamp = data.channelCreationTimestamp {
let creationDateString = stringForDate(timestamp: channelCreationTimestamp, strings: presentationData.strings) let creationDateString = stringForDate(timestamp: channelCreationTimestamp, strings: presentationData.strings)
items[.swiftgram]!.append(PeerInfoScreenLabeledValueItem(id: sgItemId, label: i18n("Chat.Created", presentationData.strings.baseLanguageCode, creationDateString), text: "", action: nil, longTapAction: { sourceNode in items[.swiftgram]!.append(PeerInfoScreenLabeledValueItem(id: sgItemId, context: context, label: "Chat.Created", text: creationDateString, textColor: .primary, leftIcon: nil, icon: nil, action: { node, _ in
interaction.openPeerInfoContextMenu(.copy(creationDateString), sourceNode, nil) openCreationDateContextMenu(node, nil, creationDateString)
}, requestLayout: { _ in }, longTapAction: nil, iconAction: nil, contextAction: { node, gesture, _ in
interaction.requestLayout(false) openCreationDateContextMenu(node, gesture, creationDateString)
})) }, requestLayout: { _ in }))
sgItemId += 1 sgItemId += 1
} }
} }
@ -2220,11 +2243,11 @@ private func infoItems(nearestChatParticipant: (String?, Int32?), showProfileId:
} }
} }
if !regDateString.isEmpty { if !regDateString.isEmpty {
items[.swiftgram]!.append(PeerInfoScreenLabeledValueItem(id: sgItemId, label: i18n("Chat.RegDate", presentationData.strings.baseLanguageCode), text: regDateString, action: nil, longTapAction: { sourceNode in items[.swiftgram]!.append(PeerInfoScreenLabeledValueItem(id: sgItemId, context: context, label: "Chat.RegDate", text: regDateString, textColor: .primary, leftIcon: nil, icon: nil, action: { node, _ in
interaction.openPeerInfoContextMenu(.copy(regDateString), sourceNode, nil) openRegDateContextMenu(node, nil, regDateString)
}, requestLayout: { _ in }, longTapAction: nil, iconAction: nil, contextAction: { node, gesture, _ in
interaction.requestLayout(false) openRegDateContextMenu(node, gesture, regDateString)
})) }, requestLayout: { _ in }))
sgItemId += 1 sgItemId += 1
} }
} }
@ -3457,6 +3480,18 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
return return
} }
self.openBirthdayContextMenu(node: node, gesture: gesture) self.openBirthdayContextMenu(node: node, gesture: gesture)
}, openIdContextMenu: { [weak self] node, gesture, id in
guard let self else { return }
self.openIdContextMenu(node: node, gesture: gesture, id: id)
}, openDcContextMenu: { [weak self] node, gesture in
guard let self else { return }
self.openDcContextMenu(node: node, gesture: gesture)
}, openCreationDateContextMenu: { [weak self] node, gesture, creationDate in
guard let self else { return }
self.openCreationDateContextMenu(node: node, gesture: gesture, creationDate: creationDate)
}, openRegDateContextMenu: { [weak self] node, gesture, regDate in
guard let self else { return }
self.openRegDateContextMenu(node: node, gesture: gesture, regDate: regDate)
}, editingOpenAffiliateProgram: { [weak self] in }, editingOpenAffiliateProgram: { [weak self] in
guard let self else { guard let self else {
return return
@ -8232,6 +8267,68 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
self.controller?.present(contextController, in: .window(.root)) self.controller?.present(contextController, in: .window(.root))
} }
private func openIdContextMenu(node: ASDisplayNode, gesture: ContextGesture?, id: String) {
guard let sourceNode = node as? ContextExtractedContentContainingNode else { return }
let copyAction = { [weak self] in
guard let self else { return }
UIPasteboard.general.string = id
self.controller?.present(UndoOverlayController(presentationData: self.presentationData, content: .copy(text: "Copied ID"), elevatedLayout: false, animateInAsReplacement: false, action: { _ in return false }), in: .current)
}
var items: [ContextMenuItem] = []
items.append(.action(ContextMenuActionItem(text: "Copy ID", icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Copy"), color: theme.contextMenu.primaryColor) }, action: { c, _ in
c?.dismiss { copyAction() }
})))
let actions = ContextController.Items(content: .list(items))
let contextController = ContextController(presentationData: self.presentationData, source: .extracted(PeerInfoContextExtractedContentSource(sourceNode: sourceNode)), items: .single(actions), gesture: gesture)
self.controller?.present(contextController, in: .window(.root))
}
private func openDcContextMenu(node: ASDisplayNode, gesture: ContextGesture?) {
guard let sourceNode = node as? ContextExtractedContentContainingNode else { return }
let learnMoreAction = { [weak self] in
self?.openUrl(url: "https://core.telegram.org/api/datacenter", concealed: false, external: false)
}
var items: [ContextMenuItem] = []
items.append(.action(ContextMenuActionItem(text: self.presentationData.strings.Passport_InfoLearnMore, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Browser"), color: theme.contextMenu.primaryColor) }, action: { c, _ in
c?.dismiss { learnMoreAction() }
})))
let actions = ContextController.Items(content: .list(items))
let contextController = ContextController(presentationData: self.presentationData, source: .extracted(PeerInfoContextExtractedContentSource(sourceNode: sourceNode)), items: .single(actions), gesture: gesture)
self.controller?.present(contextController, in: .window(.root))
}
private func openCreationDateContextMenu(node: ASDisplayNode, gesture: ContextGesture?, creationDate: String) {
guard let sourceNode = node as? ContextExtractedContentContainingNode else { return }
let copyAction = { [weak self] in
guard let self else { return }
UIPasteboard.general.string = creationDate
self.controller?.present(UndoOverlayController(presentationData: self.presentationData, content: .copy(text: "Copied creation date"), elevatedLayout: false, animateInAsReplacement: false, action: { _ in return false }), in: .current)
}
var items: [ContextMenuItem] = []
items.append(.action(ContextMenuActionItem(text: "Copy Creation Date", icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Copy"), color: theme.contextMenu.primaryColor) }, action: { c, _ in
c?.dismiss { copyAction() }
})))
let actions = ContextController.Items(content: .list(items))
let contextController = ContextController(presentationData: self.presentationData, source: .extracted(PeerInfoContextExtractedContentSource(sourceNode: sourceNode)), items: .single(actions), gesture: gesture)
self.controller?.present(contextController, in: .window(.root))
}
private func openRegDateContextMenu(node: ASDisplayNode, gesture: ContextGesture?, regDate: String) {
guard let sourceNode = node as? ContextExtractedContentContainingNode else { return }
let copyAction = { [weak self] in
guard let self else { return }
UIPasteboard.general.string = regDate
self.controller?.present(UndoOverlayController(presentationData: self.presentationData, content: .copy(text: "Copied registration date"), elevatedLayout: false, animateInAsReplacement: false, action: { _ in return false }), in: .current)
}
var items: [ContextMenuItem] = []
items.append(.action(ContextMenuActionItem(text: "Copy Registration Date", icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Copy"), color: theme.contextMenu.primaryColor) }, action: { c, _ in
c?.dismiss { copyAction() }
})))
let actions = ContextController.Items(content: .list(items))
let contextController = ContextController(presentationData: self.presentationData, source: .extracted(PeerInfoContextExtractedContentSource(sourceNode: sourceNode)), items: .single(actions), gesture: gesture)
self.controller?.present(contextController, in: .window(.root))
}
private func openPhone(value: String, node: ASDisplayNode, gesture: ContextGesture?, progress: Promise<Bool>?) { private func openPhone(value: String, node: ASDisplayNode, gesture: ContextGesture?, progress: Promise<Bool>?) {
guard let sourceNode = node as? ContextExtractedContentContainingNode else { guard let sourceNode = node as? ContextExtractedContentContainingNode else {
return return
@ -9835,22 +9932,6 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
return nil return nil
} }
})) }))
case .aboutDC:
let contextMenuController = makeContextMenuController(actions: [ContextMenuAction(content: .text(title: self.presentationData.strings.Passport_InfoLearnMore, accessibilityLabel: self.presentationData.strings.Passport_InfoLearnMore), action: { [weak self] in
self?.openUrl(url: "https://core.telegram.org/api/datacenter", concealed: false, external: false)
})])
controller.present(contextMenuController, in: .window(.root), with: ContextMenuControllerPresentationArguments(sourceNodeAndRect: { [weak self, weak sourceNode] in
if let controller = self?.controller, let sourceNode = sourceNode {
var rect = sourceNode.bounds.insetBy(dx: 0.0, dy: 2.0)
if let sourceRect = sourceRect {
rect = sourceRect.insetBy(dx: 0.0, dy: 2.0)
}
return (sourceNode, rect, controller.displayNode, controller.view.bounds)
} else {
return nil
}
}))
case .bio: case .bio:
var text: String? var text: String?