mirror of
https://github.com/ichmagmaus111/ghostgram.git
synced 2026-08-20 04:47:15 +02:00
chore: migrate to new version + fixed several critical bugs
- Migrated project to latest Telegram iOS base (v12.3.2+) - Fixed circular dependency between GhostModeManager and MiscSettingsManager - Fixed multiple Bazel build configuration errors (select() default conditions) - Fixed duplicate type definitions in PeerInfoScreen - Fixed swiftmodule directory resolution in build scripts - Added Ghostgram Settings tab in main Settings menu with all 5 features - Cleared sensitive credentials from config.json (template-only now) - Excluded bazel-cache from version control
This commit is contained in:
@@ -3,285 +3,13 @@ import UIKit
|
||||
import SwiftSignalKit
|
||||
import AsyncDisplayKit
|
||||
import Display
|
||||
import ComponentFlow
|
||||
import Postbox
|
||||
import TelegramCore
|
||||
import TelegramPresentationData
|
||||
import TelegramVoip
|
||||
import AccountContext
|
||||
import AppBundle
|
||||
|
||||
private final class CallRatingAlertContentNode: AlertContentNode {
|
||||
private let strings: PresentationStrings
|
||||
private let apply: (Int) -> Void
|
||||
|
||||
var rating: Int?
|
||||
|
||||
private let titleNode: ASTextNode
|
||||
private var starContainerNode: ASDisplayNode
|
||||
private let starNodes: [ASButtonNode]
|
||||
|
||||
private let actionNodesSeparator: ASDisplayNode
|
||||
private let actionNodes: [TextAlertContentActionNode]
|
||||
private let actionVerticalSeparators: [ASDisplayNode]
|
||||
|
||||
private let disposable = MetaDisposable()
|
||||
|
||||
private var validLayout: CGSize?
|
||||
|
||||
override var dismissOnOutsideTap: Bool {
|
||||
return self.isUserInteractionEnabled
|
||||
}
|
||||
|
||||
init(theme: AlertControllerTheme, ptheme: PresentationTheme, strings: PresentationStrings, actions: [TextAlertAction], dismiss: @escaping () -> Void, apply: @escaping (Int) -> Void) {
|
||||
self.strings = strings
|
||||
self.apply = apply
|
||||
|
||||
self.titleNode = ASTextNode()
|
||||
self.titleNode.maximumNumberOfLines = 3
|
||||
|
||||
self.starContainerNode = ASDisplayNode()
|
||||
|
||||
var starNodes: [ASButtonNode] = []
|
||||
for _ in 0 ..< 5 {
|
||||
starNodes.append(ASButtonNode())
|
||||
}
|
||||
self.starNodes = starNodes
|
||||
|
||||
self.actionNodesSeparator = ASDisplayNode()
|
||||
self.actionNodesSeparator.isLayerBacked = true
|
||||
|
||||
self.actionNodes = actions.map { action -> TextAlertContentActionNode in
|
||||
return TextAlertContentActionNode(theme: theme, action: action)
|
||||
}
|
||||
|
||||
var actionVerticalSeparators: [ASDisplayNode] = []
|
||||
if actions.count > 1 {
|
||||
for _ in 0 ..< actions.count - 1 {
|
||||
let separatorNode = ASDisplayNode()
|
||||
separatorNode.isLayerBacked = true
|
||||
actionVerticalSeparators.append(separatorNode)
|
||||
}
|
||||
}
|
||||
self.actionVerticalSeparators = actionVerticalSeparators
|
||||
|
||||
super.init()
|
||||
|
||||
self.addSubnode(self.titleNode)
|
||||
|
||||
self.addSubnode(self.starContainerNode)
|
||||
|
||||
for node in self.starNodes {
|
||||
node.addTarget(self, action: #selector(self.starPressed(_:)), forControlEvents: .touchDown)
|
||||
node.addTarget(self, action: #selector(self.starReleased(_:)), forControlEvents: .touchUpInside)
|
||||
self.starContainerNode.addSubnode(node)
|
||||
}
|
||||
|
||||
self.addSubnode(self.actionNodesSeparator)
|
||||
|
||||
for actionNode in self.actionNodes {
|
||||
self.addSubnode(actionNode)
|
||||
}
|
||||
|
||||
for separatorNode in self.actionVerticalSeparators {
|
||||
self.addSubnode(separatorNode)
|
||||
}
|
||||
|
||||
self.updateTheme(theme)
|
||||
}
|
||||
|
||||
deinit {
|
||||
self.disposable.dispose()
|
||||
}
|
||||
|
||||
override func didLoad() {
|
||||
super.didLoad()
|
||||
|
||||
self.starContainerNode.view.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(self.panGesture(_:))))
|
||||
}
|
||||
|
||||
@objc func panGesture(_ gestureRecognizer: UIPanGestureRecognizer) {
|
||||
let location = gestureRecognizer.location(in: self.starContainerNode.view)
|
||||
var selectedNode: ASButtonNode?
|
||||
for node in self.starNodes {
|
||||
if node.frame.contains(location) {
|
||||
selectedNode = node
|
||||
break
|
||||
}
|
||||
}
|
||||
if let selectedNode = selectedNode {
|
||||
switch gestureRecognizer.state {
|
||||
case .began, .changed:
|
||||
self.starPressed(selectedNode)
|
||||
case .ended:
|
||||
self.starReleased(selectedNode)
|
||||
case .cancelled:
|
||||
self.resetStars()
|
||||
default:
|
||||
break
|
||||
}
|
||||
} else {
|
||||
self.resetStars()
|
||||
}
|
||||
}
|
||||
|
||||
private func resetStars() {
|
||||
for i in 0 ..< self.starNodes.count {
|
||||
let node = self.starNodes[i]
|
||||
node.isSelected = false
|
||||
}
|
||||
}
|
||||
|
||||
@objc func starPressed(_ sender: ASButtonNode) {
|
||||
if let index = self.starNodes.firstIndex(of: sender) {
|
||||
self.rating = index + 1
|
||||
for i in 0 ..< self.starNodes.count {
|
||||
let node = self.starNodes[i]
|
||||
node.isSelected = i <= index
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc func starReleased(_ sender: ASButtonNode) {
|
||||
if let index = self.starNodes.firstIndex(of: sender) {
|
||||
self.rating = index + 1
|
||||
for i in 0 ..< self.starNodes.count {
|
||||
let node = self.starNodes[i]
|
||||
node.isSelected = i <= index
|
||||
}
|
||||
if let rating = self.rating {
|
||||
self.apply(rating)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override func updateTheme(_ theme: AlertControllerTheme) {
|
||||
self.titleNode.attributedText = NSAttributedString(string: self.strings.Calls_RatingTitle, font: Font.bold(17.0), textColor: theme.primaryColor, paragraphAlignment: .center)
|
||||
|
||||
for node in self.starNodes {
|
||||
node.setImage(generateTintedImage(image: UIImage(bundleImageName: "Call/Star"), color: theme.accentColor), for: [])
|
||||
let highlighted = generateTintedImage(image: UIImage(bundleImageName: "Call/StarHighlighted"), color: theme.accentColor)
|
||||
node.setImage(highlighted, for: [.selected])
|
||||
node.setImage(highlighted, for: [.selected, .highlighted])
|
||||
}
|
||||
|
||||
self.actionNodesSeparator.backgroundColor = theme.separatorColor
|
||||
for actionNode in self.actionNodes {
|
||||
actionNode.updateTheme(theme)
|
||||
}
|
||||
for separatorNode in self.actionVerticalSeparators {
|
||||
separatorNode.backgroundColor = theme.separatorColor
|
||||
}
|
||||
|
||||
if let size = self.validLayout {
|
||||
_ = self.updateLayout(size: size, transition: .immediate)
|
||||
}
|
||||
}
|
||||
|
||||
override func updateLayout(size: CGSize, transition: ContainedViewLayoutTransition) -> CGSize {
|
||||
var size = size
|
||||
size.width = min(size.width , 270.0)
|
||||
|
||||
self.validLayout = size
|
||||
|
||||
let actionButtonHeight: CGFloat = 44.0
|
||||
var minActionsWidth: CGFloat = 0.0
|
||||
let maxActionWidth: CGFloat = floor(size.width / CGFloat(self.actionNodes.count))
|
||||
let actionTitleInsets: CGFloat = 8.0
|
||||
|
||||
var effectiveActionLayout = TextAlertContentActionLayout.horizontal
|
||||
for actionNode in self.actionNodes {
|
||||
let actionTitleSize = actionNode.titleNode.updateLayout(CGSize(width: maxActionWidth, height: actionButtonHeight))
|
||||
if case .horizontal = effectiveActionLayout, actionTitleSize.height > actionButtonHeight * 0.6667 {
|
||||
effectiveActionLayout = .vertical
|
||||
}
|
||||
switch effectiveActionLayout {
|
||||
case .horizontal:
|
||||
minActionsWidth += actionTitleSize.width + actionTitleInsets
|
||||
case .vertical:
|
||||
minActionsWidth = max(minActionsWidth, actionTitleSize.width + actionTitleInsets)
|
||||
}
|
||||
}
|
||||
|
||||
let insets = UIEdgeInsets(top: 18.0, left: 18.0, bottom: 18.0, right: 18.0)
|
||||
|
||||
var origin: CGPoint = CGPoint(x: 0.0, y: 20.0)
|
||||
let titleSize = self.titleNode.measure(CGSize(width: size.width - 32.0, height: size.height))
|
||||
|
||||
var contentWidth = max(titleSize.width, minActionsWidth)
|
||||
contentWidth = max(contentWidth, 234.0)
|
||||
|
||||
var actionsHeight: CGFloat = 0.0
|
||||
switch effectiveActionLayout {
|
||||
case .horizontal:
|
||||
actionsHeight = actionButtonHeight
|
||||
case .vertical:
|
||||
actionsHeight = actionButtonHeight * CGFloat(self.actionNodes.count)
|
||||
}
|
||||
|
||||
let resultWidth = contentWidth + insets.left + insets.right
|
||||
|
||||
transition.updateFrame(node: self.titleNode, frame: CGRect(origin: CGPoint(x: floorToScreenPixels((resultWidth - titleSize.width) / 2.0), y: origin.y), size: titleSize))
|
||||
origin.y += titleSize.height + 13.0
|
||||
|
||||
let starSize = CGSize(width: 42.0, height: 38.0)
|
||||
let starsOrigin = floorToScreenPixels((resultWidth - starSize.width * 5.0) / 2.0)
|
||||
self.starContainerNode.frame = CGRect(origin: CGPoint(x: starsOrigin, y: origin.y), size: CGSize(width: starSize.width * CGFloat(self.starNodes.count), height: starSize.height))
|
||||
for i in 0 ..< self.starNodes.count {
|
||||
let node = self.starNodes[i]
|
||||
transition.updateFrame(node: node, frame: CGRect(x: starSize.width * CGFloat(i), y: 0.0, width: starSize.width, height: starSize.height))
|
||||
}
|
||||
origin.y += titleSize.height
|
||||
|
||||
let resultSize = CGSize(width: resultWidth, height: titleSize.height + actionsHeight + 56.0 + insets.top + insets.bottom)
|
||||
|
||||
transition.updateFrame(node: self.actionNodesSeparator, frame: CGRect(origin: CGPoint(x: 0.0, y: resultSize.height - actionsHeight - UIScreenPixel), size: CGSize(width: resultSize.width, height: UIScreenPixel)))
|
||||
|
||||
var actionOffset: CGFloat = 0.0
|
||||
let actionWidth: CGFloat = floor(resultSize.width / CGFloat(self.actionNodes.count))
|
||||
var separatorIndex = -1
|
||||
var nodeIndex = 0
|
||||
for actionNode in self.actionNodes {
|
||||
if separatorIndex >= 0 {
|
||||
let separatorNode = self.actionVerticalSeparators[separatorIndex]
|
||||
switch effectiveActionLayout {
|
||||
case .horizontal:
|
||||
transition.updateFrame(node: separatorNode, frame: CGRect(origin: CGPoint(x: actionOffset - UIScreenPixel, y: resultSize.height - actionsHeight), size: CGSize(width: UIScreenPixel, height: actionsHeight - UIScreenPixel)))
|
||||
case .vertical:
|
||||
transition.updateFrame(node: separatorNode, frame: CGRect(origin: CGPoint(x: 0.0, y: resultSize.height - actionsHeight + actionOffset - UIScreenPixel), size: CGSize(width: resultSize.width, height: UIScreenPixel)))
|
||||
}
|
||||
}
|
||||
separatorIndex += 1
|
||||
|
||||
let currentActionWidth: CGFloat
|
||||
switch effectiveActionLayout {
|
||||
case .horizontal:
|
||||
if nodeIndex == self.actionNodes.count - 1 {
|
||||
currentActionWidth = resultSize.width - actionOffset
|
||||
} else {
|
||||
currentActionWidth = actionWidth
|
||||
}
|
||||
case .vertical:
|
||||
currentActionWidth = resultSize.width
|
||||
}
|
||||
|
||||
let actionNodeFrame: CGRect
|
||||
switch effectiveActionLayout {
|
||||
case .horizontal:
|
||||
actionNodeFrame = CGRect(origin: CGPoint(x: actionOffset, y: resultSize.height - actionsHeight), size: CGSize(width: currentActionWidth, height: actionButtonHeight))
|
||||
actionOffset += currentActionWidth
|
||||
case .vertical:
|
||||
actionNodeFrame = CGRect(origin: CGPoint(x: 0.0, y: resultSize.height - actionsHeight + actionOffset), size: CGSize(width: currentActionWidth, height: actionButtonHeight))
|
||||
actionOffset += actionButtonHeight
|
||||
}
|
||||
|
||||
transition.updateFrame(node: actionNode, frame: actionNodeFrame)
|
||||
|
||||
nodeIndex += 1
|
||||
}
|
||||
|
||||
return resultSize
|
||||
}
|
||||
}
|
||||
import AlertComponent
|
||||
|
||||
func rateCallAndSendLogs(engine: TelegramEngine, callId: CallId, starsCount: Int, comment: String, userInitiated: Bool, includeLogs: Bool) -> Signal<Void, NoError> {
|
||||
let peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(4244000))
|
||||
@@ -309,35 +37,199 @@ func rateCallAndSendLogs(engine: TelegramEngine, callId: CallId, starsCount: Int
|
||||
}
|
||||
}
|
||||
|
||||
public func callRatingController(sharedContext: SharedAccountContext, account: Account, callId: CallId, userInitiated: Bool, isVideo: Bool, present: @escaping (ViewController, Any) -> Void, push: @escaping (ViewController) -> Void) -> AlertController {
|
||||
let presentationData = sharedContext.currentPresentationData.with { $0 }
|
||||
let theme = presentationData.theme
|
||||
let strings = presentationData.strings
|
||||
public func callRatingController(
|
||||
sharedContext: SharedAccountContext,
|
||||
account: Account,
|
||||
callId: CallId,
|
||||
userInitiated: Bool,
|
||||
isVideo: Bool,
|
||||
present: @escaping (ViewController, Any) -> Void,
|
||||
push: @escaping (ViewController) -> Void
|
||||
) -> ViewController {
|
||||
let strings = sharedContext.currentPresentationData.with { $0 }.strings
|
||||
|
||||
var dismissImpl: ((Bool) -> Void)?
|
||||
var contentNode: CallRatingAlertContentNode?
|
||||
let actions: [TextAlertAction] = [TextAlertAction(type: .genericAction, title: presentationData.strings.Common_NotNow, action: {
|
||||
dismissImpl?(true)
|
||||
})]
|
||||
var dismissImpl: (() -> Void)?
|
||||
|
||||
contentNode = CallRatingAlertContentNode(theme: AlertControllerTheme(presentationData: presentationData), ptheme: theme, strings: strings, actions: actions, dismiss: {
|
||||
dismissImpl?(true)
|
||||
}, apply: { rating in
|
||||
dismissImpl?(true)
|
||||
if rating < 4 {
|
||||
push(callFeedbackController(sharedContext: sharedContext, account: account, callId: callId, rating: rating, userInitiated: userInitiated, isVideo: isVideo))
|
||||
} else {
|
||||
let _ = rateCallAndSendLogs(engine: TelegramEngine(account: account), callId: callId, starsCount: rating, comment: "", userInitiated: userInitiated, includeLogs: false).start()
|
||||
var content: [AnyComponentWithIdentity<AlertComponentEnvironment>] = []
|
||||
content.append(AnyComponentWithIdentity(
|
||||
id: "title",
|
||||
component: AnyComponent(
|
||||
AlertTitleComponent(
|
||||
title: strings.Calls_RatingTitle,
|
||||
alignment: .center
|
||||
)
|
||||
)
|
||||
))
|
||||
content.append(AnyComponentWithIdentity(
|
||||
id: "stars",
|
||||
component: AnyComponent(
|
||||
AlertCallRatingComponent(completion: { rating in
|
||||
dismissImpl?()
|
||||
if rating < 4 {
|
||||
push(callFeedbackController(sharedContext: sharedContext, account: account, callId: callId, rating: rating, userInitiated: userInitiated, isVideo: isVideo))
|
||||
} else {
|
||||
let _ = rateCallAndSendLogs(engine: TelegramEngine(account: account), callId: callId, starsCount: rating, comment: "", userInitiated: userInitiated, includeLogs: false).start()
|
||||
}
|
||||
})
|
||||
)
|
||||
))
|
||||
|
||||
let alertController = AlertScreen(
|
||||
sharedContext: sharedContext,
|
||||
content: content,
|
||||
actions: [
|
||||
.init(title: strings.Common_NotNow)
|
||||
]
|
||||
)
|
||||
|
||||
dismissImpl = { [weak alertController] in
|
||||
alertController?.dismiss(completion: nil)
|
||||
}
|
||||
|
||||
return alertController
|
||||
}
|
||||
|
||||
private final class AlertCallRatingComponent: Component {
|
||||
public typealias EnvironmentType = AlertComponentEnvironment
|
||||
|
||||
private let completion: (Int) -> Void
|
||||
|
||||
public init(completion: @escaping (Int) -> Void) {
|
||||
self.completion = completion
|
||||
}
|
||||
|
||||
public static func ==(lhs: AlertCallRatingComponent, rhs: AlertCallRatingComponent) -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
public final class View: UIView {
|
||||
private var containerView: UIView
|
||||
private let starButtons: [HighlightTrackingButton]
|
||||
|
||||
var rating: Int?
|
||||
|
||||
private var component: AlertCallRatingComponent?
|
||||
private weak var state: EmptyComponentState?
|
||||
|
||||
public override init(frame: CGRect) {
|
||||
self.containerView = UIView()
|
||||
|
||||
var starButtons: [HighlightTrackingButton] = []
|
||||
for _ in 0 ..< 5 {
|
||||
starButtons.append(HighlightTrackingButton())
|
||||
}
|
||||
self.starButtons = starButtons
|
||||
|
||||
super.init(frame: frame)
|
||||
|
||||
self.addSubview(self.containerView)
|
||||
|
||||
for button in self.starButtons {
|
||||
button.addTarget(self, action: #selector(self.starPressed(_:)), for: .touchDown)
|
||||
button.addTarget(self, action: #selector(self.starReleased(_:)), for: .touchUpInside)
|
||||
self.containerView.addSubview(button)
|
||||
}
|
||||
|
||||
self.containerView.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(self.panGesture(_:))))
|
||||
}
|
||||
})
|
||||
|
||||
let controller = AlertController(theme: AlertControllerTheme(presentationData: presentationData), contentNode: contentNode!)
|
||||
dismissImpl = { [weak controller] animated in
|
||||
if animated {
|
||||
controller?.dismissAnimated()
|
||||
} else {
|
||||
controller?.dismiss()
|
||||
|
||||
public required init?(coder: NSCoder) {
|
||||
preconditionFailure()
|
||||
}
|
||||
|
||||
@objc func panGesture(_ gestureRecognizer: UIPanGestureRecognizer) {
|
||||
let location = gestureRecognizer.location(in: self.containerView)
|
||||
var selectedButton: HighlightTrackingButton?
|
||||
for button in self.starButtons {
|
||||
if button.frame.contains(location) {
|
||||
selectedButton = button
|
||||
break
|
||||
}
|
||||
}
|
||||
if let selectedButton = selectedButton {
|
||||
switch gestureRecognizer.state {
|
||||
case .began, .changed:
|
||||
self.starPressed(selectedButton)
|
||||
case .ended:
|
||||
self.starReleased(selectedButton)
|
||||
case .cancelled:
|
||||
self.resetStars()
|
||||
default:
|
||||
break
|
||||
}
|
||||
} else {
|
||||
self.resetStars()
|
||||
}
|
||||
}
|
||||
|
||||
private func resetStars() {
|
||||
for i in 0 ..< self.starButtons.count {
|
||||
let node = self.starButtons[i]
|
||||
node.isSelected = false
|
||||
}
|
||||
}
|
||||
|
||||
@objc func starPressed(_ sender: HighlightTrackingButton) {
|
||||
if let index = self.starButtons.firstIndex(of: sender) {
|
||||
self.rating = index + 1
|
||||
for i in 0 ..< self.starButtons.count {
|
||||
let node = self.starButtons[i]
|
||||
node.isSelected = i <= index
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc func starReleased(_ sender: HighlightTrackingButton) {
|
||||
guard let component = self.component else {
|
||||
return
|
||||
}
|
||||
if let index = self.starButtons.firstIndex(of: sender) {
|
||||
self.rating = index + 1
|
||||
for i in 0 ..< self.starButtons.count {
|
||||
let node = self.starButtons[i]
|
||||
node.isSelected = i <= index
|
||||
}
|
||||
if let rating = self.rating {
|
||||
component.completion(rating)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func update(component: AlertCallRatingComponent, availableSize: CGSize, state: EmptyComponentState, environment: Environment<AlertComponentEnvironment>, transition: ComponentTransition) -> CGSize {
|
||||
if self.component == nil {
|
||||
for i in 0 ..< self.starButtons.count {
|
||||
let button = self.starButtons[i]
|
||||
button.setImage(UIImage(bundleImageName: "Call/Star")?.withRenderingMode(.alwaysTemplate), for: .normal)
|
||||
button.setImage(UIImage(bundleImageName: "Call/StarHighlighted")?.withRenderingMode(.alwaysTemplate), for: .selected)
|
||||
button.setImage(UIImage(bundleImageName: "Call/StarHighlighted")?.withRenderingMode(.alwaysTemplate), for: [.selected, .highlighted])
|
||||
}
|
||||
}
|
||||
|
||||
self.component = component
|
||||
self.state = state
|
||||
|
||||
let environment = environment[AlertComponentEnvironment.self]
|
||||
|
||||
let buttonCount = CGFloat(self.starButtons.count)
|
||||
let starSize = CGSize(width: 42.0, height: 38.0)
|
||||
let starsOrigin = floorToScreenPixels((availableSize.width - starSize.width * buttonCount) / 2.0)
|
||||
self.containerView.frame = CGRect(origin: CGPoint(x: starsOrigin, y: 0.0), size: CGSize(width: starSize.width * buttonCount, height: starSize.height))
|
||||
for i in 0 ..< self.starButtons.count {
|
||||
let button = self.starButtons[i]
|
||||
button.imageView?.tintColor = environment.theme.actionSheet.controlAccentColor
|
||||
|
||||
transition.setFrame(view: button, frame: CGRect(x: starSize.width * CGFloat(i), y: 0.0, width: starSize.width, height: starSize.height))
|
||||
}
|
||||
|
||||
return CGSize(width: availableSize.width, height: 38.0)
|
||||
}
|
||||
}
|
||||
return controller
|
||||
|
||||
public func makeView() -> View {
|
||||
return View(frame: CGRect())
|
||||
}
|
||||
|
||||
public func update(view: View, availableSize: CGSize, state: EmptyComponentState, environment: Environment<AlertComponentEnvironment>, transition: ComponentTransition) -> CGSize {
|
||||
return view.update(component: self, availableSize: availableSize, state: state, environment: environment, transition: transition)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user