|
|
@ -1,5 +1,6 @@
|
|
|
|
import CoreServices
|
|
|
|
import CoreServices
|
|
|
|
import Photos
|
|
|
|
import Photos
|
|
|
|
|
|
|
|
import PhotosUI
|
|
|
|
|
|
|
|
|
|
|
|
extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuActionDelegate, ScrollToBottomButtonDelegate,
|
|
|
|
extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuActionDelegate, ScrollToBottomButtonDelegate,
|
|
|
|
SendMediaNavDelegate, UIDocumentPickerDelegate, AttachmentApprovalViewControllerDelegate, GifPickerViewControllerDelegate,
|
|
|
|
SendMediaNavDelegate, UIDocumentPickerDelegate, AttachmentApprovalViewControllerDelegate, GifPickerViewControllerDelegate,
|
|
|
@ -91,12 +92,14 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func handleLibraryButtonTapped() {
|
|
|
|
func handleLibraryButtonTapped() {
|
|
|
|
// FIXME: We're not yet handling the case where the user only gives access to selected photos/videos
|
|
|
|
requestLibraryPermissionIfNeeded { [weak self] in
|
|
|
|
guard requestLibraryPermissionIfNeeded() else { return }
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
let sendMediaNavController = SendMediaNavigationController.showingMediaLibraryFirst()
|
|
|
|
let sendMediaNavController = SendMediaNavigationController.showingMediaLibraryFirst()
|
|
|
|
sendMediaNavController.sendMediaNavDelegate = self
|
|
|
|
sendMediaNavController.sendMediaNavDelegate = self
|
|
|
|
sendMediaNavController.modalPresentationStyle = .fullScreen
|
|
|
|
sendMediaNavController.modalPresentationStyle = .fullScreen
|
|
|
|
present(sendMediaNavController, animated: true, completion: nil)
|
|
|
|
self?.present(sendMediaNavController, animated: true, completion: nil)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func handleGIFButtonTapped() {
|
|
|
|
func handleGIFButtonTapped() {
|
|
|
@ -752,19 +755,54 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func requestLibraryPermissionIfNeeded() -> Bool {
|
|
|
|
func requestLibraryPermissionIfNeeded(onAuthorized: @escaping () -> Void) {
|
|
|
|
switch PHPhotoLibrary.authorizationStatus() {
|
|
|
|
let authorizationStatus: PHAuthorizationStatus
|
|
|
|
case .authorized, .limited: return true
|
|
|
|
if #available(iOS 14, *) {
|
|
|
|
|
|
|
|
authorizationStatus = PHPhotoLibrary.authorizationStatus(for: .readWrite)
|
|
|
|
|
|
|
|
if authorizationStatus == .notDetermined {
|
|
|
|
|
|
|
|
// When the user chooses to select photos (which is the .limit status),
|
|
|
|
|
|
|
|
// the PHPhotoUI will present the picker view on the top of the front view.
|
|
|
|
|
|
|
|
// Since we have the ScreenLockUI showing when we request premissions,
|
|
|
|
|
|
|
|
// the picker view will be presented on the top of the ScreenLockUI.
|
|
|
|
|
|
|
|
// However, the ScreenLockUI will dismiss with the permission request alert view, so
|
|
|
|
|
|
|
|
// the picker view then will dismiss, too. The selection process cannot be finished
|
|
|
|
|
|
|
|
// this way. So we add a flag (isRequestingPermission) to prevent the ScreenLockUI
|
|
|
|
|
|
|
|
// from showing when we request the photo library permission.
|
|
|
|
|
|
|
|
Environment.shared.isRequestingPermission = true
|
|
|
|
|
|
|
|
let appMode = AppModeManager.shared.currentAppMode
|
|
|
|
|
|
|
|
// FIXME: Rather than setting the app mode to light and then to dark again once we're done,
|
|
|
|
|
|
|
|
// it'd be better to just customize the appearance of the image picker. There doesn't currently
|
|
|
|
|
|
|
|
// appear to be a good way to do so though...
|
|
|
|
|
|
|
|
AppModeManager.shared.setCurrentAppMode(to: .light)
|
|
|
|
|
|
|
|
PHPhotoLibrary.requestAuthorization(for: .readWrite) { status in
|
|
|
|
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
|
|
|
|
AppModeManager.shared.setCurrentAppMode(to: appMode)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Environment.shared.isRequestingPermission = false
|
|
|
|
|
|
|
|
if [ PHAuthorizationStatus.authorized, PHAuthorizationStatus.limited ].contains(status) {
|
|
|
|
|
|
|
|
onAuthorized()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
authorizationStatus = PHPhotoLibrary.authorizationStatus()
|
|
|
|
|
|
|
|
if authorizationStatus == .notDetermined {
|
|
|
|
|
|
|
|
PHPhotoLibrary.requestAuthorization { status in
|
|
|
|
|
|
|
|
if status == .authorized {
|
|
|
|
|
|
|
|
onAuthorized()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
switch authorizationStatus {
|
|
|
|
|
|
|
|
case .authorized, .limited:
|
|
|
|
|
|
|
|
onAuthorized()
|
|
|
|
case .denied, .restricted:
|
|
|
|
case .denied, .restricted:
|
|
|
|
let modal = PermissionMissingModal(permission: "library") { }
|
|
|
|
let modal = PermissionMissingModal(permission: "library") { }
|
|
|
|
modal.modalPresentationStyle = .overFullScreen
|
|
|
|
modal.modalPresentationStyle = .overFullScreen
|
|
|
|
modal.modalTransitionStyle = .crossDissolve
|
|
|
|
modal.modalTransitionStyle = .crossDissolve
|
|
|
|
present(modal, animated: true, completion: nil)
|
|
|
|
present(modal, animated: true, completion: nil)
|
|
|
|
return false
|
|
|
|
default: return
|
|
|
|
case .notDetermined:
|
|
|
|
|
|
|
|
PHPhotoLibrary.requestAuthorization { _ in }
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
default: return false
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|