Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios

This commit is contained in:
Ilya Laktyushin 2020-11-30 03:38:52 +04:00
commit 37b9b53a9a
6 changed files with 271 additions and 90 deletions

View File

@ -800,7 +800,7 @@ public extension ContainedViewLayoutTransition {
}
}
func updateSublayerTransformScale(node: ASDisplayNode, scale: CGPoint, completion: ((Bool) -> Void)? = nil) {
func updateSublayerTransformScale(node: ASDisplayNode, scale: CGPoint, beginWithCurrentState: Bool = false, completion: ((Bool) -> Void)? = nil) {
if !node.isNodeLoaded {
node.subnodeTransform = CATransform3DMakeScale(scale.x, scale.y, 1.0)
completion?(true)
@ -826,8 +826,15 @@ public extension ContainedViewLayoutTransition {
completion(true)
}
case let .animated(duration, curve):
let initialTransform: CATransform3D
if beginWithCurrentState, node.isNodeLoaded {
initialTransform = node.layer.presentation()?.sublayerTransform ?? t
} else {
initialTransform = t
}
node.layer.sublayerTransform = CATransform3DMakeScale(scale.x, scale.y, 1.0)
node.layer.animate(from: NSValue(caTransform3D: t), to: NSValue(caTransform3D: node.layer.sublayerTransform), keyPath: "sublayerTransform", timingFunction: curve.timingFunction, duration: duration, delay: 0.0, mediaTimingFunction: curve.mediaTimingFunction, removeOnCompletion: true, additive: false, completion: {
node.layer.animate(from: NSValue(caTransform3D: initialTransform), to: NSValue(caTransform3D: node.layer.sublayerTransform), keyPath: "sublayerTransform", timingFunction: curve.timingFunction, duration: duration, delay: 0.0, mediaTimingFunction: curve.mediaTimingFunction, removeOnCompletion: true, additive: false, completion: {
result in
if let completion = completion {
completion(result)

View File

@ -852,7 +852,9 @@ public func rebuildControllerStackAfterSupergroupUpgrade(controller: ViewControl
if controllers[i] === controller {
for j in 0 ..< i {
if controllers[j] is ChatController {
controllers.removeSubrange(j + 1 ... i - 1)
if j + 1 <= i - 1 {
controllers.removeSubrange(j + 1 ... i - 1)
}
break
}
}

View File

@ -11,6 +11,7 @@ import AccountContext
import AppBundle
import SwiftSignalKit
import AnimatedAvatarSetNode
import AudioBlob
private let titleFont = Font.semibold(15.0)
private let subtitleFont = Font.regular(13.0)
@ -61,9 +62,12 @@ public final class GroupCallNavigationAccessoryPanel: ASDisplayNode {
private let joinButtonTitleNode: ImmediateTextNode
private let joinButtonBackgroundNode: ASImageNode
private var audioLevelView: VoiceBlobView?
private let micButton: HighlightTrackingButtonNode
private let micButtonForegroundNode: VoiceChatMicrophoneNode
private let micButtonBackgroundNode: ASImageNode
private var micButtonBackgroundNodeIsMuted: Bool?
let titleNode: ImmediateTextNode
let textNode: ImmediateTextNode
@ -77,6 +81,9 @@ public final class GroupCallNavigationAccessoryPanel: ASDisplayNode {
private let membersDisposable = MetaDisposable()
private let isMutedDisposable = MetaDisposable()
private let audioLevelDisposable = MetaDisposable()
private var callState: PresentationGroupCallState?
private var currentData: GroupCallPanelData?
private var validLayout: (CGSize, CGFloat, CGFloat)?
@ -182,16 +189,18 @@ public final class GroupCallNavigationAccessoryPanel: ASDisplayNode {
private var actionButtonPressGestureStartTime: Double = 0.0
@objc private func micButtonPressGesture(_ gestureRecognizer: UILongPressGestureRecognizer) {
guard let call = self.currentData?.groupCall else {
guard let call = self.currentData?.groupCall, let callState = self.callState else {
return
}
switch gestureRecognizer.state {
case .began:
self.actionButtonPressGestureStartTime = CACurrentMediaTime()
call.setIsMuted(action: .muted(isPushToTalkActive: true))
if callState.muteState != nil {
call.setIsMuted(action: .muted(isPushToTalkActive: true))
}
case .ended, .cancelled:
let timestamp = CACurrentMediaTime()
if timestamp - self.actionButtonPressGestureStartTime < 0.2 {
if callState.muteState != nil || timestamp - self.actionButtonPressGestureStartTime < 0.1 {
call.toggleIsMuted()
} else {
call.setIsMuted(action: .muted(isPushToTalkActive: false))
@ -214,9 +223,6 @@ public final class GroupCallNavigationAccessoryPanel: ASDisplayNode {
self.joinButtonTitleNode.attributedText = NSAttributedString(string: presentationData.strings.VoiceChat_PanelJoin.uppercased(), font: Font.semibold(15.0), textColor: presentationData.theme.chat.inputPanel.actionControlForegroundColor)
self.joinButtonBackgroundNode.image = generateStretchableFilledCircleImage(diameter: 28.0, color: presentationData.theme.chat.inputPanel.actionControlFillColor)
//TODO:localize
self.micButtonBackgroundNode.image = generateStretchableFilledCircleImage(diameter: 36.0, color: UIColor(rgb: 0x30b251))
self.titleNode.attributedText = NSAttributedString(string: presentationData.strings.VoiceChat_Title, font: Font.semibold(15.0), textColor: presentationData.theme.chat.inputPanel.primaryTextColor)
self.textNode.attributedText = NSAttributedString(string: self.textNode.attributedText?.string ?? "", font: Font.regular(13.0), textColor: presentationData.theme.chat.inputPanel.secondaryTextColor)
@ -239,6 +245,8 @@ public final class GroupCallNavigationAccessoryPanel: ASDisplayNode {
self.textNode.attributedText = NSAttributedString(string: membersText, font: Font.regular(13.0), textColor: self.theme.chat.inputPanel.secondaryTextColor)
self.callState = nil
self.membersDisposable.set(nil)
self.isMutedDisposable.set(nil)
@ -272,15 +280,80 @@ public final class GroupCallNavigationAccessoryPanel: ASDisplayNode {
}
}))
self.isMutedDisposable.set((groupCall.isMuted
|> deliverOnMainQueue).start(next: { [weak self] isMuted in
self.isMutedDisposable.set((groupCall.state
|> deliverOnMainQueue).start(next: { [weak self] callState in
guard let strongSelf = self else {
return
}
strongSelf.micButtonForegroundNode.update(state: VoiceChatMicrophoneNode.State(muted: isMuted, color: UIColor.white), animated: true)
var transition: ContainedViewLayoutTransition = .immediate
if strongSelf.callState != nil {
transition = .animated(duration: 0.3, curve: .spring)
}
strongSelf.callState = callState
if let (size, leftInset, rightInset) = strongSelf.validLayout {
strongSelf.updateLayout(size: size, leftInset: leftInset, rightInset: rightInset, transition: transition)
}
}))
self.audioLevelDisposable.set((groupCall.myAudioLevel
|> deliverOnMainQueue).start(next: { [weak self] value in
guard let strongSelf = self else {
return
}
if strongSelf.audioLevelView == nil {
let blobFrame = CGRect(origin: CGPoint(), size: CGSize(width: 36.0, height: 36.0)).insetBy(dx: -12.0, dy: -12.0)
let audioLevelView = VoiceBlobView(
frame: blobFrame,
maxLevel: 0.3,
smallBlobRange: (0, 0),
mediumBlobRange: (0.7, 0.8),
bigBlobRange: (0.8, 0.9)
)
let maskRect = CGRect(origin: .zero, size: blobFrame.size)
let playbackMaskLayer = CAShapeLayer()
playbackMaskLayer.frame = maskRect
playbackMaskLayer.fillRule = .evenOdd
let maskPath = UIBezierPath()
maskPath.append(UIBezierPath(roundedRect: maskRect.insetBy(dx: 12, dy: 12), cornerRadius: 22))
maskPath.append(UIBezierPath(rect: maskRect))
playbackMaskLayer.path = maskPath.cgPath
audioLevelView.layer.mask = playbackMaskLayer
audioLevelView.setColor(UIColor(rgb: 0x30B251))
strongSelf.audioLevelView = audioLevelView
strongSelf.micButton.view.insertSubview(audioLevelView, at: 0)
}
var value = value
if value <= 0.15 {
value = 0.0
}
let level = min(1.0, max(0.0, CGFloat(value)))
let avatarScale: CGFloat
strongSelf.audioLevelView?.updateLevel(CGFloat(value) * 2.0)
if value > 0.0 {
strongSelf.audioLevelView?.startAnimating()
avatarScale = 1.03 + level * 0.1
} else {
strongSelf.audioLevelView?.stopAnimating(duration: 0.5)
avatarScale = 1.0
}
//let transition: ContainedViewLayoutTransition = .animated(duration: 0.15, curve: .spring)
//transition.updateSublayerTransformScale(node: strongSelf.avatarNode, scale: avatarScale, beginWithCurrentState: true)
}))
}
} else if data.groupCall == nil {
self.audioLevelDisposable.set(nil)
let membersText: String
let membersTextIsActive: Bool
if data.numberOfActiveSpeakers != 0 {
@ -334,6 +407,26 @@ public final class GroupCallNavigationAccessoryPanel: ASDisplayNode {
let animationSize = CGSize(width: 36.0, height: 36.0)
transition.updateFrame(node: self.micButtonForegroundNode, frame: CGRect(origin: CGPoint(x: floor((micButtonFrame.width - animationSize.width) / 2.0), y: floor((micButtonFrame.height - animationSize.height) / 2.0)), size: animationSize))
var isMuted = true
if let _ = self.callState?.muteState {
isMuted = true
} else {
isMuted = false
}
self.micButtonForegroundNode.update(state: VoiceChatMicrophoneNode.State(muted: isMuted, color: UIColor.white), animated: transition.isAnimated)
if isMuted != self.micButtonBackgroundNodeIsMuted {
self.micButtonBackgroundNodeIsMuted = isMuted
let updatedImage = generateStretchableFilledCircleImage(diameter: 36.0, color: isMuted ? UIColor(rgb: 0xb6b6bb) : UIColor(rgb: 0x30b251))
if let updatedImage = updatedImage, let previousImage = self.micButtonBackgroundNode.image?.cgImage, transition.isAnimated {
self.micButtonBackgroundNode.image = updatedImage
self.micButtonBackgroundNode.layer.animate(from: previousImage, to: updatedImage.cgImage!, keyPath: "contents", timingFunction: CAMediaTimingFunctionName.easeOut.rawValue, duration: 0.25, delay: 0.0)
} else {
self.micButtonBackgroundNode.image = updatedImage
}
}
let titleSize = self.titleNode.updateLayout(CGSize(width: size.width, height: .greatestFiniteMagnitude))
let textSize = self.textNode.updateLayout(CGSize(width: size.width, height: .greatestFiniteMagnitude))

View File

@ -60,6 +60,7 @@ public final class PresentationCallManagerImpl: PresentationCallManager {
}
private var currentCallDisposable = MetaDisposable()
private let removeCurrentCallDisposable = MetaDisposable()
private let removeCurrentGroupCallDisposable = MetaDisposable()
private var currentGroupCallValue: PresentationGroupCallImpl?
private var currentGroupCall: PresentationGroupCallImpl? {
@ -68,9 +69,17 @@ public final class PresentationCallManagerImpl: PresentationCallManager {
private var ringingStatesDisposable: Disposable?
private let hasActiveCallsPromise = ValuePromise<Bool>(false, ignoreRepeated: true)
private let hasActivePersonalCallsPromise = ValuePromise<Bool>(false, ignoreRepeated: true)
private let hasActiveGroupCallsPromise = ValuePromise<Bool>(false, ignoreRepeated: true)
public var hasActiveCalls: Signal<Bool, NoError> {
return self.hasActiveCallsPromise.get()
return combineLatest(queue: .mainQueue(),
self.hasActivePersonalCallsPromise.get(),
self.hasActiveGroupCallsPromise.get()
)
|> map { value1, value2 -> Bool in
return value1 || value2
}
|> distinctUntilChanged
}
private let currentCallPromise = Promise<PresentationCall?>(nil)
@ -254,6 +263,7 @@ public final class PresentationCallManagerImpl: PresentationCallManager {
self.currentCallDisposable.dispose()
self.ringingStatesDisposable?.dispose()
self.removeCurrentCallDisposable.dispose()
self.removeCurrentGroupCallDisposable.dispose()
self.startCallDisposable.dispose()
self.proxyServerDisposable?.dispose()
self.callSettingsDisposable?.dispose()
@ -300,14 +310,14 @@ public final class PresentationCallManagerImpl: PresentationCallManager {
)
strongSelf.updateCurrentCall(call)
strongSelf.currentCallPromise.set(.single(call))
strongSelf.hasActiveCallsPromise.set(true)
strongSelf.hasActivePersonalCallsPromise.set(true)
strongSelf.removeCurrentCallDisposable.set((call.canBeRemoved
|> deliverOnMainQueue).start(next: { [weak self, weak call] value in
if value, let strongSelf = self, let call = call {
if strongSelf.currentCall === call {
strongSelf.updateCurrentCall(nil)
strongSelf.currentCallPromise.set(.single(nil))
strongSelf.hasActiveCallsPromise.set(false)
strongSelf.hasActivePersonalCallsPromise.set(false)
}
}
}))
@ -331,6 +341,9 @@ public final class PresentationCallManagerImpl: PresentationCallManager {
if let call = self.currentCall {
alreadyInCall = true
alreadyInCallWithPeerId = call.peerId
} else if let currentGroupCall = self.currentGroupCallValue {
alreadyInCall = true
alreadyInCallWithPeerId = currentGroupCall.peerId
} else {
if #available(iOS 10.0, *) {
if CXCallObserver().calls.contains(where: { $0.hasEnded == false }) {
@ -395,6 +408,13 @@ public final class PresentationCallManagerImpl: PresentationCallManager {
|> deliverOnMainQueue).start(next: { _ in
begin()
}))
} else if let currentGroupCall = self.currentGroupCallValue {
self.startCallDisposable.set((currentGroupCall.leave(terminateIfPossible: false)
|> filter { $0 }
|> take(1)
|> deliverOnMainQueue).start(next: { _ in
begin()
}))
} else {
begin()
}
@ -410,6 +430,13 @@ public final class PresentationCallManagerImpl: PresentationCallManager {
|> deliverOnMainQueue).start(next: { _ in
begin()
}))
} else if let currentGroupCall = self.currentGroupCallValue {
self.startCallDisposable.set((currentGroupCall.leave(terminateIfPossible: false)
|> filter { $0 }
|> take(1)
|> deliverOnMainQueue).start(next: { _ in
begin()
}))
} else {
begin()
}
@ -544,14 +571,14 @@ public final class PresentationCallManagerImpl: PresentationCallManager {
)
strongSelf.updateCurrentCall(call)
strongSelf.currentCallPromise.set(.single(call))
strongSelf.hasActiveCallsPromise.set(true)
strongSelf.hasActivePersonalCallsPromise.set(true)
strongSelf.removeCurrentCallDisposable.set((call.canBeRemoved
|> deliverOnMainQueue).start(next: { [weak call] value in
if value, let strongSelf = self, let call = call {
if strongSelf.currentCall === call {
strongSelf.updateCurrentCall(nil)
strongSelf.currentCallPromise.set(.single(nil))
strongSelf.hasActiveCallsPromise.set(false)
strongSelf.hasActivePersonalCallsPromise.set(false)
}
}
}))
@ -597,6 +624,7 @@ public final class PresentationCallManagerImpl: PresentationCallManager {
let begin: () -> Void = { [weak self] in
let _ = self?.startGroupCall(accountContext: context, peerId: peerId, initialCall: initialCall, sourcePanel: sourcePanel).start()
}
if let currentGroupCall = self.currentGroupCallValue {
if endCurrentIfAny {
let endSignal = currentGroupCall.leave(terminateIfPossible: false)
@ -609,6 +637,16 @@ public final class PresentationCallManagerImpl: PresentationCallManager {
} else {
return .alreadyInProgress(currentGroupCall.peerId)
}
} else if let currentCall = self.currentCall {
if endCurrentIfAny {
self.callKitIntegration?.dropCall(uuid: currentCall.internalId)
self.startCallDisposable.set((currentCall.hangUp()
|> deliverOnMainQueue).start(next: { _ in
begin()
}))
} else {
return .alreadyInProgress(currentCall.peerId)
}
} else {
begin()
}
@ -674,14 +712,19 @@ public final class PresentationCallManagerImpl: PresentationCallManager {
call.sourcePanel = sourcePanel
strongSelf.updateCurrentGroupCall(call)
strongSelf.currentGroupCallPromise.set(.single(call))
strongSelf.hasActiveCallsPromise.set(true)
strongSelf.removeCurrentCallDisposable.set((call.canBeRemoved
strongSelf.hasActiveGroupCallsPromise.set(true)
strongSelf.removeCurrentGroupCallDisposable.set((call.canBeRemoved
|> filter { $0 }
|> take(1)
|> deliverOnMainQueue).start(next: { [weak call] value in
if value, let strongSelf = self, let call = call {
guard let strongSelf = self, let call = call else {
return
}
if value {
if strongSelf.currentGroupCall === call {
strongSelf.updateCurrentGroupCall(nil)
strongSelf.currentGroupCallPromise.set(.single(nil))
strongSelf.hasActiveCallsPromise.set(false)
strongSelf.hasActiveGroupCallsPromise.set(false)
}
}
}))

View File

@ -497,6 +497,11 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
if let clientParams = joinCallResult.callInfo.clientParams {
strongSelf.updateSessionState(internalState: .estabilished(info: joinCallResult.callInfo, clientParams: clientParams, localSsrc: ssrc, initialState: joinCallResult.state), audioSessionControl: strongSelf.audioSessionControl)
}
}, error: { _ in
guard let strongSelf = self else {
return
}
strongSelf._canBeRemoved.set(.single(true))
}))
}))
@ -690,11 +695,13 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
}))
} else {
self.leaveDisposable.set((leaveGroupCall(account: self.account, callId: callInfo.id, accessHash: callInfo.accessHash, source: localSsrc)
|> deliverOnMainQueue).start(completed: { [weak self] in
|> deliverOnMainQueue).start(error: { [weak self] _ in
self?._canBeRemoved.set(.single(true))
}, completed: { [weak self] in
self?._canBeRemoved.set(.single(true))
}))
}
} else if case .requesting = self.internalState {
} else {
self.callContext?.stop()
self.callContext = nil
self.requestDisposable.set(nil)

View File

@ -3032,6 +3032,29 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
}
}
} else if let group = peer as? TelegramGroup {
if case .creator = group.role {
items.append(ActionSheetButtonItem(title: presentationData.strings.ChannelInfo_CreateVoiceChat, color: .accent, action: { [weak self] in
dismissAction()
guard let strongSelf = self else {
return
}
strongSelf.activeActionDisposable.set((convertGroupToSupergroup(account: strongSelf.context.account, peerId: group.id)
|> deliverOnMainQueue).start(next: { peerId in
guard let strongSelf = self else {
return
}
if let controller = strongSelf.controller, let navigationController = controller.navigationController as? NavigationController {
rebuildControllerStackAfterSupergroupUpgrade(controller: controller, navigationController: navigationController)
strongSelf.createAndJoinGroupCall(peerId: peerId)
}
}))
}))
}
if case .Member = group.membership {
items.append(ActionSheetButtonItem(title: presentationData.strings.Group_LeaveGroup, color: .destructive, action: { [weak self] in
dismissAction()
@ -3181,72 +3204,8 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
if let activeCall = cachedChannelData.activeCall {
let _ = self.context.sharedContext.callManager?.joinGroupCall(context: self.context, peerId: peer.id, initialCall: activeCall, endCurrentIfAny: false, sourcePanel: nil)
} else if let callManager = self.context.sharedContext.callManager {
let startCall: (Bool) -> Void = { [weak self] endCurrentIfAny in
guard let strongSelf = self else {
return
}
var dismissStatus: (() -> Void)?
let statusController = OverlayStatusController(theme: strongSelf.presentationData.theme, type: .loading(cancelled: {
dismissStatus?()
}))
dismissStatus = { [weak self, weak statusController] in
self?.activeActionDisposable.set(nil)
statusController?.dismiss()
}
strongSelf.controller?.present(statusController, in: .window(.root))
strongSelf.activeActionDisposable.set((createGroupCall(account: strongSelf.context.account, peerId: peer.id)
|> deliverOnMainQueue).start(next: { [weak self] info in
guard let strongSelf = self else {
return
}
let _ = strongSelf.context.sharedContext.callManager?.joinGroupCall(context: strongSelf.context, peerId: peer.id, initialCall: CachedChannelData.ActiveCall(id: info.id, accessHash: info.accessHash), endCurrentIfAny: endCurrentIfAny, sourcePanel: nil)
}, error: { [weak self] _ in
dismissStatus?()
guard let strongSelf = self else {
return
}
strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel)
}, completed: { [weak self] in
dismissStatus?()
guard let strongSelf = self else {
return
}
strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel)
}))
}
let _ = (callManager.currentGroupCallSignal
|> take(1)
|> deliverOnMainQueue).start(next: { [weak self] activeCall in
guard let strongSelf = self else {
return
}
if let activeCall = activeCall {
let currentPeerId = activeCall.peerId
let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 }
let _ = (strongSelf.context.account.postbox.transaction { transaction -> (Peer?, Peer?) in
return (transaction.getPeer(peer.id), transaction.getPeer(currentPeerId))
} |> deliverOnMainQueue).start(next: { [weak self] peer, current in
if let peer = peer {
if let strongSelf = self, let current = current {
strongSelf.controller?.present(textAlertController(context: strongSelf.context, title: presentationData.strings.Call_CallInProgressTitle, text: presentationData.strings.Call_CallInProgressMessage(current.compactDisplayTitle, peer.compactDisplayTitle).0, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_Cancel, action: {}), TextAlertAction(type: .genericAction, title: presentationData.strings.Common_OK, action: {
startCall(true)
})]), in: .window(.root))
} else {
strongSelf.controller?.present(textAlertController(context: strongSelf.context, title: presentationData.strings.Call_CallInProgressTitle, text: presentationData.strings.Call_ExternalCallInProgressMessage, actions: [TextAlertAction(type: .genericAction, title: presentationData.strings.Common_OK, action: {
})]), in: .window(.root))
}
}
})
} else {
startCall(false)
}
})
} else {
self.createAndJoinGroupCall(peerId: peer.id)
}
return
}
@ -3302,6 +3261,76 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
}
}
private func createAndJoinGroupCall(peerId: PeerId) {
if let callManager = self.context.sharedContext.callManager {
let startCall: (Bool) -> Void = { [weak self] endCurrentIfAny in
guard let strongSelf = self else {
return
}
var dismissStatus: (() -> Void)?
let statusController = OverlayStatusController(theme: strongSelf.presentationData.theme, type: .loading(cancelled: {
dismissStatus?()
}))
dismissStatus = { [weak self, weak statusController] in
self?.activeActionDisposable.set(nil)
statusController?.dismiss()
}
strongSelf.controller?.present(statusController, in: .window(.root))
strongSelf.activeActionDisposable.set((createGroupCall(account: strongSelf.context.account, peerId: peerId)
|> deliverOnMainQueue).start(next: { [weak self] info in
guard let strongSelf = self else {
return
}
let _ = strongSelf.context.sharedContext.callManager?.joinGroupCall(context: strongSelf.context, peerId: peerId, initialCall: CachedChannelData.ActiveCall(id: info.id, accessHash: info.accessHash), endCurrentIfAny: endCurrentIfAny, sourcePanel: nil)
}, error: { [weak self] _ in
dismissStatus?()
guard let strongSelf = self else {
return
}
strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel)
}, completed: { [weak self] in
dismissStatus?()
guard let strongSelf = self else {
return
}
strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel)
}))
}
let _ = (callManager.currentGroupCallSignal
|> take(1)
|> deliverOnMainQueue).start(next: { [weak self] activeCall in
guard let strongSelf = self else {
return
}
if let activeCall = activeCall {
let currentPeerId = activeCall.peerId
let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 }
let _ = (strongSelf.context.account.postbox.transaction { transaction -> (Peer?, Peer?) in
return (transaction.getPeer(peerId), transaction.getPeer(currentPeerId))
} |> deliverOnMainQueue).start(next: { [weak self] peer, current in
if let peer = peer {
if let strongSelf = self, let current = current {
strongSelf.controller?.present(textAlertController(context: strongSelf.context, title: presentationData.strings.Call_CallInProgressTitle, text: presentationData.strings.Call_CallInProgressMessage(current.compactDisplayTitle, peer.compactDisplayTitle).0, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_Cancel, action: {}), TextAlertAction(type: .genericAction, title: presentationData.strings.Common_OK, action: {
startCall(true)
})]), in: .window(.root))
} else {
strongSelf.controller?.present(textAlertController(context: strongSelf.context, title: presentationData.strings.Call_CallInProgressTitle, text: presentationData.strings.Call_ExternalCallInProgressMessage, actions: [TextAlertAction(type: .genericAction, title: presentationData.strings.Common_OK, action: {
})]), in: .window(.root))
}
}
})
} else {
startCall(false)
}
})
}
}
private func openPhone(value: String) {
let _ = (getUserPeer(postbox: self.context.account.postbox, peerId: peerId)
|> deliverOnMainQueue).start(next: { [weak self] peer, _ in