From 0e3b3429dcd06c003c575f5ae99a65b9debac453 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Thu, 29 Oct 2020 00:09:07 +0400 Subject: [PATCH] Fix live location start from modal location display --- .../LocationUI/Sources/LocationMapNode.swift | 16 ++++++++++------ .../Sources/LocationViewControllerNode.swift | 6 ++++-- .../Sources/TelegramBaseController.swift | 3 ++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/submodules/LocationUI/Sources/LocationMapNode.swift b/submodules/LocationUI/Sources/LocationMapNode.swift index 6837febadf..fb5532b981 100644 --- a/submodules/LocationUI/Sources/LocationMapNode.swift +++ b/submodules/LocationUI/Sources/LocationMapNode.swift @@ -158,6 +158,8 @@ final class LocationMapNode: ASDisplayNode, MKMapViewDelegate { private weak var userLocationAnnotationView: MKAnnotationView? private var headingArrowView: UIImageView? + private weak var defaultUserLocationAnnotation: MKAnnotation? + private let pinDisposable = MetaDisposable() private var mapView: LocationMapView? { @@ -390,6 +392,8 @@ final class LocationMapNode: ASDisplayNode, MKMapViewDelegate { func mapView(_ mapView: MKMapView, didAdd views: [MKAnnotationView]) { for view in views { if view.annotation is MKUserLocation { + self.defaultUserLocationAnnotation = view.annotation + self.userLocationAnnotationView = view if let headingArrowView = self.headingArrowView { view.addSubview(headingArrowView) @@ -694,15 +698,15 @@ final class LocationMapNode: ASDisplayNode, MKMapViewDelegate { guard let mapView = self.mapView else { return } - var annotations: [MKAnnotation] = [] - if let userAnnotation = self.userLocationAnnotation { - annotations.append(userAnnotation) + var coordinates: [CLLocationCoordinate2D] = [] + if let location = self.currentUserLocation { + coordinates.append(location.coordinate) } - annotations.append(contentsOf: self.annotations) + coordinates.append(contentsOf: self.annotations.map { $0.coordinate }) var zoomRect: MKMapRect? - for annotation in annotations { - let pointRegionRect = MKMapRect(region: MKCoordinateRegion(center: annotation.coordinate, latitudinalMeters: 100, longitudinalMeters: 100)) + for coordinate in coordinates { + let pointRegionRect = MKMapRect(region: MKCoordinateRegion(center: coordinate, latitudinalMeters: 100, longitudinalMeters: 100)) if let currentZoomRect = zoomRect { zoomRect = currentZoomRect.union(pointRegionRect) } else { diff --git a/submodules/LocationUI/Sources/LocationViewControllerNode.swift b/submodules/LocationUI/Sources/LocationViewControllerNode.swift index 3d5fdedec7..d276100b15 100644 --- a/submodules/LocationUI/Sources/LocationViewControllerNode.swift +++ b/submodules/LocationUI/Sources/LocationViewControllerNode.swift @@ -485,7 +485,9 @@ final class LocationViewControllerNode: ViewControllerTracingNode, CLLocationMan if !strongSelf.reportedAnnotationsReady { strongSelf.reportedAnnotationsReady = true - strongSelf.onAnnotationsReady?() + if annotations.count > 0 { + strongSelf.onAnnotationsReady?() + } } } @@ -496,7 +498,7 @@ final class LocationViewControllerNode: ViewControllerTracingNode, CLLocationMan } let rightBarButtonAction: LocationViewRightBarButton if location.liveBroadcastingTimeout != nil { - if liveLocations.count > 1 { + if annotations.count > 0 { rightBarButtonAction = .showAll } else { rightBarButtonAction = .none diff --git a/submodules/TelegramBaseController/Sources/TelegramBaseController.swift b/submodules/TelegramBaseController/Sources/TelegramBaseController.swift index 0e963e8cfa..86d2e44dcb 100644 --- a/submodules/TelegramBaseController/Sources/TelegramBaseController.swift +++ b/submodules/TelegramBaseController/Sources/TelegramBaseController.swift @@ -38,7 +38,8 @@ private func presentLiveLocationController(context: AccountContext, peerId: Peer }, openUrl: { _ in }, openPeer: { peer, navigation in }, callPeer: { _, _ in - }, enqueueMessage: { _ in + }, enqueueMessage: { message in + let _ = enqueueMessages(account: context.account, peerId: peerId, messages: [message]).start() }, sendSticker: nil, setupTemporaryHiddenMedia: { _, _, _ in }, chatAvatarHiddenMedia: { _, _ in