mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Invite Links Fixes
This commit is contained in:
parent
656f4899c2
commit
e6218f11f4
@ -6077,3 +6077,5 @@ Sorry for the inconvenience.";
|
||||
|
||||
"Channel.AdminLog.MessageChangedAutoremoveTimeoutSet" = "%1$@ set auto-remove timer to %2$@";
|
||||
"Channel.AdminLog.MessageChangedAutoremoveTimeoutRemove" = "%1$@ disabled auto-remove timer";
|
||||
|
||||
"ChannelInfo.InviteLink.RevokeAlert.Text" = "Are you sure you want to revoke this link? Once you do, no one will be able to join the channel using it.";
|
||||
|
@ -179,7 +179,7 @@ private final class InnerActionsContainerNode: ASDisplayNode {
|
||||
if self.effectView == nil {
|
||||
let effectView: UIVisualEffectView
|
||||
if #available(iOS 13.0, *) {
|
||||
if self.presentationData.theme.overallDarkAppearance {
|
||||
if self.presentationData.theme.rootController.keyboardColor == .dark {
|
||||
effectView = UIVisualEffectView(effect: UIBlurEffect(style: .systemMaterialDark))
|
||||
} else {
|
||||
effectView = UIVisualEffectView(effect: UIBlurEffect(style: .systemMaterialLight))
|
||||
|
@ -578,7 +578,7 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi
|
||||
let propertyAnimator = propertyAnimator as? UIViewPropertyAnimator
|
||||
propertyAnimator?.stopAnimation(true)
|
||||
}
|
||||
self.effectView.effect = makeCustomZoomBlurEffect(isLight: !self.presentationData.theme.overallDarkAppearance)
|
||||
self.effectView.effect = makeCustomZoomBlurEffect(isLight: presentationData.theme.rootController.keyboardColor == .light)
|
||||
self.effectView.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2 * animationDurationFactor)
|
||||
self.propertyAnimator = UIViewPropertyAnimator(duration: 0.2 * animationDurationFactor * UIView.animationDurationFactor(), curve: .easeInOut, animations: {
|
||||
})
|
||||
@ -596,7 +596,7 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi
|
||||
}
|
||||
} else {
|
||||
UIView.animate(withDuration: 0.2 * animationDurationFactor, animations: {
|
||||
self.effectView.effect = makeCustomZoomBlurEffect(isLight: !self.presentationData.theme.overallDarkAppearance)
|
||||
self.effectView.effect = makeCustomZoomBlurEffect(isLight: self.presentationData.theme.rootController.keyboardColor == .light)
|
||||
}, completion: { [weak self] _ in
|
||||
self?.didCompleteAnimationIn = true
|
||||
self?.actionsContainerNode.animateIn()
|
||||
@ -1106,7 +1106,7 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi
|
||||
propertyAnimator?.stopAnimation(true)
|
||||
}
|
||||
}
|
||||
self.effectView.effect = makeCustomZoomBlurEffect(isLight: !self.presentationData.theme.overallDarkAppearance)
|
||||
self.effectView.effect = makeCustomZoomBlurEffect(isLight: presentationData.theme.rootController.keyboardColor == .light)
|
||||
self.dimNode.alpha = 1.0
|
||||
}
|
||||
self.dimNode.isHidden = false
|
||||
|
@ -12,6 +12,7 @@ swift_library(
|
||||
"//submodules/TelegramPresentationData:TelegramPresentationData",
|
||||
"//submodules/TelegramStringFormatting:TelegramStringFormatting",
|
||||
"//submodules/SegmentedControlNode:SegmentedControlNode",
|
||||
"//submodules/DirectionalPanGesture:DirectionalPanGesture",
|
||||
],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
|
@ -5,6 +5,7 @@ import AsyncDisplayKit
|
||||
import TelegramPresentationData
|
||||
import TelegramStringFormatting
|
||||
import SegmentedControlNode
|
||||
import DirectionalPanGesture
|
||||
|
||||
public final class DatePickerTheme: Equatable {
|
||||
public let backgroundColor: UIColor
|
||||
@ -69,7 +70,11 @@ private let dayFont = Font.regular(13.0)
|
||||
private let dateFont = Font.with(size: 17.0, design: .regular, traits: .monospacedNumbers)
|
||||
private let selectedDateFont = Font.with(size: 17.0, design: .regular, traits: [.bold, .monospacedNumbers])
|
||||
|
||||
private let calendar = Calendar(identifier: .gregorian)
|
||||
private var calendar: Calendar = {
|
||||
var calendar = Calendar(identifier: .gregorian)
|
||||
calendar.locale = Locale.current
|
||||
return calendar
|
||||
}()
|
||||
|
||||
private func monthForDate(_ date: Date) -> Date {
|
||||
var components = calendar.dateComponents([.year, .month], from: date)
|
||||
@ -300,9 +305,6 @@ public final class DatePickerNode: ASDisplayNode {
|
||||
|
||||
private var transitionFraction: CGFloat = 0.0
|
||||
|
||||
private var gestureRecognizer: UIPanGestureRecognizer?
|
||||
private var gestureSelectedIndex: Int?
|
||||
|
||||
private var validLayout: CGSize?
|
||||
|
||||
public var valueUpdated: ((Date) -> Void)?
|
||||
@ -479,7 +481,10 @@ public final class DatePickerNode: ASDisplayNode {
|
||||
|
||||
self.view.disablesInteractiveTransitionGestureRecognizer = true
|
||||
|
||||
self.contentNode.view.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(self.panGesture(_:))))
|
||||
let panGesture = DirectionalPanGestureRecognizer(target: self, action: #selector(self.panGesture(_:)))
|
||||
panGesture.direction = .horizontal
|
||||
|
||||
self.contentNode.view.addGestureRecognizer(panGesture)
|
||||
self.contentNode.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.tapGesture(_:))))
|
||||
}
|
||||
|
||||
@ -499,6 +504,7 @@ public final class DatePickerNode: ASDisplayNode {
|
||||
}
|
||||
}
|
||||
self.pickerNode.date = self.state.date
|
||||
self.timePickerNode.date = self.state.date
|
||||
|
||||
if let size = self.validLayout {
|
||||
self.updateLayout(size: size, transition: animated ? .animated(duration: 0.3, curve: .spring) : .immediate)
|
||||
@ -714,15 +720,17 @@ public final class DatePickerNode: ASDisplayNode {
|
||||
let daysSideInset: CGFloat = 12.0
|
||||
let cellSize: CGFloat = floor((size.width - daysSideInset * 2.0) / 7.0)
|
||||
|
||||
var dayIndex: Int32 = Int32(calendar.firstWeekday) - 1
|
||||
for i in 0 ..< self.dayNodes.count {
|
||||
let dayNode = self.dayNodes[i]
|
||||
dayNode.attributedText = NSAttributedString(string: shortStringForDayOfWeek(strings: self.strings, day: Int32(i)).uppercased(), font: dayFont, textColor: theme.secondaryTextColor)
|
||||
dayNode.attributedText = NSAttributedString(string: shortStringForDayOfWeek(strings: self.strings, day: dayIndex % 7).uppercased(), font: dayFont, textColor: theme.secondaryTextColor)
|
||||
|
||||
let textSize = dayNode.updateLayout(size)
|
||||
let cellFrame = CGRect(x: daysSideInset + CGFloat(i) * cellSize, y: topInset - 38.0, width: cellSize, height: cellSize)
|
||||
let textFrame = CGRect(origin: CGPoint(x: cellFrame.minX + floor((cellFrame.width - textSize.width) / 2.0), y: cellFrame.minY + floor((cellFrame.height - textSize.height) / 2.0)), size: textSize)
|
||||
|
||||
dayNode.frame = textFrame
|
||||
dayIndex += 1
|
||||
}
|
||||
|
||||
let containerSize = CGSize(width: size.width, height: size.height - topInset)
|
||||
@ -887,20 +895,124 @@ private final class MonthPickerNode: ASDisplayNode, UIPickerViewDelegate, UIPick
|
||||
}
|
||||
}
|
||||
|
||||
private class TimeInputView: UIView, UIKeyInput {
|
||||
override var canBecomeFirstResponder: Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
var keyboardType: UIKeyboardType = .numberPad
|
||||
|
||||
var text: String = ""
|
||||
var hasText: Bool {
|
||||
return !self.text.isEmpty
|
||||
}
|
||||
|
||||
var textUpdated: ((String) -> Void)?
|
||||
|
||||
private let nonDigits = CharacterSet.decimalDigits.inverted
|
||||
func insertText(_ text: String) {
|
||||
if text.rangeOfCharacter(from: nonDigits) != nil {
|
||||
return
|
||||
}
|
||||
var updatedText = self.text
|
||||
updatedText.append(updatedText)
|
||||
updatedText = String(updatedText.suffix(4))
|
||||
self.text = updatedText
|
||||
self.textUpdated?(self.text)
|
||||
}
|
||||
|
||||
func deleteBackward() {
|
||||
var updatedText = self.text
|
||||
updatedText.removeLast()
|
||||
self.text = updatedText
|
||||
self.textUpdated?(self.text)
|
||||
}
|
||||
}
|
||||
|
||||
private class TimeInputNode: ASDisplayNode {
|
||||
var textUpdated: ((String) -> Void)? {
|
||||
didSet {
|
||||
if let view = self.view as? TimeInputView {
|
||||
view.textUpdated = self.textUpdated
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
self.setViewBlock { () -> UIView in
|
||||
return TimeInputView()
|
||||
}
|
||||
}
|
||||
|
||||
override func didLoad() {
|
||||
super.didLoad()
|
||||
|
||||
self.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.handleTap)))
|
||||
|
||||
if let view = self.view as? TimeInputView {
|
||||
view.textUpdated = self.textUpdated
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func handleTap() {
|
||||
self.view.becomeFirstResponder()
|
||||
}
|
||||
}
|
||||
|
||||
public func stringTimestamp(hours: Int32, minutes: Int32, dateTimeFormat: PresentationDateTimeFormat) -> String {
|
||||
switch dateTimeFormat.timeFormat {
|
||||
case .regular:
|
||||
let hourString: String
|
||||
if hours == 0 {
|
||||
hourString = "12"
|
||||
} else if hours > 12 {
|
||||
hourString = "\(hours - 12)"
|
||||
} else {
|
||||
hourString = "\(hours)"
|
||||
}
|
||||
|
||||
let periodString: String
|
||||
if hours >= 12 {
|
||||
periodString = "PM"
|
||||
} else {
|
||||
periodString = "AM"
|
||||
}
|
||||
if minutes >= 10 {
|
||||
return "\(hourString) \(minutes) \(periodString)"
|
||||
} else {
|
||||
return "\(hourString):0\(minutes) \(periodString)"
|
||||
}
|
||||
case .military:
|
||||
return String(format: "%02d %02d", arguments: [Int(hours), Int(minutes)])
|
||||
}
|
||||
}
|
||||
|
||||
private final class TimePickerNode: ASDisplayNode {
|
||||
private var theme: DatePickerTheme
|
||||
private let dateTimeFormat: PresentationDateTimeFormat
|
||||
|
||||
private let backgroundNode: ASDisplayNode
|
||||
private let textNode: ImmediateTextNode
|
||||
private let colonNode: ImmediateTextNode
|
||||
private let inputNode: TimeInputNode
|
||||
private let amPMSelectorNode: SegmentedControlNode
|
||||
|
||||
var date: Date
|
||||
var date: Date {
|
||||
didSet {
|
||||
if let size = self.validLayout {
|
||||
self.updateLayout(size: size)
|
||||
}
|
||||
}
|
||||
}
|
||||
var minDate: Date?
|
||||
var maxDate: Date?
|
||||
|
||||
var valueChanged: ((Date) -> Void)?
|
||||
|
||||
private var validLayout: CGSize?
|
||||
|
||||
init(theme: DatePickerTheme, dateTimeFormat: PresentationDateTimeFormat, date: Date) {
|
||||
self.theme = theme
|
||||
self.dateTimeFormat = dateTimeFormat
|
||||
@ -911,6 +1023,8 @@ private final class TimePickerNode: ASDisplayNode {
|
||||
self.backgroundNode.cornerRadius = 9.0
|
||||
|
||||
self.textNode = ImmediateTextNode()
|
||||
self.colonNode = ImmediateTextNode()
|
||||
self.inputNode = TimeInputNode()
|
||||
|
||||
let hours = calendar.component(.hour, from: date)
|
||||
|
||||
@ -920,6 +1034,8 @@ private final class TimePickerNode: ASDisplayNode {
|
||||
|
||||
self.addSubnode(self.backgroundNode)
|
||||
self.addSubnode(self.textNode)
|
||||
// self.addSubnode(self.colonNode)
|
||||
// self.addSubnode(self.inputNode)
|
||||
self.addSubnode(self.amPMSelectorNode)
|
||||
|
||||
self.amPMSelectorNode.selectedIndexChanged = { index in
|
||||
@ -934,6 +1050,10 @@ private final class TimePickerNode: ASDisplayNode {
|
||||
self.valueChanged?(newDate)
|
||||
}
|
||||
}
|
||||
|
||||
self.inputNode.textUpdated = { text in
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func updateTheme(_ theme: DatePickerTheme) {
|
||||
@ -952,9 +1072,17 @@ private final class TimePickerNode: ASDisplayNode {
|
||||
let string = stringForShortTimestamp(hours: hours, minutes: minutes, dateTimeFormat: self.dateTimeFormat).replacingOccurrences(of: " AM", with: "").replacingOccurrences(of: " PM", with: "")
|
||||
|
||||
self.textNode.attributedText = NSAttributedString(string: string, font: Font.with(size: 21.0, design: .regular, weight: .regular, traits: [.monospacedNumbers]), textColor: self.theme.textColor)
|
||||
|
||||
self.colonNode.attributedText = NSAttributedString(string: ":", font: Font.with(size: 21.0, design: .regular, weight: .regular, traits: [.monospacedNumbers]), textColor: self.theme.textColor)
|
||||
|
||||
let textSize = self.textNode.updateLayout(size)
|
||||
self.textNode.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((self.backgroundNode.frame.width - textSize.width) / 2.0), y: floorToScreenPixels((self.backgroundNode.frame.height - textSize.height) / 2.0)), size: textSize)
|
||||
|
||||
let colonSize = self.colonNode.updateLayout(size)
|
||||
self.colonNode.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((self.backgroundNode.frame.width - colonSize.width) / 2.0) - 7.0, y: floorToScreenPixels((self.backgroundNode.frame.height - colonSize.height) / 2.0) - 2.0), size: colonSize)
|
||||
|
||||
self.inputNode.frame = self.backgroundNode.frame
|
||||
|
||||
if self.dateTimeFormat.timeFormat == .military {
|
||||
contentSize = self.backgroundNode.frame.size
|
||||
self.amPMSelectorNode.isHidden = true
|
||||
|
@ -2,11 +2,18 @@ import Foundation
|
||||
import UIKit
|
||||
|
||||
public class DirectionalPanGestureRecognizer: UIPanGestureRecognizer {
|
||||
public enum Direction {
|
||||
case horizontal
|
||||
case vertical
|
||||
}
|
||||
|
||||
private var validatedGesture = false
|
||||
private var firstLocation: CGPoint = CGPoint()
|
||||
|
||||
public var shouldBegin: ((CGPoint) -> Bool)?
|
||||
|
||||
public var direction: Direction = .vertical
|
||||
|
||||
override public init(target: Any?, action: Selector?) {
|
||||
super.init(target: target, action: action)
|
||||
|
||||
@ -46,10 +53,19 @@ public class DirectionalPanGestureRecognizer: UIPanGestureRecognizer {
|
||||
let absTranslationY: CGFloat = abs(translation.y)
|
||||
|
||||
if !self.validatedGesture {
|
||||
if absTranslationX > 4.0 && absTranslationX > absTranslationY * 2.0 {
|
||||
self.state = .failed
|
||||
} else if absTranslationY > 2.0 && absTranslationX * 2.0 < absTranslationY {
|
||||
self.validatedGesture = true
|
||||
switch self.direction {
|
||||
case .horizontal:
|
||||
if absTranslationY > 4.0 && absTranslationY > absTranslationX * 2.0 {
|
||||
self.state = .failed
|
||||
} else if absTranslationX > 2.0 && absTranslationY * 2.0 < absTranslationX {
|
||||
self.validatedGesture = true
|
||||
}
|
||||
case .vertical:
|
||||
if absTranslationX > 4.0 && absTranslationX > absTranslationY * 2.0 {
|
||||
self.state = .failed
|
||||
} else if absTranslationY > 2.0 && absTranslationX * 2.0 < absTranslationY {
|
||||
self.validatedGesture = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -364,42 +364,51 @@ public func inviteLinkEditController(context: AccountContext, peerId: PeerId, in
|
||||
guard let invite = invite else {
|
||||
return
|
||||
}
|
||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||
let controller = ActionSheetController(presentationData: presentationData)
|
||||
let dismissAction: () -> Void = { [weak controller] in
|
||||
controller?.dismissAnimated()
|
||||
}
|
||||
controller.setItemGroups([
|
||||
ActionSheetItemGroup(items: [
|
||||
ActionSheetTextItem(title: presentationData.strings.GroupInfo_InviteLink_RevokeAlert_Text),
|
||||
ActionSheetButtonItem(title: presentationData.strings.GroupInfo_InviteLink_RevokeLink, color: .destructive, action: {
|
||||
dismissAction()
|
||||
dismissImpl?()
|
||||
let _ = (context.account.postbox.loadedPeerWithId(peerId)
|
||||
|> deliverOnMainQueue).start(next: { peer in
|
||||
let isGroup: Bool
|
||||
if let peer = peer as? TelegramChannel, case .broadcast = peer.info {
|
||||
isGroup = false
|
||||
} else {
|
||||
isGroup = true
|
||||
}
|
||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||
let controller = ActionSheetController(presentationData: presentationData)
|
||||
let dismissAction: () -> Void = { [weak controller] in
|
||||
controller?.dismissAnimated()
|
||||
}
|
||||
controller.setItemGroups([
|
||||
ActionSheetItemGroup(items: [
|
||||
ActionSheetTextItem(title: isGroup ? presentationData.strings.GroupInfo_InviteLink_RevokeAlert_Text : presentationData.strings.ChannelInfo_InviteLink_RevokeAlert_Text),
|
||||
ActionSheetButtonItem(title: presentationData.strings.GroupInfo_InviteLink_RevokeLink, color: .destructive, action: {
|
||||
dismissAction()
|
||||
dismissImpl?()
|
||||
|
||||
let _ = (revokePeerExportedInvitation(account: context.account, peerId: peerId, link: invite.link)
|
||||
|> timeout(10, queue: Queue.mainQueue(), alternate: .fail(.generic))
|
||||
|> deliverOnMainQueue).start(next: { invite in
|
||||
switch invite {
|
||||
case .none:
|
||||
completion?(nil)
|
||||
case let .update(invitation):
|
||||
completion?(invitation)
|
||||
case let .replace(_, invitation):
|
||||
completion?(invitation)
|
||||
}
|
||||
}, error: { _ in
|
||||
updateState { state in
|
||||
var updatedState = state
|
||||
updatedState.updating = false
|
||||
return updatedState
|
||||
}
|
||||
presentControllerImpl?(textAlertController(context: context, title: nil, text: presentationData.strings.Login_UnknownError, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil)
|
||||
let _ = (revokePeerExportedInvitation(account: context.account, peerId: peerId, link: invite.link)
|
||||
|> timeout(10, queue: Queue.mainQueue(), alternate: .fail(.generic))
|
||||
|> deliverOnMainQueue).start(next: { invite in
|
||||
switch invite {
|
||||
case .none:
|
||||
completion?(nil)
|
||||
case let .update(invitation):
|
||||
completion?(invitation)
|
||||
case let .replace(_, invitation):
|
||||
completion?(invitation)
|
||||
}
|
||||
}, error: { _ in
|
||||
updateState { state in
|
||||
var updatedState = state
|
||||
updatedState.updating = false
|
||||
return updatedState
|
||||
}
|
||||
presentControllerImpl?(textAlertController(context: context, title: nil, text: presentationData.strings.Login_UnknownError, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil)
|
||||
})
|
||||
})
|
||||
})
|
||||
]),
|
||||
ActionSheetItemGroup(items: [ActionSheetButtonItem(title: presentationData.strings.Common_Cancel, action: { dismissAction() })])
|
||||
])
|
||||
presentControllerImpl?(controller, nil)
|
||||
]),
|
||||
ActionSheetItemGroup(items: [ActionSheetButtonItem(title: presentationData.strings.Common_Cancel, action: { dismissAction() })])
|
||||
])
|
||||
presentControllerImpl?(controller, nil)
|
||||
})
|
||||
})
|
||||
|
||||
let previousState = Atomic<InviteLinkEditControllerState?>(value: nil)
|
||||
|
@ -366,25 +366,34 @@ public final class InviteLinkInviteController: ViewController {
|
||||
}, action: { _, f in
|
||||
f(.dismissWithoutContent)
|
||||
|
||||
let controller = ActionSheetController(presentationData: presentationData)
|
||||
let dismissAction: () -> Void = { [weak controller] in
|
||||
controller?.dismissAnimated()
|
||||
}
|
||||
controller.setItemGroups([
|
||||
ActionSheetItemGroup(items: [
|
||||
ActionSheetTextItem(title: presentationData.strings.GroupInfo_InviteLink_RevokeAlert_Text),
|
||||
ActionSheetButtonItem(title: presentationData.strings.GroupInfo_InviteLink_RevokeLink, color: .destructive, action: {
|
||||
dismissAction()
|
||||
let _ = (context.account.postbox.loadedPeerWithId(peerId)
|
||||
|> deliverOnMainQueue).start(next: { peer in
|
||||
let isGroup: Bool
|
||||
if let peer = peer as? TelegramChannel, case .broadcast = peer.info {
|
||||
isGroup = false
|
||||
} else {
|
||||
isGroup = true
|
||||
}
|
||||
let controller = ActionSheetController(presentationData: presentationData)
|
||||
let dismissAction: () -> Void = { [weak controller] in
|
||||
controller?.dismissAnimated()
|
||||
}
|
||||
controller.setItemGroups([
|
||||
ActionSheetItemGroup(items: [
|
||||
ActionSheetTextItem(title: isGroup ? presentationData.strings.GroupInfo_InviteLink_RevokeAlert_Text : presentationData.strings.ChannelInfo_InviteLink_RevokeAlert_Text),
|
||||
ActionSheetButtonItem(title: presentationData.strings.GroupInfo_InviteLink_RevokeLink, color: .destructive, action: {
|
||||
dismissAction()
|
||||
|
||||
if let invite = invite {
|
||||
let _ = (revokePeerExportedInvitation(account: context.account, peerId: peerId, link: invite.link) |> deliverOnMainQueue).start(completed: {
|
||||
})
|
||||
}
|
||||
})
|
||||
]),
|
||||
ActionSheetItemGroup(items: [ActionSheetButtonItem(title: presentationData.strings.Common_Cancel, action: { dismissAction() })])
|
||||
])
|
||||
self?.controller?.present(controller, in: .window(.root))
|
||||
if let invite = invite {
|
||||
let _ = (revokePeerExportedInvitation(account: context.account, peerId: peerId, link: invite.link) |> deliverOnMainQueue).start(completed: {
|
||||
})
|
||||
}
|
||||
})
|
||||
]),
|
||||
ActionSheetItemGroup(items: [ActionSheetButtonItem(title: presentationData.strings.Common_Cancel, action: { dismissAction() })])
|
||||
])
|
||||
self?.controller?.present(controller, in: .window(.root))
|
||||
})
|
||||
})))
|
||||
|
||||
let contextController = ContextController(account: context.account, presentationData: presentationData, source: .extracted(InviteLinkContextExtractedContentSource(controller: controller, sourceNode: node, blurBackground: false)), items: .single(items), reactionItems: [], gesture: gesture)
|
||||
|
@ -477,52 +477,62 @@ public func inviteLinkListController(context: AccountContext, peerId: PeerId, ad
|
||||
}, action: { _, f in
|
||||
f(.dismissWithoutContent)
|
||||
|
||||
let controller = ActionSheetController(presentationData: presentationData)
|
||||
let dismissAction: () -> Void = { [weak controller] in
|
||||
controller?.dismissAnimated()
|
||||
}
|
||||
controller.setItemGroups([
|
||||
ActionSheetItemGroup(items: [
|
||||
ActionSheetTextItem(title: presentationData.strings.GroupInfo_InviteLink_RevokeAlert_Text),
|
||||
ActionSheetButtonItem(title: presentationData.strings.GroupInfo_InviteLink_RevokeLink, color: .destructive, action: {
|
||||
dismissAction()
|
||||
let _ = (context.account.postbox.loadedPeerWithId(peerId)
|
||||
|> deliverOnMainQueue).start(next: { peer in
|
||||
let isGroup: Bool
|
||||
if let peer = peer as? TelegramChannel, case .broadcast = peer.info {
|
||||
isGroup = false
|
||||
} else {
|
||||
isGroup = true
|
||||
}
|
||||
|
||||
var revoke = false
|
||||
updateState { state in
|
||||
if !state.revokingPrivateLink {
|
||||
revoke = true
|
||||
var updatedState = state
|
||||
updatedState.revokingPrivateLink = true
|
||||
return updatedState
|
||||
} else {
|
||||
return state
|
||||
}
|
||||
}
|
||||
if revoke {
|
||||
revokeLinkDisposable.set((revokePeerExportedInvitation(account: context.account, peerId: peerId, link: invite.link) |> deliverOnMainQueue).start(next: { result in
|
||||
updateState { state in
|
||||
let controller = ActionSheetController(presentationData: presentationData)
|
||||
let dismissAction: () -> Void = { [weak controller] in
|
||||
controller?.dismissAnimated()
|
||||
}
|
||||
controller.setItemGroups([
|
||||
ActionSheetItemGroup(items: [
|
||||
ActionSheetTextItem(title: isGroup ? presentationData.strings.GroupInfo_InviteLink_RevokeAlert_Text : presentationData.strings.ChannelInfo_InviteLink_RevokeAlert_Text),
|
||||
ActionSheetButtonItem(title: presentationData.strings.GroupInfo_InviteLink_RevokeLink, color: .destructive, action: {
|
||||
dismissAction()
|
||||
|
||||
var revoke = false
|
||||
updateState { state in
|
||||
if !state.revokingPrivateLink {
|
||||
revoke = true
|
||||
var updatedState = state
|
||||
updatedState.revokingPrivateLink = false
|
||||
updatedState.revokingPrivateLink = true
|
||||
return updatedState
|
||||
} else {
|
||||
return state
|
||||
}
|
||||
if let result = result {
|
||||
switch result {
|
||||
case let .update(newInvite):
|
||||
invitesContext.remove(newInvite)
|
||||
revokedInvitesContext.add(newInvite)
|
||||
case let .replace(previousInvite, newInvite):
|
||||
revokedInvitesContext.add(previousInvite)
|
||||
invitesContext.remove(previousInvite)
|
||||
invitesContext.add(newInvite)
|
||||
}
|
||||
if revoke {
|
||||
revokeLinkDisposable.set((revokePeerExportedInvitation(account: context.account, peerId: peerId, link: invite.link) |> deliverOnMainQueue).start(next: { result in
|
||||
updateState { state in
|
||||
var updatedState = state
|
||||
updatedState.revokingPrivateLink = false
|
||||
return updatedState
|
||||
}
|
||||
}
|
||||
}))
|
||||
}
|
||||
})
|
||||
]),
|
||||
ActionSheetItemGroup(items: [ActionSheetButtonItem(title: presentationData.strings.Common_Cancel, action: { dismissAction() })])
|
||||
])
|
||||
presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
||||
if let result = result {
|
||||
switch result {
|
||||
case let .update(newInvite):
|
||||
invitesContext.remove(newInvite)
|
||||
revokedInvitesContext.add(newInvite)
|
||||
case let .replace(previousInvite, newInvite):
|
||||
revokedInvitesContext.add(previousInvite)
|
||||
invitesContext.remove(previousInvite)
|
||||
invitesContext.add(newInvite)
|
||||
}
|
||||
}
|
||||
}))
|
||||
}
|
||||
})
|
||||
]),
|
||||
ActionSheetItemGroup(items: [ActionSheetButtonItem(title: presentationData.strings.Common_Cancel, action: { dismissAction() })])
|
||||
])
|
||||
presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
||||
})
|
||||
})))
|
||||
}
|
||||
|
||||
@ -646,27 +656,36 @@ public func inviteLinkListController(context: AccountContext, peerId: PeerId, ad
|
||||
}, action: { _, f in
|
||||
f(.default)
|
||||
|
||||
let controller = ActionSheetController(presentationData: presentationData)
|
||||
let dismissAction: () -> Void = { [weak controller] in
|
||||
controller?.dismissAnimated()
|
||||
}
|
||||
controller.setItemGroups([
|
||||
ActionSheetItemGroup(items: [
|
||||
ActionSheetTextItem(title: presentationData.strings.GroupInfo_InviteLink_RevokeAlert_Text),
|
||||
ActionSheetButtonItem(title: presentationData.strings.GroupInfo_InviteLink_RevokeLink, color: .destructive, action: {
|
||||
dismissAction()
|
||||
let _ = (context.account.postbox.loadedPeerWithId(peerId)
|
||||
|> deliverOnMainQueue).start(next: { peer in
|
||||
let isGroup: Bool
|
||||
if let peer = peer as? TelegramChannel, case .broadcast = peer.info {
|
||||
isGroup = false
|
||||
} else {
|
||||
isGroup = true
|
||||
}
|
||||
let controller = ActionSheetController(presentationData: presentationData)
|
||||
let dismissAction: () -> Void = { [weak controller] in
|
||||
controller?.dismissAnimated()
|
||||
}
|
||||
controller.setItemGroups([
|
||||
ActionSheetItemGroup(items: [
|
||||
ActionSheetTextItem(title: isGroup ? presentationData.strings.GroupInfo_InviteLink_RevokeAlert_Text : presentationData.strings.ChannelInfo_InviteLink_RevokeAlert_Text),
|
||||
ActionSheetButtonItem(title: presentationData.strings.GroupInfo_InviteLink_RevokeLink, color: .destructive, action: {
|
||||
dismissAction()
|
||||
|
||||
revokeLinkDisposable.set((revokePeerExportedInvitation(account: context.account, peerId: peerId, link: invite.link) |> deliverOnMainQueue).start(completed: {
|
||||
revokeLinkDisposable.set((revokePeerExportedInvitation(account: context.account, peerId: peerId, link: invite.link) |> deliverOnMainQueue).start(completed: {
|
||||
|
||||
}))
|
||||
}))
|
||||
|
||||
invitesContext.remove(invite)
|
||||
revokedInvitesContext.add(invite.withUpdated(isRevoked: true))
|
||||
})
|
||||
]),
|
||||
ActionSheetItemGroup(items: [ActionSheetButtonItem(title: presentationData.strings.Common_Cancel, action: { dismissAction() })])
|
||||
])
|
||||
presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
||||
invitesContext.remove(invite)
|
||||
revokedInvitesContext.add(invite.withUpdated(isRevoked: true))
|
||||
})
|
||||
]),
|
||||
ActionSheetItemGroup(items: [ActionSheetButtonItem(title: presentationData.strings.Common_Cancel, action: { dismissAction() })])
|
||||
])
|
||||
presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
||||
})
|
||||
})))
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,11 @@ public final class InviteLinkQRCodeController: ViewController {
|
||||
|
||||
private var presentationDataDisposable: Disposable?
|
||||
|
||||
private var initialBrightness: CGFloat?
|
||||
private var brightnessArguments: (Double, Double, CGFloat, CGFloat)?
|
||||
|
||||
private var animator: ConstantDisplayLinkAnimator?
|
||||
|
||||
private let idleTimerExtensionDisposable = MetaDisposable()
|
||||
|
||||
public init(context: AccountContext, invite: ExportedInvitation, isGroup: Bool) {
|
||||
@ -64,6 +69,11 @@ public final class InviteLinkQRCodeController: ViewController {
|
||||
self.idleTimerExtensionDisposable.set(self.context.sharedContext.applicationBindings.pushIdleTimerExtension())
|
||||
|
||||
self.statusBar.statusBarStyle = .Ignore
|
||||
|
||||
self.animator = ConstantDisplayLinkAnimator(update: { [weak self] in
|
||||
self?.updateBrightness()
|
||||
})
|
||||
self.animator?.isPaused = true
|
||||
}
|
||||
|
||||
required init(coder aDecoder: NSCoder) {
|
||||
@ -73,6 +83,7 @@ public final class InviteLinkQRCodeController: ViewController {
|
||||
deinit {
|
||||
self.presentationDataDisposable?.dispose()
|
||||
self.idleTimerExtensionDisposable.dispose()
|
||||
self.animator?.invalidate()
|
||||
}
|
||||
|
||||
override public func loadDisplayNode() {
|
||||
@ -85,20 +96,43 @@ public final class InviteLinkQRCodeController: ViewController {
|
||||
}
|
||||
}
|
||||
|
||||
override public func loadView() {
|
||||
super.loadView()
|
||||
}
|
||||
|
||||
override public func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
|
||||
if !self.animatedIn {
|
||||
self.animatedIn = true
|
||||
self.controllerNode.animateIn()
|
||||
|
||||
self.initialBrightness = UIScreen.main.brightness
|
||||
self.brightnessArguments = (CACurrentMediaTime(), 0.3, UIScreen.main.brightness, 1.0)
|
||||
self.updateBrightness()
|
||||
}
|
||||
}
|
||||
|
||||
private func updateBrightness() {
|
||||
if let (startTime, duration, initial, target) = self.brightnessArguments {
|
||||
self.animator?.isPaused = false
|
||||
|
||||
let t = CGFloat(max(0.0, min(1.0, (CACurrentMediaTime() - startTime) / duration)))
|
||||
let value = initial + (target - initial) * t
|
||||
|
||||
UIScreen.main.brightness = value
|
||||
|
||||
if t >= 1.0 {
|
||||
self.brightnessArguments = nil
|
||||
self.animator?.isPaused = true
|
||||
}
|
||||
} else {
|
||||
self.animator?.isPaused = true
|
||||
}
|
||||
}
|
||||
|
||||
override public func dismiss(completion: (() -> Void)? = nil) {
|
||||
if UIScreen.main.brightness > 0.99, let initialBrightness = self.initialBrightness {
|
||||
self.brightnessArguments = (CACurrentMediaTime(), 0.3, UIScreen.main.brightness, initialBrightness)
|
||||
self.updateBrightness()
|
||||
}
|
||||
|
||||
self.controllerNode.animateOut(completion: completion)
|
||||
}
|
||||
|
||||
@ -344,7 +378,7 @@ public final class InviteLinkQRCodeController: ViewController {
|
||||
self.containerLayout = (layout, navigationBarHeight)
|
||||
|
||||
var insets = layout.insets(options: [.statusBar, .input])
|
||||
insets.top = max(10.0, insets.top)
|
||||
insets.top = 48.0
|
||||
|
||||
let makeImageLayout = self.qrImageNode.asyncLayout()
|
||||
let imageSide: CGFloat = 240.0
|
||||
|
@ -511,26 +511,35 @@ public final class InviteLinkViewController: ViewController {
|
||||
}, action: { [weak self] _, f in
|
||||
f(.dismissWithoutContent)
|
||||
|
||||
let controller = ActionSheetController(presentationData: presentationData)
|
||||
let dismissAction: () -> Void = { [weak controller] in
|
||||
controller?.dismissAnimated()
|
||||
}
|
||||
controller.setItemGroups([
|
||||
ActionSheetItemGroup(items: [
|
||||
ActionSheetTextItem(title: presentationData.strings.GroupInfo_InviteLink_RevokeAlert_Text),
|
||||
ActionSheetButtonItem(title: presentationData.strings.GroupInfo_InviteLink_RevokeLink, color: .destructive, action: {
|
||||
dismissAction()
|
||||
self?.controller?.dismiss()
|
||||
let _ = (context.account.postbox.loadedPeerWithId(peerId)
|
||||
|> deliverOnMainQueue).start(next: { peer in
|
||||
let isGroup: Bool
|
||||
if let peer = peer as? TelegramChannel, case .broadcast = peer.info {
|
||||
isGroup = false
|
||||
} else {
|
||||
isGroup = true
|
||||
}
|
||||
let controller = ActionSheetController(presentationData: presentationData)
|
||||
let dismissAction: () -> Void = { [weak controller] in
|
||||
controller?.dismissAnimated()
|
||||
}
|
||||
controller.setItemGroups([
|
||||
ActionSheetItemGroup(items: [
|
||||
ActionSheetTextItem(title: isGroup ? presentationData.strings.GroupInfo_InviteLink_RevokeAlert_Text : presentationData.strings.ChannelInfo_InviteLink_RevokeAlert_Text),
|
||||
ActionSheetButtonItem(title: presentationData.strings.GroupInfo_InviteLink_RevokeLink, color: .destructive, action: {
|
||||
dismissAction()
|
||||
self?.controller?.dismiss()
|
||||
|
||||
let _ = (revokePeerExportedInvitation(account: context.account, peerId: peerId, link: invite.link) |> deliverOnMainQueue).start(completed: {
|
||||
let _ = (revokePeerExportedInvitation(account: context.account, peerId: peerId, link: invite.link) |> deliverOnMainQueue).start(completed: {
|
||||
})
|
||||
|
||||
self?.controller?.revokedInvitationsContext?.remove(invite)
|
||||
})
|
||||
|
||||
self?.controller?.revokedInvitationsContext?.remove(invite)
|
||||
})
|
||||
]),
|
||||
ActionSheetItemGroup(items: [ActionSheetButtonItem(title: presentationData.strings.Common_Cancel, action: { dismissAction() })])
|
||||
])
|
||||
self?.controller?.present(controller, in: .window(.root))
|
||||
]),
|
||||
ActionSheetItemGroup(items: [ActionSheetButtonItem(title: presentationData.strings.Common_Cancel, action: { dismissAction() })])
|
||||
])
|
||||
self?.controller?.present(controller, in: .window(.root))
|
||||
})
|
||||
})))
|
||||
}
|
||||
|
||||
|
@ -988,50 +988,60 @@ public func channelVisibilityController(context: AccountContext, peerId: PeerId,
|
||||
}, action: { _, f in
|
||||
f(.dismissWithoutContent)
|
||||
|
||||
let controller = ActionSheetController(presentationData: presentationData)
|
||||
let dismissAction: () -> Void = { [weak controller] in
|
||||
controller?.dismissAnimated()
|
||||
}
|
||||
controller.setItemGroups([
|
||||
ActionSheetItemGroup(items: [
|
||||
ActionSheetTextItem(title: presentationData.strings.GroupInfo_InviteLink_RevokeAlert_Text),
|
||||
ActionSheetButtonItem(title: presentationData.strings.GroupInfo_InviteLink_RevokeLink, color: .destructive, action: {
|
||||
dismissAction()
|
||||
let _ = (context.account.postbox.loadedPeerWithId(peerId)
|
||||
|> deliverOnMainQueue).start(next: { peer in
|
||||
let isGroup: Bool
|
||||
if let peer = peer as? TelegramChannel, case .broadcast = peer.info {
|
||||
isGroup = false
|
||||
} else {
|
||||
isGroup = true
|
||||
}
|
||||
|
||||
let _ = (context.account.postbox.transaction { transaction -> String? in
|
||||
if let cachedData = transaction.getPeerCachedData(peerId: peerId) {
|
||||
if let cachedData = cachedData as? CachedChannelData {
|
||||
return cachedData.exportedInvitation?.link
|
||||
} else if let cachedData = cachedData as? CachedGroupData {
|
||||
return cachedData.exportedInvitation?.link
|
||||
}
|
||||
}
|
||||
return nil
|
||||
} |> deliverOnMainQueue).start(next: { link in
|
||||
if let link = link {
|
||||
var revoke = false
|
||||
updateState { state in
|
||||
if !state.revokingPrivateLink {
|
||||
revoke = true
|
||||
return state.withUpdatedRevokingPrivateLink(true)
|
||||
} else {
|
||||
return state
|
||||
let controller = ActionSheetController(presentationData: presentationData)
|
||||
let dismissAction: () -> Void = { [weak controller] in
|
||||
controller?.dismissAnimated()
|
||||
}
|
||||
controller.setItemGroups([
|
||||
ActionSheetItemGroup(items: [
|
||||
ActionSheetTextItem(title: isGroup ? presentationData.strings.GroupInfo_InviteLink_RevokeAlert_Text : presentationData.strings.ChannelInfo_InviteLink_RevokeAlert_Text),
|
||||
ActionSheetButtonItem(title: presentationData.strings.GroupInfo_InviteLink_RevokeLink, color: .destructive, action: {
|
||||
dismissAction()
|
||||
|
||||
let _ = (context.account.postbox.transaction { transaction -> String? in
|
||||
if let cachedData = transaction.getPeerCachedData(peerId: peerId) {
|
||||
if let cachedData = cachedData as? CachedChannelData {
|
||||
return cachedData.exportedInvitation?.link
|
||||
} else if let cachedData = cachedData as? CachedGroupData {
|
||||
return cachedData.exportedInvitation?.link
|
||||
}
|
||||
}
|
||||
if revoke {
|
||||
revokeLinkDisposable.set((revokePeerExportedInvitation(account: context.account, peerId: peerId, link: link) |> deliverOnMainQueue).start(completed: {
|
||||
updateState {
|
||||
$0.withUpdatedRevokingPrivateLink(false)
|
||||
return nil
|
||||
} |> deliverOnMainQueue).start(next: { link in
|
||||
if let link = link {
|
||||
var revoke = false
|
||||
updateState { state in
|
||||
if !state.revokingPrivateLink {
|
||||
revoke = true
|
||||
return state.withUpdatedRevokingPrivateLink(true)
|
||||
} else {
|
||||
return state
|
||||
}
|
||||
}))
|
||||
}
|
||||
if revoke {
|
||||
revokeLinkDisposable.set((revokePeerExportedInvitation(account: context.account, peerId: peerId, link: link) |> deliverOnMainQueue).start(completed: {
|
||||
updateState {
|
||||
$0.withUpdatedRevokingPrivateLink(false)
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
]),
|
||||
ActionSheetItemGroup(items: [ActionSheetButtonItem(title: presentationData.strings.Common_Cancel, action: { dismissAction() })])
|
||||
])
|
||||
presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
||||
]),
|
||||
ActionSheetItemGroup(items: [ActionSheetButtonItem(title: presentationData.strings.Common_Cancel, action: { dismissAction() })])
|
||||
])
|
||||
presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
||||
})
|
||||
})))
|
||||
|
||||
let contextController = ContextController(account: context.account, presentationData: presentationData, source: .extracted(InviteLinkContextExtractedContentSource(controller: controller, sourceNode: node)), items: .single(items), reactionItems: [], gesture: nil)
|
||||
|
@ -71,7 +71,7 @@ public final class PermissionContentNode: ASDisplayNode {
|
||||
if case let .animation(animation) = icon {
|
||||
self.animationNode = AnimatedStickerNode()
|
||||
if let path = getAppBundle().path(forResource: animation, ofType: "tgs") {
|
||||
self.animationNode?.setup(source: AnimatedStickerNodeLocalFileSource(path: path), width: 320, height: 320, playbackMode: .loop, mode: .direct(cachePathPrefix: nil))
|
||||
self.animationNode?.setup(source: AnimatedStickerNodeLocalFileSource(path: path), width: 320, height: 320, playbackMode: .once, mode: .direct(cachePathPrefix: nil))
|
||||
self.animationNode?.visibility = true
|
||||
}
|
||||
self.nearbyIconNode = nil
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -873,6 +873,12 @@ extension PresentationThemeDecoding {
|
||||
} else if number === kCFBooleanFalse as NSNumber {
|
||||
return false
|
||||
}
|
||||
} else if let string = value as? String {
|
||||
if string.lowercased() == "true" {
|
||||
return true
|
||||
} else if string.lowercased() == "false" {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
throw PresentationThemeDecodingError.typeMismatch
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user