|
@@ -59,10 +59,12 @@ class ChatViewController: MessagesViewController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- override func viewDidAppear(_ animated: Bool) {
|
|
|
+ override func viewWillAppear(_ animated: Bool) {
|
|
|
+ super.viewWillAppear(animated)
|
|
|
+
|
|
|
let nc = NotificationCenter.default
|
|
|
- msgChangedObserver = nc.addObserver(forName:Notification.Name(rawValue:"MrEventMsgsChanged"),
|
|
|
- object:nil, queue:nil) {
|
|
|
+ msgChangedObserver = nc.addObserver(forName:notificationChanged,
|
|
|
+ object:nil, queue: OperationQueue.main) {
|
|
|
notification in
|
|
|
print("----------- MrEventMsgsChanged notification received --------")
|
|
|
self.getMessageIds()
|
|
@@ -70,8 +72,8 @@ class ChatViewController: MessagesViewController {
|
|
|
self.messagesCollectionView.scrollToBottom()
|
|
|
}
|
|
|
|
|
|
- incomingMsgObserver = nc.addObserver(forName:Notification.Name(rawValue:"MrEventIncomingMsg"),
|
|
|
- object:nil, queue:nil) {
|
|
|
+ incomingMsgObserver = nc.addObserver(forName:notificationIncoming,
|
|
|
+ object:nil, queue: OperationQueue.main) {
|
|
|
notification in
|
|
|
print("----------- MrEventIncomingMsg received --------")
|
|
|
self.getMessageIds()
|
|
@@ -87,6 +89,8 @@ class ChatViewController: MessagesViewController {
|
|
|
}
|
|
|
|
|
|
override func viewWillDisappear(_ animated: Bool) {
|
|
|
+ super.viewDidDisappear(animated)
|
|
|
+
|
|
|
setTextDraft()
|
|
|
let nc = NotificationCenter.default
|
|
|
if let msgChangedObserver = self.msgChangedObserver {
|
|
@@ -425,12 +429,15 @@ extension ChatViewController: MessagesLayoutDelegate {
|
|
|
|
|
|
extension ChatViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
|
|
|
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
|
|
|
- if let pickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage,
|
|
|
- let width = Int32(exactly: pickedImage.size.width),
|
|
|
- let height = Int32(exactly: pickedImage.size.height),
|
|
|
- let path = saveImage(image: pickedImage) {
|
|
|
- dc_send_image_msg(mailboxPointer, UInt32(self.chatId), path, "image/jpeg", width, height)
|
|
|
+ DispatchQueue.global().async {
|
|
|
+ if let pickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage,
|
|
|
+ let width = Int32(exactly: pickedImage.size.width),
|
|
|
+ let height = Int32(exactly: pickedImage.size.height),
|
|
|
+ let path = self.saveImage(image: pickedImage) {
|
|
|
+ dc_send_image_msg(mailboxPointer, UInt32(self.chatId), path, "image/jpeg", width, height)
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
dismiss(animated: true, completion: nil)
|
|
|
}
|
|
|
}
|