|
@@ -149,9 +149,8 @@ class ChatViewController: MessagesViewController {
|
|
|
// this will be removed in viewWillDisappear
|
|
|
navigationController?.navigationBar.addGestureRecognizer(navBarTap)
|
|
|
|
|
|
- let chat = DcChat(id: chatId)
|
|
|
if showCustomNavBar {
|
|
|
- updateTitle(chat: chat)
|
|
|
+ updateTitle(chat: DcChat(id: chatId))
|
|
|
}
|
|
|
|
|
|
configureMessageMenu()
|
|
@@ -175,7 +174,7 @@ class ChatViewController: MessagesViewController {
|
|
|
}
|
|
|
}
|
|
|
if self.showCustomNavBar {
|
|
|
- self.updateTitle(chat: chat)
|
|
|
+ self.updateTitle(chat: DcChat(id: self.chatId))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -233,6 +232,15 @@ class ChatViewController: MessagesViewController {
|
|
|
stopTimer()
|
|
|
}
|
|
|
|
|
|
+ override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
|
|
|
+ coordinator.animate(alongsideTransition: { (_) -> Void in
|
|
|
+ if self.showCustomNavBar, let titleView = self.navigationItem.titleView as? ChatTitleView {
|
|
|
+ titleView.hideLocationStreamingIndicator() }},
|
|
|
+ completion: { (_) -> Void in
|
|
|
+ self.updateTitle(chat: DcChat(id: self.chatId)) })
|
|
|
+ super.viewWillTransition(to: size, with: coordinator)
|
|
|
+ }
|
|
|
+
|
|
|
private func updateTitle(chat: DcChat) {
|
|
|
let titleView = ChatTitleView()
|
|
|
|
|
@@ -250,7 +258,7 @@ class ChatViewController: MessagesViewController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- titleView.updateTitleView(title: chat.name, subtitle: subtitle)
|
|
|
+ titleView.updateTitleView(title: chat.name, subtitle: subtitle, isLocationStreaming: chat.isSendingLocations)
|
|
|
navigationItem.titleView = titleView
|
|
|
|
|
|
let badge: InitialsBadge
|
|
@@ -1094,11 +1102,16 @@ extension ChatViewController: MessagesLayoutDelegate {
|
|
|
let cameraAction = PhotoPickerAlertAction(title: String.localized("camera"), style: .default, handler: cameraButtonPressed(_:))
|
|
|
let documentAction = UIAlertAction(title: String.localized("documents"), style: .default, handler: documentActionPressed(_:))
|
|
|
let voiceMessageAction = UIAlertAction(title: String.localized("voice_message"), style: .default, handler: voiceMessageButtonPressed(_:))
|
|
|
+ let isLocationStreaming = dcContext.isSendingLocationsToChat(chatId: chatId)
|
|
|
+ let locationStreamingAction = UIAlertAction(title: isLocationStreaming ? String.localized("stop_sharing_location") : String.localized("location"),
|
|
|
+ style: isLocationStreaming ? .destructive : .default,
|
|
|
+ handler: locationStreamingButtonPressed(_:))
|
|
|
|
|
|
alert.addAction(cameraAction)
|
|
|
alert.addAction(galleryAction)
|
|
|
alert.addAction(documentAction)
|
|
|
alert.addAction(voiceMessageAction)
|
|
|
+ alert.addAction(locationStreamingAction)
|
|
|
alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
|
|
|
self.present(alert, animated: true, completion: nil)
|
|
|
}
|
|
@@ -1119,6 +1132,37 @@ extension ChatViewController: MessagesLayoutDelegate {
|
|
|
coordinator?.showPhotoVideoLibrary(delegate: self)
|
|
|
}
|
|
|
|
|
|
+ private func locationStreamingButtonPressed(_ action: UIAlertAction) {
|
|
|
+ let isLocationStreaming = dcContext.isSendingLocationsToChat(chatId: chatId)
|
|
|
+ if isLocationStreaming {
|
|
|
+ locationStreamingFor(seconds: 0)
|
|
|
+ } else {
|
|
|
+ let alert = UIAlertController(title: String.localized("title_share_location"), message: nil, preferredStyle: .safeActionSheet)
|
|
|
+ addDurationSelectionAction(to: alert, key: "share_location_for_5_minutes", duration: Time.fiveMinutes)
|
|
|
+ addDurationSelectionAction(to: alert, key: "share_location_for_30_minutes", duration: Time.thirtyMinutes)
|
|
|
+ addDurationSelectionAction(to: alert, key: "share_location_for_one_hour", duration: Time.oneHour)
|
|
|
+ addDurationSelectionAction(to: alert, key: "share_location_for_two_hours", duration: Time.twoHours)
|
|
|
+ addDurationSelectionAction(to: alert, key: "share_location_for_six_hours", duration: Time.sixHours)
|
|
|
+ alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
|
|
|
+ self.present(alert, animated: true, completion: nil)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private func addDurationSelectionAction(to alert: UIAlertController, key: String, duration: Int) {
|
|
|
+ let action = UIAlertAction(title: String.localized(key), style: .default, handler: { _ in
|
|
|
+ self.locationStreamingFor(seconds: duration)
|
|
|
+ })
|
|
|
+ alert.addAction(action)
|
|
|
+ }
|
|
|
+
|
|
|
+ private func locationStreamingFor(seconds: Int) {
|
|
|
+ guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ self.dcContext.sendLocationsToChat(chatId: self.chatId, seconds: seconds)
|
|
|
+ appDelegate.locationManager.shareLocation(chatId: self.chatId, duration: seconds)
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// MARK: - MessageCellDelegate
|