From adea2656742f92a414017eb8b84e5e6418a37c71 Mon Sep 17 00:00:00 2001 From: saeedrooyekhat Date: Wed, 14 Mar 2018 13:07:21 +0330 Subject: [PATCH] Improvement open chat from call even room not exist in room list --- .../View Controllers/Call/IGCall.swift | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/iGap/Controller/View Controllers/Call/IGCall.swift b/iGap/Controller/View Controllers/Call/IGCall.swift index 131f34b..aa45e10 100644 --- a/iGap/Controller/View Controllers/Call/IGCall.swift +++ b/iGap/Controller/View Controllers/Call/IGCall.swift @@ -74,9 +74,32 @@ class IGCall: UIViewController, CallStateObserver, ReturnToCallObserver { let realm = try! Realm() let predicate = NSPredicate(format: "chatRoom.peer.id = %lld", userId) - if let roomInfo = try realm.objects(IGRoom.self).filter(predicate).first { + if let roomInfo = try! realm.objects(IGRoom.self).filter(predicate).first { room = roomInfo performSegue(withIdentifier: "showRoomMessages", sender: self) + } else { + IGChatGetRoomRequest.Generator.generate(peerId: userId).success({ (protoResponse) in + DispatchQueue.main.async { + if let chatGetRoomResponse = protoResponse as? IGPChatGetRoomResponse { + IGChatGetRoomRequest.Handler.interpret(response: chatGetRoomResponse) + self.room = IGRoom(igpRoom: chatGetRoomResponse.igpRoom) + self.performSegue(withIdentifier: "showRoomMessages", sender: self) + } + } + }).error({ (errorCode, waitTime) in + switch errorCode { + case .timeout: + DispatchQueue.main.async { + let alert = UIAlertController(title: "Timeout", message: "Please try again later", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + } + default: + break + } + + }).send() } }