|
@@ -107,8 +107,8 @@ class AppCoordinator: NSObject, Coordinator, UITabBarControllerDelegate {
|
|
|
|
|
|
func presentLoginController() {
|
|
func presentLoginController() {
|
|
let accountSetupController = AccountSetupController()
|
|
let accountSetupController = AccountSetupController()
|
|
- let accountSetupNavigationController = DCNavigationController(rootViewController: accountSetupController)
|
|
|
|
- rootViewController.present(accountSetupNavigationController, animated: false, completion: nil)
|
|
|
|
|
|
+ let accountSetupNav = DCNavigationController(rootViewController: accountSetupController)
|
|
|
|
+ rootViewController.present(accountSetupNav, animated: false, completion: nil)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -119,7 +119,7 @@ extension AppCoordinator: UITabBarDelegate {
|
|
|
|
|
|
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
|
|
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
|
|
print("shouldSelect")
|
|
print("shouldSelect")
|
|
- return true
|
|
|
|
|
|
+ return true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -415,25 +415,49 @@ class ChatViewCoordinator: NSObject, Coordinator {
|
|
// navigationController.present(nav, animated: true, completion: nil)
|
|
// navigationController.present(nav, animated: true, completion: nil)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private func sendImage(_ image:UIImage) {
|
|
|
|
+ DispatchQueue.global().async {
|
|
|
|
+ if let compressedImage = image.dcCompress() {
|
|
|
|
+ // at this point image is compressed by 85% by default
|
|
|
|
+ let pixelSize = compressedImage.imageSizeInPixel()
|
|
|
|
+ let width = Int32(exactly: pixelSize.width)!
|
|
|
|
+ let height = Int32(exactly: pixelSize.height)!
|
|
|
|
+ let path = Utils.saveImage(image: compressedImage)
|
|
|
|
+ let msg = dc_msg_new(mailboxPointer, DC_MSG_IMAGE)
|
|
|
|
+ dc_msg_set_file(msg, path, "image/jpeg")
|
|
|
|
+ dc_msg_set_dimension(msg, width, height)
|
|
|
|
+ dc_send_msg(mailboxPointer, UInt32(self.chatId), msg)
|
|
|
|
+ // cleanup
|
|
|
|
+ dc_msg_unref(msg)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private func sendVideo(url: NSURL) {
|
|
|
|
+ let msg = dc_msg_new(mailboxPointer, DC_MSG_VIDEO)
|
|
|
|
+ if let path = url.relativePath?.cString(using: .utf8) { //absoluteString?.cString(using: .utf8) {
|
|
|
|
+ dc_msg_set_file(msg, path, nil)
|
|
|
|
+ dc_send_msg(mailboxPointer, UInt32(chatId), msg)
|
|
|
|
+ dc_msg_unref(msg)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private func handleMediaMessageSuccess() {
|
|
|
|
+ if let chatViewController = self.navigationController.visibleViewController as? MediaSendHandler {
|
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
|
|
|
+ chatViewController.onSuccess()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
func showCameraViewController() {
|
|
func showCameraViewController() {
|
|
if UIImagePickerController.isSourceTypeAvailable(.camera) {
|
|
if UIImagePickerController.isSourceTypeAvailable(.camera) {
|
|
let cameraViewController = CameraViewController { [weak self] image, _ in
|
|
let cameraViewController = CameraViewController { [weak self] image, _ in
|
|
- self?.navigationController.dismiss(animated: true, completion: nil)
|
|
|
|
-
|
|
|
|
- DispatchQueue.global().async {
|
|
|
|
- if let compressedImage = image?.dcCompress() {
|
|
|
|
- // at this point image is compressed by 85% by default
|
|
|
|
- let pixelSize = compressedImage.imageSizeInPixel()
|
|
|
|
- let width = Int32(exactly: pixelSize.width)!
|
|
|
|
- let height = Int32(exactly: pixelSize.height)!
|
|
|
|
- let path = Utils.saveImage(image: compressedImage)
|
|
|
|
- let msg = dc_msg_new(mailboxPointer, DC_MSG_IMAGE)
|
|
|
|
- dc_msg_set_file(msg, path, "image/jpeg")
|
|
|
|
- dc_msg_set_dimension(msg, width, height)
|
|
|
|
- dc_send_msg(mailboxPointer, UInt32(self!.chatId), msg)
|
|
|
|
- // cleanup
|
|
|
|
- dc_msg_unref(msg)
|
|
|
|
- }
|
|
|
|
|
|
+ self?.navigationController.dismiss(animated: true, completion: {
|
|
|
|
+ self?.handleMediaMessageSuccess()
|
|
|
|
+ })
|
|
|
|
+ if let image = image {
|
|
|
|
+ self?.sendImage(image)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -449,10 +473,11 @@ class ChatViewCoordinator: NSObject, Coordinator {
|
|
}
|
|
}
|
|
func showVideoLibrary() {
|
|
func showVideoLibrary() {
|
|
if PHPhotoLibrary.authorizationStatus() != .authorized {
|
|
if PHPhotoLibrary.authorizationStatus() != .authorized {
|
|
- PHPhotoLibrary.requestAuthorization{status in
|
|
|
|
- DispatchQueue.main.async() { [weak self] in
|
|
|
|
|
|
+ PHPhotoLibrary.requestAuthorization { status in
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ [weak self] in
|
|
switch status {
|
|
switch status {
|
|
- case .denied,.notDetermined,.restricted:
|
|
|
|
|
|
+ case .denied, .notDetermined, .restricted:
|
|
print("denied")
|
|
print("denied")
|
|
case .authorized:
|
|
case .authorized:
|
|
self?.presentVideoLibrary()
|
|
self?.presentVideoLibrary()
|
|
@@ -465,7 +490,7 @@ class ChatViewCoordinator: NSObject, Coordinator {
|
|
}
|
|
}
|
|
|
|
|
|
private func presentVideoLibrary() {
|
|
private func presentVideoLibrary() {
|
|
- if UIImagePickerController.isSourceTypeAvailable(.photoLibrary){
|
|
|
|
|
|
+ if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) {
|
|
let videoPicker = UIImagePickerController()
|
|
let videoPicker = UIImagePickerController()
|
|
videoPicker.title = "Videos"
|
|
videoPicker.title = "Videos"
|
|
videoPicker.delegate = self
|
|
videoPicker.delegate = self
|
|
@@ -478,26 +503,13 @@ class ChatViewCoordinator: NSObject, Coordinator {
|
|
|
|
|
|
extension ChatViewCoordinator: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
|
|
extension ChatViewCoordinator: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
|
|
|
|
|
|
- func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
|
|
|
|
- if let videoUrl = info[UIImagePickerController.InfoKey.mediaURL] as? NSURL{
|
|
|
|
- print("videourl: ", videoUrl)
|
|
|
|
- //trying compression of video
|
|
|
|
- let data = NSData(contentsOf: videoUrl as URL)!
|
|
|
|
- print("File size before compression: \(Double(data.length / 1048576)) mb")
|
|
|
|
- let size = Double(data.length / 1048576)
|
|
|
|
- print(size)
|
|
|
|
- let msg = dc_msg_new(mailboxPointer, DC_MSG_VIDEO)
|
|
|
|
- if let path = videoUrl.relativePath?.cString(using: .utf8) { //absoluteString?.cString(using: .utf8) {
|
|
|
|
- dc_msg_set_file(msg, path, nil)
|
|
|
|
- dc_send_msg(mailboxPointer, UInt32(chatId), msg)
|
|
|
|
- dc_msg_unref(msg)
|
|
|
|
- }
|
|
|
|
- // self.videoPickedBlock?(videoUrl, size)
|
|
|
|
|
|
+ func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
|
|
|
|
+ if let videoUrl = info[UIImagePickerController.InfoKey.mediaURL] as? NSURL {
|
|
|
|
+ sendVideo(url: videoUrl)
|
|
}
|
|
}
|
|
- else{
|
|
|
|
- print("Something went wrong in video")
|
|
|
|
|
|
+ navigationController.dismiss(animated: true) {
|
|
|
|
+ self.handleMediaMessageSuccess()
|
|
}
|
|
}
|
|
- navigationController.dismiss(animated: true, completion: nil)
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -519,8 +531,6 @@ class NewGroupCoordinator: Coordinator {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
class GroupNameCoordinator: Coordinator {
|
|
class GroupNameCoordinator: Coordinator {
|
|
let navigationController: UINavigationController
|
|
let navigationController: UINavigationController
|
|
|
|
|