diff --git a/submodules/LegacyComponents/Sources/TGMediaAssetsController.m b/submodules/LegacyComponents/Sources/TGMediaAssetsController.m index 24ffeecb78..25327d303a 100644 --- a/submodules/LegacyComponents/Sources/TGMediaAssetsController.m +++ b/submodules/LegacyComponents/Sources/TGMediaAssetsController.m @@ -67,7 +67,7 @@ + (instancetype)controllerWithContext:(id)context assetGroup:(TGMediaAssetGroup *)assetGroup intent:(TGMediaAssetsControllerIntent)intent recipientName:(NSString *)recipientName saveEditedPhotos:(bool)saveEditedPhotos allowGrouping:(bool)allowGrouping inhibitSelection:(bool)inhibitSelection selectionLimit:(int)selectionLimit { - if (intent != TGMediaAssetsControllerSendMediaIntent) + if (intent != TGMediaAssetsControllerSendMediaIntent && intent != TGMediaAssetsControllerSendFileIntent) allowGrouping = false; TGMediaAssetsController *assetsController = [[TGMediaAssetsController alloc] initWithContext:context intent:intent saveEditedPhotos:saveEditedPhotos allowGrouping:allowGrouping selectionLimit:selectionLimit]; @@ -735,6 +735,9 @@ dict[@"fileName"] = assetData.fileName; dict[@"mimeType"] = TGMimeTypeForFileUTI(assetData.fileUTI); + if (groupedId != nil) + dict[@"groupedId"] = groupedId; + id generatedItem = descriptionGenerator(dict, caption, entities, nil); return generatedItem; }] catch:^SSignal *(id error) @@ -752,6 +755,9 @@ dict[@"mimeType"] = TGMimeTypeForFileUTI(asset.uniformTypeIdentifier); dict[@"fileName"] = asset.fileName; + if (groupedId != nil) + dict[@"groupedId"] = groupedId; + id generatedItem = descriptionGenerator(dict, caption, entities, nil); return generatedItem; }]; @@ -971,6 +977,9 @@ if (adjustments.paintingData.stickers.count > 0) dict[@"stickers"] = adjustments.paintingData.stickers; + if (groupedId != nil) + dict[@"groupedId"] = groupedId; + id generatedItem = descriptionGenerator(dict, caption, entities, nil); return generatedItem; }]]; diff --git a/submodules/LegacyMediaPickerUI/Sources/LegacyMediaPickers.swift b/submodules/LegacyMediaPickerUI/Sources/LegacyMediaPickers.swift index 72377a327e..0a859df6fc 100644 --- a/submodules/LegacyMediaPickerUI/Sources/LegacyMediaPickers.swift +++ b/submodules/LegacyMediaPickerUI/Sources/LegacyMediaPickers.swift @@ -184,7 +184,7 @@ public func legacyAssetPickerItemGenerator() -> ((Any?, String?, [Any]?, String? name = customName } - result["item" as NSString] = LegacyAssetItemWrapper(item: .file(data: .asset(asset.backingAsset), thumbnail: thumbnail, mimeType: mimeType, name: name, caption: caption), timer: nil, groupedId: nil) + result["item" as NSString] = LegacyAssetItemWrapper(item: .file(data: .asset(asset.backingAsset), thumbnail: thumbnail, mimeType: mimeType, name: name, caption: caption), timer: nil, groupedId: (dict["groupedId"] as? NSNumber)?.int64Value) } else { result["item" as NSString] = LegacyAssetItemWrapper(item: .image(data: .asset(asset.backingAsset), thumbnail: thumbnail, caption: caption, stickers: []), timer: (dict["timer"] as? NSNumber)?.intValue, groupedId: (dict["groupedId"] as? NSNumber)?.int64Value) } diff --git a/submodules/LocationUI/Sources/LocationMapNode.swift b/submodules/LocationUI/Sources/LocationMapNode.swift index 107cf7d856..e214920f44 100644 --- a/submodules/LocationUI/Sources/LocationMapNode.swift +++ b/submodules/LocationUI/Sources/LocationMapNode.swift @@ -545,6 +545,27 @@ final class LocationMapNode: ASDisplayNode, MKMapViewDelegate { self.pinDisposable.set(nil) } + func showAll(animated: Bool = true) { + guard let mapView = self.mapView else { + return + } + var annotations: [MKAnnotation] = [] + if let userAnnotation = self.userLocationAnnotation { + annotations.append(userAnnotation) + } + annotations.append(contentsOf: self.annotations) + + var zoomRect: MKMapRect = MKMapRect() + for annotation in annotations { + let pointRegionRect = MKMapRect(region: MKCoordinateRegion(center: annotation.coordinate, latitudinalMeters: 100, longitudinalMeters: 100)) + zoomRect = zoomRect.union(pointRegionRect) + } + + let insets = UIEdgeInsets() + zoomRect = mapView.mapRectThatFits(zoomRect, edgePadding: insets) + mapView.setVisibleMapRect(zoomRect, animated: animated) + } + func updateLayout(size: CGSize) { self.proximityDimView.frame = CGRect(origin: CGPoint(), size: size) self.pickerAnnotationContainerView.frame = CGRect(x: 0.0, y: floorToScreenPixels((size.height - size.width) / 2.0), width: size.width, height: size.width) diff --git a/submodules/LocationUI/Sources/LocationViewController.swift b/submodules/LocationUI/Sources/LocationViewController.swift index 78f86cbd5e..a4601dfd07 100644 --- a/submodules/LocationUI/Sources/LocationViewController.swift +++ b/submodules/LocationUI/Sources/LocationViewController.swift @@ -29,6 +29,12 @@ public class LocationViewParams { } } +enum LocationViewRightBarButton { + case none + case share + case showAll +} + class LocationViewInteraction { let toggleMapModeSelection: () -> Void let updateMapMode: (LocationMapMode) -> Void @@ -40,8 +46,9 @@ class LocationViewInteraction { let updateSendActionHighlight: (Bool) -> Void let sendLiveLocation: (CLLocationCoordinate2D) -> Void let stopLiveLocation: () -> Void + let updateRightBarButton: (LocationViewRightBarButton) -> Void - init(toggleMapModeSelection: @escaping () -> Void, updateMapMode: @escaping (LocationMapMode) -> Void, goToUserLocation: @escaping () -> Void, goToCoordinate: @escaping (CLLocationCoordinate2D) -> Void, requestDirections: @escaping () -> Void, share: @escaping () -> Void, setupProximityNotification: @escaping (CLLocationCoordinate2D, Bool) -> Void, updateSendActionHighlight: @escaping (Bool) -> Void, sendLiveLocation: @escaping (CLLocationCoordinate2D) -> Void, stopLiveLocation: @escaping () -> Void) { + init(toggleMapModeSelection: @escaping () -> Void, updateMapMode: @escaping (LocationMapMode) -> Void, goToUserLocation: @escaping () -> Void, goToCoordinate: @escaping (CLLocationCoordinate2D) -> Void, requestDirections: @escaping () -> Void, share: @escaping () -> Void, setupProximityNotification: @escaping (CLLocationCoordinate2D, Bool) -> Void, updateSendActionHighlight: @escaping (Bool) -> Void, sendLiveLocation: @escaping (CLLocationCoordinate2D) -> Void, stopLiveLocation: @escaping () -> Void, updateRightBarButton: @escaping (LocationViewRightBarButton) -> Void) { self.toggleMapModeSelection = toggleMapModeSelection self.updateMapMode = updateMapMode self.goToUserLocation = goToUserLocation @@ -52,6 +59,7 @@ class LocationViewInteraction { self.updateSendActionHighlight = updateSendActionHighlight self.sendLiveLocation = sendLiveLocation self.stopLiveLocation = stopLiveLocation + self.updateRightBarButton = updateRightBarButton } } @@ -70,6 +78,8 @@ public final class LocationViewController: ViewController { private var permissionDisposable: Disposable? private var interaction: LocationViewInteraction? + + private var rightBarButtonAction: LocationViewRightBarButton = .none public init(context: AccountContext, subject: Message, params: LocationViewParams) { self.context = context @@ -83,8 +93,6 @@ public final class LocationViewController: ViewController { self.title = self.presentationData.strings.Map_LocationTitle self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: self.presentationData.strings.Common_Close, style: .plain, target: self, action: #selector(self.cancelPressed)) - self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: PresentationResourcesRootController.navigationShareIcon(self.presentationData.theme), style: .plain, target: self, action: #selector(self.sharePressed)) - self.navigationItem.rightBarButtonItem?.accessibilityLabel = self.presentationData.strings.VoiceOver_MessageContextShare self.presentationDataDisposable = (context.sharedContext.presentationData |> deliverOnMainQueue).start(next: { [weak self] presentationData in @@ -95,7 +103,7 @@ public final class LocationViewController: ViewController { strongSelf.navigationBar?.updatePresentationData(NavigationBarPresentationData(theme: NavigationBarTheme(rootControllerTheme: strongSelf.presentationData.theme).withUpdatedSeparatorColor(.clear), strings: NavigationBarStrings(presentationStrings: strongSelf.presentationData.strings))) - strongSelf.navigationItem.rightBarButtonItem = UIBarButtonItem(image: PresentationResourcesRootController.navigationShareIcon(strongSelf.presentationData.theme), style: .plain, target: strongSelf, action: #selector(strongSelf.sharePressed)) + strongSelf.updateRightBarButton() if strongSelf.isNodeLoaded { strongSelf.controllerNode.updatePresentationData(presentationData) @@ -247,6 +255,15 @@ public final class LocationViewController: ViewController { }, stopLiveLocation: { [weak self] in params.stopLiveLocation() self?.dismiss() + }, updateRightBarButton: { [weak self] action in + guard let strongSelf = self else { + return + } + + if action != strongSelf.rightBarButtonAction { + strongSelf.rightBarButtonAction = action + strongSelf.updateRightBarButton() + } }) self.scrollToTop = { [weak self] in @@ -280,6 +297,18 @@ public final class LocationViewController: ViewController { } } + private func updateRightBarButton() { + switch self.rightBarButtonAction { + case .none: + self.navigationItem.rightBarButtonItem = nil + case .share: + self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: PresentationResourcesRootController.navigationShareIcon(self.presentationData.theme), style: .plain, target: self, action: #selector(self.sharePressed)) + self.navigationItem.rightBarButtonItem?.accessibilityLabel = self.presentationData.strings.VoiceOver_MessageContextShare + case .showAll: + self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: self.presentationData.strings.Map_LiveLocationShowAll, style: .plain, target: self, action: #selector(self.showAllPressed)) + } + } + override public func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) { super.containerLayoutUpdated(layout, transition: transition) @@ -295,7 +324,7 @@ public final class LocationViewController: ViewController { } @objc private func showAllPressed() { - self.dismiss() + self.controllerNode.showAll() } } diff --git a/submodules/LocationUI/Sources/LocationViewControllerNode.swift b/submodules/LocationUI/Sources/LocationViewControllerNode.swift index ca90e9b856..5e8bd920be 100644 --- a/submodules/LocationUI/Sources/LocationViewControllerNode.swift +++ b/submodules/LocationUI/Sources/LocationViewControllerNode.swift @@ -113,7 +113,7 @@ private enum LocationViewEntry: Comparable, Identifiable { func item(account: Account, presentationData: PresentationData, interaction: LocationViewInteraction?) -> ListViewItem { switch self { - case let .info(theme, location, address, distance, time): + case let .info(_, location, address, distance, time): let addressString: String? if let address = address { addressString = address @@ -132,7 +132,7 @@ private enum LocationViewEntry: Comparable, Identifiable { }, getDirections: { interaction?.requestDirections() }) - case let .toggleLiveLocation(theme, title, subtitle, coordinate, beginTimstamp, timeout): + case let .toggleLiveLocation(_, title, subtitle, coordinate, beginTimstamp, timeout): let beginTimeAndTimeout: (Double, Double)? if let beginTimstamp = beginTimstamp, let timeout = timeout { beginTimeAndTimeout = (beginTimstamp, timeout) @@ -403,6 +403,18 @@ final class LocationViewControllerNode: ViewControllerTracingNode { strongSelf.headerNode.mapNode.activeProximityRadius = state.proximityRadius + let rightBarButtonAction: LocationViewRightBarButton + if location.liveBroadcastingTimeout != nil { + if liveLocations.count > 1 { + rightBarButtonAction = .showAll + } else { + rightBarButtonAction = .none + } + } else { + rightBarButtonAction = .share + } + strongSelf.interaction.updateRightBarButton(rightBarButtonAction) + if let (layout, navigationBarHeight) = strongSelf.validLayout { var updateLayout = false let transition: ContainedViewLayoutTransition = .animated(duration: 0.45, curve: .spring) @@ -534,6 +546,10 @@ final class LocationViewControllerNode: ViewControllerTracingNode { } } + func showAll() { + self.headerNode.mapNode.showAll() + } + func containerLayoutUpdated(_ layout: ContainerViewLayout, navigationHeight: CGFloat, transition: ContainedViewLayoutTransition) { let isFirstLayout = self.validLayout == nil self.validLayout = (layout, navigationHeight) diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 4f6929aaac..168e497d32 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -7171,6 +7171,9 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G let message: EnqueueMessage = .message(text: "", attributes: [], mediaReference: .standalone(media: file), replyToMessageId: replyMessageId, localGroupingKey: groupingKey) messages.append(message) } + if let _ = groupingKey, results.count % 10 == 0 { + groupingKey = arc4random64() + } } if !messages.isEmpty { diff --git a/submodules/TelegramUI/Sources/ChatMessageFileBubbleContentNode.swift b/submodules/TelegramUI/Sources/ChatMessageFileBubbleContentNode.swift index 33f55cdf07..2edf78f184 100644 --- a/submodules/TelegramUI/Sources/ChatMessageFileBubbleContentNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageFileBubbleContentNode.swift @@ -104,7 +104,7 @@ class ChatMessageFileBubbleContentNode: ChatMessageBubbleContentNode { if case let .linear(_, bottom) = position { if case .Neighbour(_, _, .condensed) = bottom { if selectedFile?.isMusic ?? false { - bottomInset -= 14.0 +// bottomInset -= 14.0 } else { bottomInset -= 10.0 }