GLEGram 12.5 — Initial public release

Based on Swiftgram 12.5 (Telegram iOS 12.5).
All GLEGram features ported and organized in GLEGram/ folder.

Features: Ghost Mode, Saved Deleted Messages, Content Protection Bypass,
Font Replacement, Fake Profile, Chat Export, Plugin System, and more.

See CHANGELOG_12.5.md for full details.
This commit is contained in:
Leeksov
2026-04-06 09:48:12 +03:00
commit 4647310322
39685 changed files with 11052678 additions and 0 deletions
@@ -0,0 +1,166 @@
import Foundation
import UIKit
import TelegramCore
import SwiftSignalKit
import Display
import AsyncDisplayKit
import TelegramPresentationData
import TelegramUIPreferences
import PresentationDataUtils
import ProgressNavigationButtonNode
import AccountContext
public class TermsOfServiceControllerTheme {
public let statusBarStyle: StatusBarStyle
public let navigationBackground: UIColor
public let navigationSeparator: UIColor
public let listBackground: UIColor
public let itemBackground: UIColor
public let itemSeparator: UIColor
public let primary: UIColor
public let accent: UIColor
public let disabled: UIColor
public init(statusBarStyle: StatusBarStyle, navigationBackground: UIColor, navigationSeparator: UIColor, listBackground: UIColor, itemBackground: UIColor, itemSeparator: UIColor, primary: UIColor, accent: UIColor, disabled: UIColor) {
self.statusBarStyle = statusBarStyle
self.navigationBackground = navigationBackground
self.navigationSeparator = navigationSeparator
self.listBackground = listBackground
self.itemBackground = itemBackground
self.itemSeparator = itemSeparator
self.primary = primary
self.accent = accent
self.disabled = disabled
}
}
public extension TermsOfServiceControllerTheme {
convenience init(presentationTheme: PresentationTheme) {
self.init(statusBarStyle: presentationTheme.rootController.statusBarStyle.style, navigationBackground: presentationTheme.rootController.navigationBar.opaqueBackgroundColor, navigationSeparator: presentationTheme.rootController.navigationBar.separatorColor, listBackground: presentationTheme.list.blocksBackgroundColor, itemBackground: presentationTheme.list.itemBlocksBackgroundColor, itemSeparator: presentationTheme.list.itemBlocksSeparatorColor, primary: presentationTheme.list.itemPrimaryTextColor, accent: presentationTheme.list.itemAccentColor, disabled: presentationTheme.rootController.navigationBar.disabledButtonColor)
}
}
public class TermsOfServiceController: ViewController, StandalonePresentableController {
private var controllerNode: TermsOfServiceControllerNode {
return self.displayNode as! TermsOfServiceControllerNode
}
private let context: AccountContext
private let presentationData: PresentationData
private let text: String
private let entities: [MessageTextEntity]
private let ageConfirmation: Int32?
private let signingUp: Bool
private let accept: (String?) -> Void
private let decline: () -> Void
private let openUrl: (String) -> Void
private var proccessBotNameAfterAccept: String? = nil
private var didPlayPresentationAnimation = false
public var inProgress: Bool = false {
didSet {
if self.inProgress {
let item = UIBarButtonItem(customDisplayNode: ProgressNavigationButtonNode(color: self.presentationData.theme.list.itemAccentColor))
self.navigationItem.rightBarButtonItem = item
} else {
self.navigationItem.rightBarButtonItem = nil
}
self.controllerNode.inProgress = self.inProgress
}
}
public init(context: AccountContext, presentationData: PresentationData, text: String, entities: [MessageTextEntity], ageConfirmation: Int32?, signingUp: Bool, accept: @escaping (String?) -> Void, decline: @escaping () -> Void, openUrl: @escaping (String) -> Void) {
self.context = context
self.presentationData = presentationData
self.text = text
self.entities = entities
self.ageConfirmation = ageConfirmation
self.signingUp = signingUp
self.accept = accept
self.decline = decline
self.openUrl = openUrl
super.init(navigationBarPresentationData: NavigationBarPresentationData(theme: NavigationBarTheme(rootControllerTheme: presentationData.theme), strings: NavigationBarStrings(back: presentationData.strings.Common_Back, close: presentationData.strings.Common_Close)))
self.statusBar.statusBarStyle = self.presentationData.theme.rootController.statusBarStyle.style
self.title = self.presentationData.strings.Login_TermsOfServiceHeader
self.navigationItem.backBarButtonItem = UIBarButtonItem(title: self.presentationData.strings.Common_Back, style: .plain, target: nil, action: nil)
self.scrollToTop = { [weak self] in
self?.controllerNode.scrollToTop()
}
}
required public init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
deinit {
}
override public func loadDisplayNode() {
self.displayNode = TermsOfServiceControllerNode(presentationData: self.presentationData, text: self.text, entities: self.entities, ageConfirmation: self.ageConfirmation, leftAction: { [weak self] in
guard let strongSelf = self else {
return
}
let text: String
let declineTitle: String
if strongSelf.signingUp {
text = strongSelf.presentationData.strings.Login_TermsOfServiceSignupDecline
declineTitle = strongSelf.presentationData.strings.Login_TermsOfServiceDecline
} else {
text = strongSelf.presentationData.strings.PrivacyPolicy_DeclineMessage
declineTitle = strongSelf.presentationData.strings.PrivacyPolicy_DeclineDeclineAndDelete
}
strongSelf.present(textAlertController(context: strongSelf.context, title: strongSelf.presentationData.strings.PrivacyPolicy_Decline, text: text, actions: [TextAlertAction(type: .destructiveAction, title: declineTitle, action: {
self?.decline()
}), TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_Cancel, action: {
})], actionLayout: .vertical), in: .window(.root))
}, rightAction: { [weak self] in
guard let strongSelf = self else {
return
}
if let ageConfirmation = strongSelf.ageConfirmation {
strongSelf.present(textAlertController(context: strongSelf.context, title: strongSelf.presentationData.strings.PrivacyPolicy_AgeVerificationTitle, text: strongSelf.presentationData.strings.PrivacyPolicy_AgeVerificationMessage("\(ageConfirmation)").string, actions: [TextAlertAction(type: .genericAction, title: strongSelf.presentationData.strings.Common_Cancel, action: {}), TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.PrivacyPolicy_AgeVerificationAgree, action: {
self?.accept(self?.proccessBotNameAfterAccept)
})]), in: .window(.root))
} else {
strongSelf.accept(self?.proccessBotNameAfterAccept)
}
}, openUrl: self.openUrl, present: { [weak self] c, a in
self?.present(c, in: .window(.root), with: a)
}, setToProcceedBot: { [weak self] botName in
self?.proccessBotNameAfterAccept = botName
})
self.displayNodeDidLoad()
}
override public func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
super.containerLayoutUpdated(layout, transition: transition)
self.controllerNode.containerLayoutUpdated(layout, navigationBarHeight: self.navigationLayout(layout: layout).navigationFrame.maxY, transition: transition)
}
override public func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if !self.didPlayPresentationAnimation {
self.didPlayPresentationAnimation = true
self.controllerNode.animateIn()
}
}
override public func dismiss(completion: (() -> Void)? = nil) {
self.controllerNode.animateOut(completion: { [weak self] in
self?.presentingViewController?.dismiss(animated: false, completion: nil)
completion?()
})
}
}
@@ -0,0 +1,260 @@
import Foundation
import UIKit
import TelegramCore
import SwiftSignalKit
import Display
import AsyncDisplayKit
import TelegramPresentationData
import TextFormat
import UndoUI
final class TermsOfServiceControllerNode: ViewControllerTracingNode {
private let presentationData: PresentationData
private let text: String
private let entities: [MessageTextEntity]
private let ageConfirmation: Int32?
private let leftAction: () -> Void
private let rightAction: () -> Void
private let openUrl: (String) -> Void
private let present: (ViewController, Any?) -> Void
private let scrollNode: ASScrollNode
private let contentBackgroundNode: ASDisplayNode
private let contentTextNode: ImmediateTextNode
private let toolbarNode: ASDisplayNode
private let toolbarSeparatorNode: ASDisplayNode
private let leftActionNode: HighlightableButtonNode
private let leftActionTextNode: ImmediateTextNode
private let rightActionNode: HighlightableButtonNode
private let rightActionTextNode: ImmediateTextNode
private var containerLayout: (ContainerViewLayout, CGFloat)?
var inProgress: Bool = false {
didSet {
if self.inProgress != oldValue {
self.leftActionTextNode.alpha = self.inProgress ? 0.5 : 1.0
self.rightActionTextNode.alpha = self.inProgress ? 0.5 : 1.0
self.leftActionNode.isEnabled = !self.inProgress
self.rightActionNode.isEnabled = !self.inProgress
}
}
}
init(presentationData: PresentationData, text: String, entities: [MessageTextEntity], ageConfirmation: Int32?, leftAction: @escaping () -> Void, rightAction: @escaping () -> Void, openUrl: @escaping (String) -> Void, present: @escaping (ViewController, Any?) -> Void, setToProcceedBot:@escaping(String)->Void) {
self.presentationData = presentationData
self.text = text
self.entities = entities
self.ageConfirmation = ageConfirmation
self.leftAction = leftAction
self.rightAction = rightAction
self.openUrl = openUrl
self.present = present
self.scrollNode = ASScrollNode()
self.contentBackgroundNode = ASDisplayNode()
self.contentTextNode = ImmediateTextNode()
self.contentTextNode.displaysAsynchronously = false
self.contentTextNode.maximumNumberOfLines = 0
let fontSize = floor(presentationData.listsFontSize.baseDisplaySize * 15.0 / 17.0)
self.contentTextNode.attributedText = stringWithAppliedEntities(text, entities: entities, baseColor: presentationData.theme.list.itemPrimaryTextColor, linkColor: presentationData.theme.list.itemAccentColor, baseFont: Font.regular(fontSize), linkFont: Font.regular(fontSize), boldFont: Font.semibold(fontSize), italicFont: Font.italic(fontSize), boldItalicFont: Font.semiboldItalic(fontSize), fixedFont: Font.monospace(fontSize), blockQuoteFont: Font.regular(fontSize), message: nil)
self.toolbarNode = ASDisplayNode()
self.toolbarSeparatorNode = ASDisplayNode()
self.leftActionNode = HighlightableButtonNode()
self.leftActionTextNode = ImmediateTextNode()
self.leftActionTextNode.displaysAsynchronously = false
self.leftActionTextNode.isUserInteractionEnabled = false
self.leftActionTextNode.attributedText = NSAttributedString(string: self.presentationData.strings.PrivacyPolicy_Decline, font: Font.regular(presentationData.listsFontSize.baseDisplaySize), textColor: self.presentationData.theme.list.itemAccentColor)
self.rightActionNode = HighlightableButtonNode()
self.rightActionTextNode = ImmediateTextNode()
self.rightActionTextNode.displaysAsynchronously = false
self.rightActionTextNode.isUserInteractionEnabled = false
self.rightActionTextNode.attributedText = NSAttributedString(string: self.presentationData.strings.PrivacyPolicy_Accept, font: Font.semibold(presentationData.listsFontSize.baseDisplaySize), textColor: self.presentationData.theme.list.itemAccentColor)
super.init()
self.backgroundColor = self.presentationData.theme.list.blocksBackgroundColor
self.toolbarNode.backgroundColor = self.presentationData.theme.rootController.navigationBar.opaqueBackgroundColor
self.toolbarSeparatorNode.backgroundColor = self.presentationData.theme.rootController.navigationBar.separatorColor
self.contentBackgroundNode.backgroundColor = self.presentationData.theme.list.itemBlocksBackgroundColor
self.addSubnode(self.scrollNode)
self.scrollNode.addSubnode(self.contentBackgroundNode)
self.scrollNode.addSubnode(self.contentTextNode)
self.addSubnode(self.toolbarNode)
self.addSubnode(self.toolbarSeparatorNode)
self.addSubnode(self.leftActionTextNode)
self.addSubnode(self.leftActionNode)
self.addSubnode(self.rightActionTextNode)
self.addSubnode(self.rightActionNode)
self.leftActionNode.highligthedChanged = { [weak self] highlighted in
guard let strongSelf = self else {
return
}
if highlighted {
strongSelf.leftActionTextNode.layer.removeAnimation(forKey: "opacity")
strongSelf.leftActionTextNode.alpha = 0.4
} else {
strongSelf.leftActionTextNode.alpha = 1.0
strongSelf.leftActionTextNode.layer.animateAlpha(from: 0.4, to: 1.0, duration: 0.2)
}
}
self.rightActionNode.highligthedChanged = { [weak self] highlighted in
guard let strongSelf = self else {
return
}
if highlighted {
strongSelf.rightActionTextNode.layer.removeAnimation(forKey: "opacity")
strongSelf.rightActionTextNode.alpha = 0.4
} else {
strongSelf.rightActionTextNode.alpha = 1.0
strongSelf.rightActionTextNode.layer.animateAlpha(from: 0.4, to: 1.0, duration: 0.2)
}
}
self.leftActionNode.addTarget(self, action: #selector(self.leftActionPressed), forControlEvents: .touchUpInside)
self.rightActionNode.addTarget(self, action: #selector(self.rightActionPressed), forControlEvents: .touchUpInside)
self.contentTextNode.linkHighlightColor = self.presentationData.theme.list.itemAccentColor.withAlphaComponent(0.2)
self.contentTextNode.highlightAttributeAction = { attributes in
if let _ = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.URL)] {
return NSAttributedString.Key(rawValue: TelegramTextAttributes.URL)
} else if let _ = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.PeerMention)] {
return NSAttributedString.Key(rawValue: TelegramTextAttributes.URL)
} else if let _ = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.PeerTextMention)] {
return NSAttributedString.Key(rawValue: TelegramTextAttributes.URL)
} else {
return nil
}
}
let showMentionActionSheet:(String) -> Void = { [weak self] mention in
guard let strongSelf = self else {
return
}
let actionSheet = ActionSheetController(presentationData: strongSelf.presentationData)
actionSheet.setItemGroups([ActionSheetItemGroup(items: [
ActionSheetTextItem(title: strongSelf.presentationData.strings.Login_TermsOfService_ProceedBot(mention).string),
ActionSheetButtonItem(title: strongSelf.presentationData.strings.PrivacyPolicy_Accept, color: .accent, action: { [weak actionSheet] in
actionSheet?.dismissAnimated()
setToProcceedBot(mention)
rightAction()
})
]), ActionSheetItemGroup(items: [ActionSheetButtonItem(title: strongSelf.presentationData.strings.Common_Cancel, action: { [weak actionSheet] in
actionSheet?.dismissAnimated()
})])])
strongSelf.present(actionSheet, nil)
}
self.contentTextNode.tapAttributeAction = { [weak self] attributes, _ in
guard let strongSelf = self else {
return
}
if let url = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.URL)] as? String {
strongSelf.openUrl(url)
} else if let mention = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.PeerMention)] as? TelegramPeerMention {
showMentionActionSheet(mention.mention)
} else if let mention = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.PeerTextMention)] as? String {
showMentionActionSheet(mention)
}
}
self.contentTextNode.longTapAttributeAction = { [weak self] attributes, _ in
guard let strongSelf = self else {
return
}
if let url = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.URL)] as? String {
let actionSheet = ActionSheetController(presentationData: strongSelf.presentationData)
actionSheet.setItemGroups([ActionSheetItemGroup(items: [
ActionSheetTextItem(title: url),
ActionSheetButtonItem(title: strongSelf.presentationData.strings.Conversation_LinkDialogOpen, color: .accent, action: { [weak actionSheet] in
actionSheet?.dismissAnimated()
self?.openUrl(url)
}),
ActionSheetButtonItem(title: strongSelf.presentationData.strings.Conversation_LinkDialogCopy, color: .accent, action: { [weak actionSheet, weak self] in
actionSheet?.dismissAnimated()
UIPasteboard.general.string = url
if let strongSelf = self {
strongSelf.present(UndoOverlayController(presentationData: strongSelf.presentationData, content: .linkCopied(title: nil, text: strongSelf.presentationData.strings.Conversation_LinkCopied), elevatedLayout: false, animateInAsReplacement: false, action: { _ in return false }), nil)
}
})
]), ActionSheetItemGroup(items: [
ActionSheetButtonItem(title: strongSelf.presentationData.strings.Common_Cancel, color: .accent, font: .bold, action: { [weak actionSheet] in
actionSheet?.dismissAnimated()
})
])])
strongSelf.present(actionSheet, nil)
} else if let mention = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.PeerMention)] as? TelegramPeerMention {
showMentionActionSheet(mention.mention)
} else if let mention = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.PeerTextMention)] as? String {
showMentionActionSheet(mention)
}
}
}
deinit {
}
func containerLayoutUpdated(_ layout: ContainerViewLayout, navigationBarHeight: CGFloat, transition: ContainedViewLayoutTransition) {
self.containerLayout = (layout, navigationBarHeight)
var insets = layout.insets(options: [])
insets.top += navigationBarHeight
let toolbarHeight: CGFloat = 44.0
insets.bottom += layout.safeInsets.bottom
let toolbarFrame = CGRect(origin: CGPoint(x: 0.0, y: layout.size.height - insets.bottom - toolbarHeight), size: CGSize(width: layout.size.width, height: insets.bottom + toolbarHeight))
insets.bottom += toolbarHeight
transition.updateFrame(node: self.toolbarNode, frame: toolbarFrame)
transition.updateFrame(node: self.toolbarSeparatorNode, frame: CGRect(origin: CGPoint(x: 0.0, y: toolbarFrame.minY), size: CGSize(width: toolbarFrame.width, height: UIScreenPixel)))
let leftActionSize = self.leftActionTextNode.updateLayout(CGSize(width: floor(layout.size.width / 2.0), height: CGFloat.greatestFiniteMagnitude))
let rightActionSize = self.rightActionTextNode.updateLayout(CGSize(width: floor(layout.size.width / 2.0), height: CGFloat.greatestFiniteMagnitude))
let leftActionTextFrame = CGRect(origin: CGPoint(x: layout.safeInsets.left + 15.0, y: toolbarFrame.minY + floor((toolbarHeight - leftActionSize.height) / 2.0)), size: leftActionSize)
let rightActionTextFrame = CGRect(origin: CGPoint(x: layout.size.width - layout.safeInsets.left - 15.0 - rightActionSize.width, y: toolbarFrame.minY + floor((toolbarHeight - rightActionSize.height) / 2.0)), size: rightActionSize)
transition.updateFrame(node: self.leftActionTextNode, frame: leftActionTextFrame)
transition.updateFrame(node: self.rightActionTextNode, frame: rightActionTextFrame)
self.leftActionNode.frame = CGRect(origin: CGPoint(x: 0.0, y: toolbarFrame.minY), size: CGSize(width: leftActionTextFrame.maxX + 15.0, height: toolbarHeight))
self.rightActionNode.frame = CGRect(origin: CGPoint(x: rightActionTextFrame.minX - 15.0, y: toolbarFrame.minY), size: CGSize(width: layout.size.width - (rightActionTextFrame.minX - 15.0), height: toolbarHeight))
let scrollFrame = CGRect(origin: CGPoint(x: 0.0, y: insets.top), size: CGSize(width: layout.size.width, height: layout.size.height - insets.top - insets.bottom))
transition.updateFrame(node: self.scrollNode, frame: scrollFrame)
let containerInset: CGFloat = 32.0
let contentInsets = UIEdgeInsets(top: 15.0, left: 15.0 + layout.safeInsets.left, bottom: 15.0, right: 15.0 + layout.safeInsets.right)
let contentSize = self.contentTextNode.updateLayout(CGSize(width: layout.size.width - contentInsets.left - contentInsets.right, height: CGFloat.greatestFiniteMagnitude))
let contentFrame = CGRect(origin: CGPoint(x: 0.0, y: containerInset), size: CGSize(width: layout.size.width, height: contentSize.height + contentInsets.top + contentInsets.bottom))
self.contentTextNode.frame = CGRect(origin: CGPoint(x: contentFrame.minX + contentInsets.left, y: contentFrame.minY + contentInsets.top), size: contentSize)
self.contentBackgroundNode.frame = contentFrame
self.scrollNode.view.contentSize = CGSize(width: layout.size.width, height: containerInset + contentFrame.height + containerInset)
}
func scrollToTop() {
self.scrollNode.view.scrollRectToVisible(CGRect(origin: CGPoint(), size: CGSize()), animated: true)
}
func animateIn() {
self.layer.animatePosition(from: CGPoint(x: self.layer.position.x, y: self.layer.position.y + self.layer.bounds.size.height), to: self.layer.position, duration: 0.5, timingFunction: kCAMediaTimingFunctionSpring)
}
func animateOut(completion: (() -> Void)? = nil) {
self.layer.animatePosition(from: self.layer.position, to: CGPoint(x: self.layer.position.x, y: self.layer.position.y + self.layer.bounds.size.height), duration: 0.2, timingFunction: CAMediaTimingFunctionName.easeInEaseOut.rawValue, removeOnCompletion: false, completion: { _ in
completion?()
})
}
@objc private func leftActionPressed() {
self.leftAction()
}
@objc private func rightActionPressed() {
self.rightAction()
}
}