diff --git a/Cartfile b/Cartfile index b26d142..4881ea6 100644 --- a/Cartfile +++ b/Cartfile @@ -13,8 +13,8 @@ github "krzyzanowskim/CryptoSwift" github "RooyeKhat-Media/Gifu" "v2.0.0-b" github "RooyeKhat-Media/ALCameraViewController" "1.2.7" -github "RooyeKhat-Media/IGProtoBuffLibrary" "build47-5" -github "RooyeKhat-Media/INSPhotoGallery" "1.1.0-a" +github "RooyeKhat-Media/IGProtoBuffLibrary" "build54" +github "RooyeKhat-Media/INSPhotoGallery" "1.1.0-d" github "RooyeKhat-Media/Starscream" "2.0.4-a" github "RooyeKhat-Media/DBAttachmentPickerController" "1.1.4-a" diff --git a/Cartfile.resolved b/Cartfile.resolved index fe1db13..b7946a9 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,11 +1,11 @@ -github "RooyeKhat-Media/IGProtoBuffLibrary" "build47-5" github "KennethTsang/GrowingTextView" "0.2.4" github "MortimerGoro/MGSwipeTableCell" "1.5.6" -github "ReactiveX/RxSwift" "3.4.0" +github "ReactiveX/RxSwift" "3.4.1" github "RooyeKhat-Media/ALCameraViewController" "1.2.7" github "RooyeKhat-Media/DBAttachmentPickerController" "1.1.4-a" github "RooyeKhat-Media/Gifu" "v2.0.0-b" -github "RooyeKhat-Media/INSPhotoGallery" "1.1.0-a" +github "RooyeKhat-Media/IGProtoBuffLibrary" "build54" +github "RooyeKhat-Media/INSPhotoGallery" "1.1.0-d" github "RooyeKhat-Media/Protobuf-Swift" "3.0.13-d" github "RooyeKhat-Media/Starscream" "2.0.4-a" github "RxSwiftCommunity/RxRealm" "0.6.0" @@ -15,5 +15,5 @@ github "artemkrachulov/AKMaskField" "v2.0.3" github "ashleymills/Reachability.swift" "v3" github "facebook/pop" "1.0.9" github "jdg/MBProgressHUD" "1.0.0" -github "krzyzanowskim/CryptoSwift" "0.6.8" -github "realm/realm-cocoa" "v2.5.1" +github "krzyzanowskim/CryptoSwift" "0.6.9" +github "realm/realm-cocoa" "v2.7.0" diff --git a/Readme.md b/Readme.md index aaba6b1..70bbce2 100644 --- a/Readme.md +++ b/Readme.md @@ -20,8 +20,8 @@ iGap API manuals: https://github.com/RooyeKhat-Media/iGap-API Protocol buffers files : https://github.com/RooyeKhat-Media/iGap-API/tree/master/app/assets/proto -## Charge -Using the iGap infrastructure and utilizing it in personal and/or organizational projects are thoroughly free of charge. +## Charge +Using the iGap infrastructure and utilizing it in personal and/or organizational projects are thoroughly free of charge. ## Supports @@ -30,7 +30,7 @@ Using the iGap infrastructure and utilizing it in personal and/or organizational Issues: https://github.com/RooyeKhat-Media/iGap-iOS/issues ## Partner -**[RooyeKhat Media](https://rooyekhat.co/en)** was founded in 2015 aiming to create communicative and informative platforms supported by Internet and network on the basis of modern technology. We focus on the fields of designing, programming, supporting communicative and media software on mobile phones and tablets. +**[RooyeKhat Media](https://rooyekhat.co/en)** was founded in 2015 aiming to create communicative and informative platforms supported by Internet and network on the basis of modern technology. We focus on the fields of designing, programming, supporting communicative and media software on mobile phones and tablets. ## Licence iGap is released under the [GNU Affero General Public License](LICENSE) . This Free Software Foundation license is fairly new, and thus we wanted to talk about how this license differs from GPL. diff --git a/iGap.xcodeproj/project.pbxproj b/iGap.xcodeproj/project.pbxproj index 0889336..3bf999c 100644 --- a/iGap.xcodeproj/project.pbxproj +++ b/iGap.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 4F9386F81EAE335200397C3B /* IGChannelAndGroupSharedMediaImagesAndVideosCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F9386F71EAE335200397C3B /* IGChannelAndGroupSharedMediaImagesAndVideosCollectionViewController.swift */; }; + 4F9F3E6A1EBA0D91008E05C1 /* IGPushResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F9F3E691EBA0D91008E05C1 /* IGPushResponse.swift */; }; 931585151E6D567000F4C04B /* IGUserPrivacy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 931585141E6D567000F4C04B /* IGUserPrivacy.swift */; }; 93193F281E5811BA0039AC0C /* IGGroupInfoTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93193F271E5811BA0039AC0C /* IGGroupInfoTableViewController.swift */; }; 93193F2A1E5811FF0039AC0C /* IGGroupInfoEditNameTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93193F291E5811FF0039AC0C /* IGGroupInfoEditNameTableViewController.swift */; }; @@ -247,6 +248,7 @@ /* Begin PBXFileReference section */ 4F9386F71EAE335200397C3B /* IGChannelAndGroupSharedMediaImagesAndVideosCollectionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IGChannelAndGroupSharedMediaImagesAndVideosCollectionViewController.swift; sourceTree = ""; }; + 4F9F3E691EBA0D91008E05C1 /* IGPushResponse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IGPushResponse.swift; sourceTree = ""; }; 931585141E6D567000F4C04B /* IGUserPrivacy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IGUserPrivacy.swift; sourceTree = ""; }; 93193F271E5811BA0039AC0C /* IGGroupInfoTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IGGroupInfoTableViewController.swift; sourceTree = ""; }; 93193F291E5811FF0039AC0C /* IGGroupInfoEditNameTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IGGroupInfoEditNameTableViewController.swift; sourceTree = ""; }; @@ -848,6 +850,7 @@ FA63BAA81DD70E77000B60AD /* IGRequestInfo.swift */, FA63BAA21DD70D94000B60AD /* IGRequestSystem.swift */, FA63BAA61DD70E1A000B60AD /* IGRequestUser.swift */, + 4F9F3E691EBA0D91008E05C1 /* IGPushResponse.swift */, ); path = Requests; sourceTree = ""; @@ -1192,6 +1195,9 @@ DevelopmentTeam = MZ7XTDD264; ProvisioningStyle = Manual; SystemCapabilities = { + com.apple.Push = { + enabled = 0; + }; com.apple.iCloud = { enabled = 1; }; @@ -1424,6 +1430,7 @@ 93A3D3CA1E407E5200D2686F /* IGChooseMemberFromContactToCreateChannelViewController.swift in Sources */, FA63BAAF1DD70F21000B60AD /* IGRequestChannel.swift in Sources */, 93AA67BC1E4F35580053380C /* IGChannelInfoEditNameTableViewController.swift in Sources */, + 4F9F3E6A1EBA0D91008E05C1 /* IGPushResponse.swift in Sources */, FADE97B31DF2DBF100FF714A /* IGMusicPlayer.swift in Sources */, FA09536B1E1B97700043ED3F /* IGSettingPrivacyAndSecurityActiveSessionMoreDetailsTableViewController.swift in Sources */, 93193F281E5811BA0039AC0C /* IGGroupInfoTableViewController.swift in Sources */, diff --git a/iGap/Controller/Custom Master Controllers/NavigationController/IGNavigationController.swift b/iGap/Controller/Custom Master Controllers/NavigationController/IGNavigationController.swift index f256ab7..f284ba2 100644 --- a/iGap/Controller/Custom Master Controllers/NavigationController/IGNavigationController.swift +++ b/iGap/Controller/Custom Master Controllers/NavigationController/IGNavigationController.swift @@ -25,6 +25,8 @@ class IGNavigationController: UINavigationController ,UINavigationBarDelegate { return super.popToRootViewController(animated: animated) } + + func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldBeRequiredToFailBy otherGestureRecognizer: UIGestureRecognizer) -> Bool { return true } @@ -83,7 +85,8 @@ class IGNavigationController: UINavigationController ,UINavigationBarDelegate { } - func setCenterView(){ + + func setCenterView() { let titleView = UIView(frame: CGRect(x: 0, y: 0, width: 150, height: 45)) let nameLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 150, height: 21)) nameLabel.text = "John Smith" @@ -99,11 +102,12 @@ class IGNavigationController: UINavigationController ,UINavigationBarDelegate { self.navigationBar.topItem?.titleView = titleView } - func getHightOfNavigationBar()->(CGFloat){ + func getHightOfNavigationBar()->(CGFloat) { let navBarHeight = self.navigationBar.frame.size.height return navBarHeight } - func connectingTitleView(){ + + func connectingTitleView() { let connectingTitleView = UIView(frame: CGRect(x: 0, y: 0, width: 150, height: 30)) let activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView(frame: CGRect(x: 0, y: 0, width: 30, height: 30)) connectingTitleView.addSubview(activityIndicator) diff --git a/iGap/Controller/Custom Master Controllers/NavigationController/IGNavigationItem.swift b/iGap/Controller/Custom Master Controllers/NavigationController/IGNavigationItem.swift index ee7d174..e1d66e3 100644 --- a/iGap/Controller/Custom Master Controllers/NavigationController/IGNavigationItem.swift +++ b/iGap/Controller/Custom Master Controllers/NavigationController/IGNavigationItem.swift @@ -10,6 +10,8 @@ import UIKit import SnapKit +import MBProgressHUD + class IGNavigationItem: UINavigationItem { @@ -22,6 +24,8 @@ class IGNavigationItem: UINavigationItem { private var centerViewSubLabel: UILabel? private var typingIndicatorView: IGDotActivityIndicator? var isUpdatingUserStatusForAction : Bool = false + var isProccesing: Bool = true + var hud = MBProgressHUD() // var centerViewSubText: UITextField? private var tapOnRightView: (()->())? @@ -111,7 +115,12 @@ class IGNavigationItem: UINavigationItem { self.leftBarButtonItem = backBarButton self.title = "" backViewContainer?.addAction { + self.backViewContainer?.isUserInteractionEnabled = false + //self.hud = MBProgressHUD.showAdded(to: self.backViewContainer!, animated: true) + // self.hud.mode = .indeterminate _ = self.navigationController?.popViewController(animated: true) + // self.hud.hide(animated: true) + } } @@ -208,7 +217,6 @@ class IGNavigationItem: UINavigationItem { self.titleView = titleView } - //MARK: - Messages View func setNavigationBarForRoom(_ room: IGRoom) { setRoomAvatar(room) @@ -243,6 +251,7 @@ class IGNavigationItem: UINavigationItem { self.centerViewSubLabel!.text = room.currentActionString() } else { + typingIndicatorView?.removeFromSuperview() typingIndicatorView = nil self.centerViewSubLabel!.snp.makeConstraints { (make) in @@ -250,8 +259,11 @@ class IGNavigationItem: UINavigationItem { make.centerX.equalTo(self.centerViewContainer!.snp.centerX) } if let peer = room.chatRoom?.peer { + if room.currenctActionsByUsers.first?.value.1 != .typing { setLastSeenLabelForUser(peer, room: room) + } } else if let groupRoom = room.groupRoom { + self.centerViewSubLabel!.text = "\(groupRoom.participantCount) member\(groupRoom.participantCount>1 ? "s" : "")" } else if let channelRoom = room.channelRoom { self.centerViewSubLabel!.text = "\(channelRoom.participantCount) member\(channelRoom.participantCount>1 ? "s" : "")" @@ -271,6 +283,11 @@ class IGNavigationItem: UINavigationItem { let avatarView = IGAvatarView(frame: avatarViewFrame) avatarView.setRoom(room) rightViewContainer!.addSubview(avatarView) + + DispatchQueue.main.asyncAfter(deadline: .now() + 10.0) { + self.setRoomAvatar(room) + } + } private func setRoomInfo(_ room: IGRoom) { @@ -300,7 +317,9 @@ class IGNavigationItem: UINavigationItem { } if let peer = room.chatRoom?.peer { - setLastSeenLabelForUser(peer , room: room) + if room.currenctActionsByUsers.first?.value.1 != .typing { + setLastSeenLabelForUser(peer , room: room) + } } else if let groupRoom = room.groupRoom { self.centerViewSubLabel!.text = "\(groupRoom.participantCount) member\(groupRoom.participantCount>1 ? "s" : "")" } else if let channelRoom = room.channelRoom { @@ -310,6 +329,7 @@ class IGNavigationItem: UINavigationItem { } private func setLastSeenLabelForUser(_ user: IGRegisteredUser , room : IGRoom) { + if room.currenctActionsByUsers.first?.value.1 != .typing && typingIndicatorView == nil { switch user.lastSeenStatus { case .longTimeAgo: self.centerViewSubLabel!.text = "A long time ago" @@ -321,7 +341,9 @@ class IGNavigationItem: UINavigationItem { self.centerViewSubLabel!.text = "Last week" break case .online: + self.centerViewSubLabel!.text = "Online" + break case .exactly: self.centerViewSubLabel!.text = "\(user.lastSeen!.humanReadableForLastSeen())" @@ -336,9 +358,10 @@ class IGNavigationItem: UINavigationItem { self.centerViewSubLabel!.text = "Service Notification" break } - print(room.currentActionString()) - DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { - self.setLastSeenLabelForUser(user , room: room) + + DispatchQueue.main.asyncAfter(deadline: .now() + 10.0) { + self.setLastSeenLabelForUser(user , room: room) + } } } diff --git a/iGap/Controller/View Controllers/Channel and Group Info/IGChannelAndGroupInfoSharedMediaImagesAndVideosCollectionViewCell.swift b/iGap/Controller/View Controllers/Channel and Group Info/IGChannelAndGroupInfoSharedMediaImagesAndVideosCollectionViewCell.swift index 4466800..ffe4580 100644 --- a/iGap/Controller/View Controllers/Channel and Group Info/IGChannelAndGroupInfoSharedMediaImagesAndVideosCollectionViewCell.swift +++ b/iGap/Controller/View Controllers/Channel and Group Info/IGChannelAndGroupInfoSharedMediaImagesAndVideosCollectionViewCell.swift @@ -9,13 +9,18 @@ */ import UIKit +import RxRealm +import RxSwift +import RealmSwift +import Gifu class IGChannelAndGroupInfoSharedMediaImagesAndVideosCollectionViewCell: UICollectionViewCell { @IBOutlet weak var sharedMediaImageView: UIImageView! @IBOutlet weak var videoSizeLabel: UILabel! @IBOutlet weak var mediaDownloadIndicator: IGDownloadUploadIndicatorView! - + let disposeBag = DisposeBag() + var attachment: IGFile? override init(frame: CGRect) { super.init(frame: frame) @@ -23,8 +28,7 @@ class IGChannelAndGroupInfoSharedMediaImagesAndVideosCollectionViewCell: UIColle } override func awakeFromNib() { - self.mediaDownloadIndicator.shouldShowSize = true - self.mediaDownloadIndicator.isHidden = true + // self.mediaDownloadIndicator.shouldShowSize = true } @@ -36,23 +40,102 @@ class IGChannelAndGroupInfoSharedMediaImagesAndVideosCollectionViewCell: UIColle override func prepareForReuse() { sharedMediaImageView.image = nil videoSizeLabel.text = nil - //self.mediaDownloadIndicator.isHidden = true self.mediaDownloadIndicator.prepareForReuse() + self.mediaDownloadIndicator.isHidden = true + self.sharedMediaImageView.isHidden = true + //self.mediaDownloadIndicator.prepareForReuse() } func setMediaIndicator(message: IGRoomMessage) { - if message.attachment?.status != .ready { + if let msgAttachment = message.attachment { + if let messageAttachmentVariableInCache = IGAttachmentManager.sharedManager.getRxVariable(attachmentPrimaryKeyId: msgAttachment.primaryKeyId!) { + self.attachment = messageAttachmentVariableInCache.value + } else { + self.attachment = msgAttachment.detach() + let attachmentRef = ThreadSafeReference(to: msgAttachment) + IGAttachmentManager.sharedManager.add(attachmentRef: attachmentRef) + self.attachment = IGAttachmentManager.sharedManager.getRxVariable(attachmentPrimaryKeyId: msgAttachment.primaryKeyId!)?.value + } + + + if let variableInCache = IGAttachmentManager.sharedManager.getRxVariable(attachmentPrimaryKeyId: msgAttachment.primaryKeyId!) { + attachment = variableInCache.value + variableInCache.asObservable().subscribe({ (event) in + DispatchQueue.main.async { + self.updateAttachmentDownloadUploadIndicatorView() + } + }).addDisposableTo(disposeBag) + } else { + + } + + //MARK: ▶︎ Rx End + switch (message.type) { + case .image, .imageAndText, .video, .videoAndText: + //self.forwardedMessageAudioAndVoiceViewHeightConstraint.constant = 0 + self.sharedMediaImageView.isHidden = false self.mediaDownloadIndicator.isHidden = false - self.mediaDownloadIndicator.size = attachment?.sizeToString() - self.mediaDownloadIndicator.delegate = self - self.mediaDownloadIndicator.setFileType(.media) - self.mediaDownloadIndicator.setState((message.attachment?.status)!) - if attachment?.status == .downloading || message.attachment?.status == .uploading { - self.mediaDownloadIndicator.setPercentage((message.attachment?.downloadUploadPercent)!) + let progress = Progress(totalUnitCount: 100) + progress.completedUnitCount = 0 + + self.sharedMediaImageView.setThumbnail(for: msgAttachment) + // self.forwardedMessageMediaContainerViewHeightConstraint.constant = messageSizes.forwardedMessageAttachmentHeight //+ 20 + + if msgAttachment.status != .ready { + self.mediaDownloadIndicator.size = msgAttachment.sizeToString() + self.mediaDownloadIndicator.delegate = self + } + default: + break } - } } + + + func updateAttachmentDownloadUploadIndicatorView() { + if let attachment = self.attachment { + + if attachment.status == .ready { + self.mediaDownloadIndicator.setState(attachment.status) + setThumbnailForAttachments() + if attachment.type == .image { + self.sharedMediaImageView.setThumbnail(for: attachment) + } + return + } + + + switch attachment.type { + case .video, .image: + self.mediaDownloadIndicator.setFileType(.media) + self.mediaDownloadIndicator.setState(attachment.status) + if attachment.status == .downloading || attachment.status == .uploading { + self.mediaDownloadIndicator.setPercentage(attachment.downloadUploadPercent) + } + default: + break + } + } + + } + + func setThumbnailForAttachments() { + if let attachment = self.attachment { + self.sharedMediaImageView.isHidden = false + if attachment.type == .voice { + self.sharedMediaImageView.image = UIImage(named: "IG_Message_Cell_Voice") + } else { + switch attachment.fileTypeBasedOnNameExtension { + case .docx: + self.sharedMediaImageView.image = UIImage(named: "IG_Message_Cell_File_Doc") + default: + self.sharedMediaImageView.image = UIImage(named: "IG_Message_Cell_File_Generic") + } + } + } + } + + } extension IGChannelAndGroupInfoSharedMediaImagesAndVideosCollectionViewCell: IGDownloadUploadIndicatorViewDelegate { @@ -60,26 +143,15 @@ extension IGChannelAndGroupInfoSharedMediaImagesAndVideosCollectionViewCell: IGD if self.attachment?.status == .downloading { return } - if self.attachment?.status == .readyToDownload { - DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { - // self.mediaDownloadIndicator.prepareForReuse() - let progress = Progress(totalUnitCount: 100) - progress.completedUnitCount = 0 - self.mediaDownloadIndicator.setState((self.attachment?.status)!) - self.mediaDownloadIndicator.setPercentage((self.attachment?.downloadUploadPercent)!) - } - - } if let attachment = self.attachment { IGDownloadManager.sharedManager.download(file: attachment, previewType: .originalFile, completion: { - self.mediaDownloadIndicator.prepareForReuse() - self.mediaDownloadIndicator.setState((attachment.status)) - + }, failure: { }) } + } func downloadUploadIndicatorDidTapOnCancel(_ indicator: IGDownloadUploadIndicatorView) { diff --git a/iGap/Controller/View Controllers/Channel and Group Info/IGChannelAndGroupSharedMediaImagesAndVideosCollectionViewController.swift b/iGap/Controller/View Controllers/Channel and Group Info/IGChannelAndGroupSharedMediaImagesAndVideosCollectionViewController.swift index e472543..a4fbffd 100644 --- a/iGap/Controller/View Controllers/Channel and Group Info/IGChannelAndGroupSharedMediaImagesAndVideosCollectionViewController.swift +++ b/iGap/Controller/View Controllers/Channel and Group Info/IGChannelAndGroupSharedMediaImagesAndVideosCollectionViewController.swift @@ -74,6 +74,8 @@ class IGChannelAndGroupSharedMediaImagesAndVideosCollectionViewController: UICol super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } + override func viewWillAppear(_ animated: Bool) { + } /* // MARK: - Navigation @@ -108,7 +110,7 @@ class IGChannelAndGroupSharedMediaImagesAndVideosCollectionViewController: UICol cell.sharedMediaImageView.setThumbnail(for: sharedAttachment) cell.videoSizeLabel.isHidden = true sharedMediaFilter = .image - cell.attachment = sharedAttachment + //cell.attachment = sharedAttachment cell.setMediaIndicator(message: sharedImage) @@ -116,6 +118,7 @@ class IGChannelAndGroupSharedMediaImagesAndVideosCollectionViewController: UICol } } } + if sharedMedia[indexPath.row].type == .video || sharedMedia[indexPath.row].type == .videoAndText { if let sharedImage: IGRoomMessage = sharedMedia[indexPath.row] { if let sharedAttachment = sharedImage.attachment { @@ -140,7 +143,7 @@ class IGChannelAndGroupSharedMediaImagesAndVideosCollectionViewController: UICol cell.videoSizeLabel.isHidden = false sharedMediaFilter = .video cell.setMediaIndicator(message: sharedImage) - cell.attachment = sharedAttachment + // cell.attachment = sharedAttachment } } @@ -222,38 +225,7 @@ class IGChannelAndGroupSharedMediaImagesAndVideosCollectionViewController: UICol } - - // MARK: UICollectionViewDelegate - - /* - // Uncomment this method to specify if the specified item should be highlighted during tracking - override func collectionView(_ collectionView: UICollectionView, shouldHighlightItemAt indexPath: IndexPath) -> Bool { - return true - } - */ - - /* - // Uncomment this method to specify if the specified item should be selected - override func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool { - return true - } - */ - - /* - // Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item - override func collectionView(_ collectionView: UICollectionView, shouldShowMenuForItemAt indexPath: IndexPath) -> Bool { - return false - } - - override func collectionView(_ collectionView: UICollectionView, canPerformAction action: Selector, forItemAt indexPath: IndexPath, withSender sender: Any?) -> Bool { - return false - } - - override func collectionView(_ collectionView: UICollectionView, performAction action: Selector, forItemAt indexPath: IndexPath, withSender sender: Any?) { - - } - */ - + } extension IGChannelAndGroupSharedMediaImagesAndVideosCollectionViewController : UICollectionViewDelegateFlowLayout { diff --git a/iGap/Controller/View Controllers/Channel and Group Info/IGChannelInfoAdminsAndModeratorsTableViewController.swift b/iGap/Controller/View Controllers/Channel and Group Info/IGChannelInfoAdminsAndModeratorsTableViewController.swift index b3a55d8..b301452 100644 --- a/iGap/Controller/View Controllers/Channel and Group Info/IGChannelInfoAdminsAndModeratorsTableViewController.swift +++ b/iGap/Controller/View Controllers/Channel and Group Info/IGChannelInfoAdminsAndModeratorsTableViewController.swift @@ -47,6 +47,8 @@ class IGChannelInfoAdminsAndModeratorsTableViewController: UITableViewController adminMember.removeAll() moderatorMember.removeAll() fetchAdminChannelMemberFromServer() + self.tableView.isUserInteractionEnabled = true + } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() @@ -71,6 +73,7 @@ class IGChannelInfoAdminsAndModeratorsTableViewController: UITableViewController if indexPath.row == 1 { index = 1 } + self.tableView.isUserInteractionEnabled = false self.performSegue(withIdentifier: "showAdminsOrModeratorDetailTableview", sender: self) } diff --git a/iGap/Controller/View Controllers/Channel and Group Info/IGChannelInfoEditDescriptionTableViewController.swift b/iGap/Controller/View Controllers/Channel and Group Info/IGChannelInfoEditDescriptionTableViewController.swift index 45102cc..97fb248 100644 --- a/iGap/Controller/View Controllers/Channel and Group Info/IGChannelInfoEditDescriptionTableViewController.swift +++ b/iGap/Controller/View Controllers/Channel and Group Info/IGChannelInfoEditDescriptionTableViewController.swift @@ -24,6 +24,7 @@ class IGChannelInfoEditDescriptionTableViewController: UITableViewController , U super.viewDidLoad() channelDescriptionTextView.text = room?.channelRoom?.roomDescription let navigationItem = self.navigationItem as! IGNavigationItem + navigationItem.navigationController = self.navigationController as! IGNavigationController let navigationController = self.navigationController as! IGNavigationController navigationController.interactivePopGestureRecognizer?.delegate = self channelDescriptionTextView.delegate = self @@ -31,10 +32,10 @@ class IGChannelInfoEditDescriptionTableViewController: UITableViewController , U if myRole == .owner || myRole == .admin { channelDescriptionTextView.isUserInteractionEnabled = true navigationItem.addNavigationViewItems(rightItemText: "Done", title: "Description") - navigationItem.navigationController = self.navigationController as! IGNavigationController navigationItem.rightViewContainer?.addAction { self.changeChannelDescription() } + placeholderLabel = UILabel() placeholderLabel.text = "Enter some text to describe channel..." placeholderLabel.font = UIFont.italicSystemFont(ofSize: (channelDescriptionTextView.font?.pointSize)!) diff --git a/iGap/Controller/View Controllers/Channel and Group Info/IGChannelInfoTableViewController.swift b/iGap/Controller/View Controllers/Channel and Group Info/IGChannelInfoTableViewController.swift index 56b56e5..4913ba8 100644 --- a/iGap/Controller/View Controllers/Channel and Group Info/IGChannelInfoTableViewController.swift +++ b/iGap/Controller/View Controllers/Channel and Group Info/IGChannelInfoTableViewController.swift @@ -45,20 +45,25 @@ class IGChannelInfoTableViewController: UITableViewController , UIGestureRecogni @IBOutlet weak var adminAndModeratorCell: UITableViewCell! var selectedChannel : IGChannelRoom? + private let disposeBag = DisposeBag() var room : IGRoom? var hud = MBProgressHUD() var allMember = [IGChannelMember]() var myRole : IGChannelMember.IGRole! var signMessageIndexPath : IndexPath? + var channelLinkIndexPath : IndexPath? var imagePicker = UIImagePickerController() // var rooms : Results! var notificationToken: NotificationToken? + var connectionStatus: IGAppManager.ConnectionStatus? override func viewDidLoad() { super.viewDidLoad() requestToGetRoom() imagePicker.delegate = self + tableView.estimatedRowHeight = 44.0 + tableView.rowHeight = UITableViewAutomaticDimension signMessageIndexPath = IndexPath(row: 2, section: 1) myRole = room?.channelRoom?.role switch myRole! { @@ -113,6 +118,20 @@ class IGChannelInfoTableViewController: UITableViewController , UIGestureRecogni self.notificationToken = room?.addNotificationBlock({ (objectChange) in self.showChannelInfo() }) + + IGAppManager.sharedManager.connectionStatus.asObservable().subscribe(onNext: { (connectionStatus) in + DispatchQueue.main.async { + self.updateConnectionStatus(connectionStatus) + + } + }, onError: { (error) in + + }, onCompleted: { + + }, onDisposed: { + + }).addDisposableTo(disposeBag) + // { (changes: RealmCollectionChange) in @@ -139,6 +158,7 @@ class IGChannelInfoTableViewController: UITableViewController , UIGestureRecogni override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) // showChannelInfo() + self.tableView.isUserInteractionEnabled = true } override func didReceiveMemoryWarning() { @@ -154,6 +174,20 @@ class IGChannelInfoTableViewController: UITableViewController , UIGestureRecogni requestToUpdateChannelSignature(signMessageSwitchStatus!) } + + func updateConnectionStatus(_ status: IGAppManager.ConnectionStatus) { + + switch status { + case .connected: + connectionStatus = .connected + case .connecting: + connectionStatus = .connecting + case .waitingForNetwork: + connectionStatus = .waitingForNetwork + } + + } + @IBAction func didTapOnCameraBtn(_ sender: UIButton) { let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) let cameraOption = UIAlertAction(title: "Take a Photo", style: .default, handler: { @@ -233,18 +267,21 @@ class IGChannelInfoTableViewController: UITableViewController , UIGestureRecogni override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { print(indexPath.section) + if indexPath.section == 0 { switch indexPath.row { case 0: if myRole == .owner || myRole == .admin { + self.tableView.isUserInteractionEnabled = false self.performSegue(withIdentifier: "showChannelInfoSetName", sender: self) } case 1: - + self.tableView.isUserInteractionEnabled = false self.performSegue(withIdentifier: "showChannelInfoSetDescription", sender: self) case 2: if myRole == .owner { + self.tableView.isUserInteractionEnabled = false self.performSegue(withIdentifier: "showChannelInfoSetType", sender: self) } case 3: @@ -256,8 +293,10 @@ class IGChannelInfoTableViewController: UITableViewController , UIGestureRecogni if indexPath.section == 1 { switch indexPath.row { case 0: + self.tableView.isUserInteractionEnabled = false self.performSegue(withIdentifier: "showChannelInfoSetMembers", sender: self) case 1: + self.tableView.isUserInteractionEnabled = false self.performSegue(withIdentifier: "showAdminAndModarators", sender: self) default: break @@ -266,6 +305,7 @@ class IGChannelInfoTableViewController: UITableViewController , UIGestureRecogni if indexPath.section == 2 { switch indexPath.row { case 0: + self.tableView.isUserInteractionEnabled = false self.performSegue(withIdentifier: "showSharedMadiaPage", sender: self) default: break @@ -281,10 +321,11 @@ class IGChannelInfoTableViewController: UITableViewController , UIGestureRecogni override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { - if indexPath.section == 1 && indexPath.row == 1 && adminAndModeratorCell.isHidden == true { + + if indexPath.section == 1 && indexPath.row == 2 && adminAndModeratorCell.isHidden == true { return 0.0 } - if indexPath.section == 1 && indexPath.row == 0 && allMemberCell.isHidden == true { + if indexPath.section == 1 && indexPath.row == 1 && allMemberCell.isHidden == true { return 0.0 } if indexPath.section == 0 && indexPath.row == 3 && channelLinkCell.isHidden == true { @@ -296,13 +337,14 @@ class IGChannelInfoTableViewController: UITableViewController , UIGestureRecogni if indexPath.section == 2 && indexPath.row == 1 && notificationCell.isHidden == true { return 0.0 } - if indexPath.section == 2 && indexPath.row == 2 && channelSignMessageCell.isHidden == true { + if indexPath.section == 1 && indexPath.row == 0 && channelSignMessageCell.isHidden == true { return 0.0 } return 44.0 } + func showDeleteChannelActionSheet() { var title : String! @@ -318,9 +360,23 @@ class IGChannelInfoTableViewController: UITableViewController , UIGestureRecogni let deleteAction = UIAlertAction(title: actionTitle , style:.default , handler: { (alert: UIAlertAction) -> Void in if self.myRole == .owner { + if self.connectionStatus == .connecting || self.connectionStatus == .waitingForNetwork { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + } else { self.deleteChannelRequest() + } } else { + if self.connectionStatus == .connecting || self.connectionStatus == .waitingForNetwork { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + } else { self.leftChannelRequest(room: self.room!) + } } }) diff --git a/iGap/Controller/View Controllers/Channel and Group Info/IGGroupInfoAdminsAndModeratorsListTableViewController.swift b/iGap/Controller/View Controllers/Channel and Group Info/IGGroupInfoAdminsAndModeratorsListTableViewController.swift index 2a33eec..b4a387a 100644 --- a/iGap/Controller/View Controllers/Channel and Group Info/IGGroupInfoAdminsAndModeratorsListTableViewController.swift +++ b/iGap/Controller/View Controllers/Channel and Group Info/IGGroupInfoAdminsAndModeratorsListTableViewController.swift @@ -46,6 +46,9 @@ class IGGroupInfoAdminsAndModeratorsListTableViewController: UITableViewControll } + override func viewWillAppear(_ animated: Bool) { + self.tableView.isUserInteractionEnabled = true + } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() @@ -64,6 +67,7 @@ class IGGroupInfoAdminsAndModeratorsListTableViewController: UITableViewControll return 2 } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + self.tableView.isUserInteractionEnabled = false if indexPath.row == 0 { index = 0 } diff --git a/iGap/Controller/View Controllers/Channel and Group Info/IGGroupInfoMemberListTableViewCell.swift b/iGap/Controller/View Controllers/Channel and Group Info/IGGroupInfoMemberListTableViewCell.swift index ada7295..ed97e2a 100644 --- a/iGap/Controller/View Controllers/Channel and Group Info/IGGroupInfoMemberListTableViewCell.swift +++ b/iGap/Controller/View Controllers/Channel and Group Info/IGGroupInfoMemberListTableViewCell.swift @@ -73,7 +73,7 @@ class IGGroupInfoMemberListTableViewCell: UITableViewCell { groupMemberRecentlyStatus.text = "Service Notification" break } - DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { + DispatchQueue.main.asyncAfter(deadline: .now() + 60.0) { self.setUser(member) } diff --git a/iGap/Controller/View Controllers/Channel and Group Info/IGGroupInfoTableViewController.swift b/iGap/Controller/View Controllers/Channel and Group Info/IGGroupInfoTableViewController.swift index 6d488ca..f33e5a8 100644 --- a/iGap/Controller/View Controllers/Channel and Group Info/IGGroupInfoTableViewController.swift +++ b/iGap/Controller/View Controllers/Channel and Group Info/IGGroupInfoTableViewController.swift @@ -44,6 +44,7 @@ class IGGroupInfoTableViewController: UITableViewController , UIGestureRecognize @IBOutlet weak var leaveGroupLabel: UILabel! var room : IGRoom? + private let disposeBag = DisposeBag() var hud = MBProgressHUD() var myRole : IGGroupMember.IGRole! var signMessageIndexPath : IndexPath? @@ -52,10 +53,9 @@ class IGGroupInfoTableViewController: UITableViewController , UIGestureRecognize var groupRoom : Results! var mode : String? = "Members" var notificationToken: NotificationToken? - + var connectionStatus: IGAppManager.ConnectionStatus? override func viewDidLoad() { super.viewDidLoad() - requestToGetRoom() myRole = room?.groupRoom?.role showGroupInfo() @@ -132,8 +132,29 @@ class IGGroupInfoTableViewController: UITableViewController , UIGestureRecognize break } } + + IGAppManager.sharedManager.connectionStatus.asObservable().subscribe(onNext: { (connectionStatus) in + DispatchQueue.main.async { + self.updateConnectionStatus(connectionStatus) + + } + }, onError: { (error) in + + }, onCompleted: { + + }, onDisposed: { + + }).addDisposableTo(disposeBag) + } + + override func viewDidAppear(_ animated: Bool) { + self.tableView.isUserInteractionEnabled = true + } + override func viewWillAppear(_ animated: Bool) { + self.tableView.isUserInteractionEnabled = true + } @IBAction func didTapOnCameraBtn(_ sender: UIButton) { } @@ -226,14 +247,17 @@ class IGGroupInfoTableViewController: UITableViewController , UIGestureRecognize switch indexPath.row { case 0: if myRole == .owner || myRole == .admin { + self.tableView.isUserInteractionEnabled = false self.performSegue(withIdentifier: "showGroupNameSetting", sender: self) } break case 1: + self.tableView.isUserInteractionEnabled = false self.performSegue(withIdentifier: "showDescribeGroupSetting", sender: self) break case 2: if myRole == .owner { + self.tableView.isUserInteractionEnabled = false self.performSegue(withIdentifier: "showGroupTypeSetting", sender: self) } case 3: @@ -246,8 +270,10 @@ class IGGroupInfoTableViewController: UITableViewController , UIGestureRecognize if indexPath.section == 1 { switch indexPath.row { case 0: + self.tableView.isUserInteractionEnabled = false self.performSegue(withIdentifier: "showGroupMemberSetting", sender: self) case 1: + self.tableView.isUserInteractionEnabled = false self.performSegue(withIdentifier: "showGroupAdminsAnadModeratorsSetting", sender: self) default: break @@ -296,6 +322,19 @@ class IGGroupInfoTableViewController: UITableViewController , UIGestureRecognize return 44.0 } + + func updateConnectionStatus(_ status: IGAppManager.ConnectionStatus) { + + switch status { + case .connected: + connectionStatus = .connected + case .connecting: + connectionStatus = .connecting + case .waitingForNetwork: + connectionStatus = .waitingForNetwork + } + + } func showGroupInfo() { groupNameTitleLabel.text = room?.title @@ -319,7 +358,6 @@ class IGGroupInfoTableViewController: UITableViewController , UIGestureRecognize var groupLink: String? = "" if room?.groupRoom?.type == .privateRoom { groupLink = room?.groupRoom?.privateExtra?.inviteLink - print(room?.groupRoom?.privateExtra?.inviteToken) } if room?.groupRoom?.type == .publicRoom { if let groupUsername = room?.groupRoom?.publicExtra?.username { @@ -343,12 +381,26 @@ class IGGroupInfoTableViewController: UITableViewController , UIGestureRecognize let deleteAction = UIAlertAction(title: actionTitle , style:.default , handler: { (alert: UIAlertAction) -> Void in if self.myRole == .owner { + if self.connectionStatus == .connecting || self.connectionStatus == .waitingForNetwork { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + } else { + self.deleteGroupRequest() + } }else{ - self.leftGroupRequest(room: self.room!) + if self.connectionStatus == .connecting || self.connectionStatus == .waitingForNetwork { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + }else { + self.leftGroupRequest(room: self.room!) + } } - }) let cancelAction = UIAlertAction(title: "Cancel", style:.cancel , handler: { (alert: UIAlertAction) -> Void in diff --git a/iGap/Controller/View Controllers/Channel and Group Info/IGGroupSharedMediaListTableViewController.swift b/iGap/Controller/View Controllers/Channel and Group Info/IGGroupSharedMediaListTableViewController.swift index 9dee5ea..293c73b 100644 --- a/iGap/Controller/View Controllers/Channel and Group Info/IGGroupSharedMediaListTableViewController.swift +++ b/iGap/Controller/View Controllers/Channel and Group Info/IGGroupSharedMediaListTableViewController.swift @@ -23,12 +23,12 @@ class IGGroupSharedMediaListTableViewController: UITableViewController , UIGestu @IBOutlet weak var sizeOfSharedLinksLabel: UILabel! @IBOutlet weak var sizeOfSharedVoice: UILabel! - @IBOutlet weak var imageIndicator: UIActivityIndicatorView! - @IBOutlet weak var voicesIndicator: UIActivityIndicatorView! - @IBOutlet weak var linkIndicator: UIActivityIndicatorView! - @IBOutlet weak var fileIndicator: UIActivityIndicatorView! - @IBOutlet weak var audioIndicator: UIActivityIndicatorView! - @IBOutlet weak var videoIndicator: UIActivityIndicatorView! +// @IBOutlet weak var imageIndicator: UIActivityIndicatorView! +// @IBOutlet weak var voicesIndicator: UIActivityIndicatorView! +// @IBOutlet weak var linkIndicator: UIActivityIndicatorView! +// @IBOutlet weak var fileIndicator: UIActivityIndicatorView! +// @IBOutlet weak var audioIndicator: UIActivityIndicatorView! +// @IBOutlet weak var videoIndicator: UIActivityIndicatorView! var selectedRowNum : Int! @@ -53,11 +53,14 @@ class IGGroupSharedMediaListTableViewController: UITableViewController , UIGestu getCountOfFile() getCountOfVoices() getCountOfLinks() + getCountOfSahredMediaFiles() + + } override func viewWillAppear(_ animated: Bool) { + self.tableView.isUserInteractionEnabled = true - } override func didReceiveMemoryWarning() { @@ -83,31 +86,38 @@ class IGGroupSharedMediaListTableViewController: UITableViewController , UIGestu switch indexPath.row { case 0: if sharedMediaImageFile.count != 0 { + self.tableView.isUserInteractionEnabled = false + self.performSegue(withIdentifier: "showImagesAndVideoSharedMediaCollection", sender: self) } break case 1: if sharedMediaAudioFile.count != 0 { + self.tableView.isUserInteractionEnabled = false self.performSegue(withIdentifier: "showLinksAndAudioSharedMediaTableview", sender: self) } break case 2: if sharedMediaVideoFile.count != 0 { + self.tableView.isUserInteractionEnabled = false self.performSegue(withIdentifier: "showImagesAndVideoSharedMediaCollection", sender: self) } break case 3: if sharedMediaFile.count != 0 { + self.tableView.isUserInteractionEnabled = false self.performSegue(withIdentifier: "showLinksAndAudioSharedMediaTableview", sender: self) } break case 4: if sharedMediaVoiceFile.count != 0 { + self.tableView.isUserInteractionEnabled = false self.performSegue(withIdentifier: "showLinksAndAudioSharedMediaTableview", sender: self) } break case 5: if sharedMediaLinkFile.count != 0 { + self.tableView.isUserInteractionEnabled = false self.performSegue(withIdentifier: "showLinksAndAudioSharedMediaTableview", sender: self) } @@ -118,10 +128,59 @@ class IGGroupSharedMediaListTableViewController: UITableViewController , UIGestu } } + func getCountOfSahredMediaFiles() { + if let selectedRoom = room { + self.hud = MBProgressHUD.showAdded(to: self.view, animated: true) + self.hud.mode = .indeterminate + IGClientCountRoomHistoryRequest.Generator.generate(roomID: selectedRoom.id).success({ (protoResponse) in + DispatchQueue.main.async { + switch protoResponse { + case let clientCountRoomHistory as IGPClientCountRoomHistoryResponse: + let response = IGClientCountRoomHistoryRequest.Handler.interpret(response: clientCountRoomHistory) + let media = response.media + let audio = response.audio + let video = response.video + let url = response.url + let file = response.file + let gif = response.gif + let image = response.image + let voice = response.voice + self.sizeOfSharedVideos.text = "\(video)" + self.sizeOfSharedFiles.text = "\(file)" + self.sizeOfSharedImage.text = "\(image)" + self.sizeOfSharedVoice.text = "\(voice)" + self.sizeOfSharedAudiosLabel.text = "\(audio)" + self.sizeOfSharedLinksLabel.text = "\(url)" + self.hud.hide(animated: true) + + default: + break + } + } + }).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) + self.hud.hide(animated: true) + + } + default: + break + } + + }).send() + + + } + } + func getCountOfImages() { if let selectedRoom = room { - self.imageIndicator.startAnimating() IGClientSearchRoomHistoryRequest.Generator.generate(roomId: selectedRoom.id, offset: 0, filter: .image).success({ (protoResponse) in DispatchQueue.main.async { switch protoResponse { @@ -133,10 +192,6 @@ class IGGroupSharedMediaListTableViewController: UITableViewController , UIGestu self.sharedMediaImageFile.append(msg) } } - let countOfImage = response.NotDeletedCount - self.sizeOfSharedImage.text = "\(countOfImage)" - self.imageIndicator.stopAnimating() - self.imageIndicator.hidesWhenStopped = true default: break } @@ -148,16 +203,12 @@ class IGGroupSharedMediaListTableViewController: UITableViewController , UIGestu 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.imageIndicator.stopAnimating() - self.imageIndicator.hidesWhenStopped = true self.present(alert, animated: true, completion: nil) } case .clientSearchRoomHistoryNotFound: DispatchQueue.main.async { self.sizeOfSharedImage.text = "\(0)" - self.imageIndicator.stopAnimating() - self.imageIndicator.hidesWhenStopped = true } default: break @@ -170,7 +221,6 @@ class IGGroupSharedMediaListTableViewController: UITableViewController , UIGestu func getCountOfAudio() { if let selectedRoom = room { - self.audioIndicator.startAnimating() IGClientSearchRoomHistoryRequest.Generator.generate(roomId: selectedRoom.id, offset: 0, filter: .audio).success({ (protoResponse) in DispatchQueue.main.async { switch protoResponse { @@ -182,10 +232,7 @@ class IGGroupSharedMediaListTableViewController: UITableViewController , UIGestu self.sharedMediaAudioFile.append(msg) } } - let countOfImage = response.NotDeletedCount - self.sizeOfSharedAudiosLabel.text = "\(countOfImage)" - self.audioIndicator.stopAnimating() - self.audioIndicator.hidesWhenStopped = true + default: break } @@ -197,16 +244,12 @@ class IGGroupSharedMediaListTableViewController: UITableViewController , UIGestu 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.audioIndicator.stopAnimating() - self.audioIndicator.hidesWhenStopped = true self.present(alert, animated: true, completion: nil) } case .clientSearchRoomHistoryNotFound: DispatchQueue.main.async { self.sizeOfSharedAudiosLabel.text = "\(0)" - self.audioIndicator.stopAnimating() - self.audioIndicator.hidesWhenStopped = true } default: @@ -220,7 +263,6 @@ class IGGroupSharedMediaListTableViewController: UITableViewController , UIGestu func getCountOfVideos() { if let selectedRoom = room { - self.videoIndicator.startAnimating() IGClientSearchRoomHistoryRequest.Generator.generate(roomId: selectedRoom.id, offset: 0, filter: .video).success({ (protoResponse) in DispatchQueue.main.async { switch protoResponse { @@ -232,10 +274,6 @@ class IGGroupSharedMediaListTableViewController: UITableViewController , UIGestu self.sharedMediaVideoFile.append(msg) } } - let countOfImage = response.NotDeletedCount - self.sizeOfSharedVideos.text = "\(countOfImage)" - self.videoIndicator.stopAnimating() - self.videoIndicator.hidesWhenStopped = true default: break } @@ -247,15 +285,11 @@ class IGGroupSharedMediaListTableViewController: UITableViewController , UIGestu 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.videoIndicator.stopAnimating() - self.videoIndicator.hidesWhenStopped = true self.present(alert, animated: true, completion: nil) } case .clientSearchRoomHistoryNotFound: DispatchQueue.main.async { self.sizeOfSharedVideos.text = "\(0)" - self.videoIndicator.stopAnimating() - self.videoIndicator.hidesWhenStopped = true } @@ -272,7 +306,6 @@ class IGGroupSharedMediaListTableViewController: UITableViewController , UIGestu func getCountOfFile() { if let selectedRoom = room { - self.fileIndicator.startAnimating() IGClientSearchRoomHistoryRequest.Generator.generate(roomId: selectedRoom.id, offset: 0, filter: .file).success({ (protoResponse) in DispatchQueue.main.async { switch protoResponse { @@ -286,8 +319,6 @@ class IGGroupSharedMediaListTableViewController: UITableViewController , UIGestu } let countOfImage = response.NotDeletedCount self.sizeOfSharedFiles.text = "\(countOfImage)" - self.fileIndicator.stopAnimating() - self.fileIndicator.hidesWhenStopped = true default: break } @@ -299,15 +330,11 @@ class IGGroupSharedMediaListTableViewController: UITableViewController , UIGestu 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.fileIndicator.stopAnimating() - self.fileIndicator.hidesWhenStopped = true self.present(alert, animated: true, completion: nil) } case .clientSearchRoomHistoryNotFound: DispatchQueue.main.async { self.sizeOfSharedFiles.text = "\(0)" - self.fileIndicator.stopAnimating() - self.fileIndicator.hidesWhenStopped = true } default: @@ -322,7 +349,6 @@ class IGGroupSharedMediaListTableViewController: UITableViewController , UIGestu func getCountOfVoices() { if let selectedRoom = room { - self.voicesIndicator.startAnimating() IGClientSearchRoomHistoryRequest.Generator.generate(roomId: selectedRoom.id, offset: 0, filter: .voice).success({ (protoResponse) in DispatchQueue.main.async { switch protoResponse { @@ -336,8 +362,6 @@ class IGGroupSharedMediaListTableViewController: UITableViewController , UIGestu } let countOfImage = response.NotDeletedCount self.sizeOfSharedVoice.text = "\(countOfImage)" - self.voicesIndicator.stopAnimating() - self.voicesIndicator.hidesWhenStopped = true default: break } @@ -349,15 +373,11 @@ class IGGroupSharedMediaListTableViewController: UITableViewController , UIGestu 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.voicesIndicator.stopAnimating() - self.voicesIndicator.hidesWhenStopped = true self.present(alert, animated: true, completion: nil) } case .clientSearchRoomHistoryNotFound: DispatchQueue.main.async { self.sizeOfSharedLinksLabel.text = "\(0)" - self.voicesIndicator.stopAnimating() - self.voicesIndicator.hidesWhenStopped = true } default: @@ -371,7 +391,6 @@ class IGGroupSharedMediaListTableViewController: UITableViewController , UIGestu } func getCountOfLinks() { if let selectedRoom = room { - self.linkIndicator.startAnimating() IGClientSearchRoomHistoryRequest.Generator.generate(roomId: selectedRoom.id, offset: 0, filter: .url).success({ (protoResponse) in DispatchQueue.main.async { switch protoResponse { @@ -385,8 +404,6 @@ class IGGroupSharedMediaListTableViewController: UITableViewController , UIGestu } let countOfImage = response.NotDeletedCount self.sizeOfSharedLinksLabel.text = "\(countOfImage)" - self.linkIndicator.stopAnimating() - self.linkIndicator.hidesWhenStopped = true default: break } @@ -398,15 +415,11 @@ class IGGroupSharedMediaListTableViewController: UITableViewController , UIGestu 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.voicesIndicator.stopAnimating() - self.voicesIndicator.hidesWhenStopped = true self.present(alert, animated: true, completion: nil) } case .clientSearchRoomHistoryNotFound: DispatchQueue.main.async { self.sizeOfSharedLinksLabel.text = "\(0)" - self.voicesIndicator.stopAnimating() - self.voicesIndicator.hidesWhenStopped = true } default: @@ -432,7 +445,6 @@ class IGGroupSharedMediaListTableViewController: UITableViewController , UIGestu switch selectedRowNum { case 0: destination.navigationTitle = "Images" - print(sharedMediaImageFile.count) destination.sharedMedia = sharedMediaImageFile case 2: destination.navigationTitle = "Videos" diff --git a/iGap/Controller/View Controllers/Chat and User Info/IGRegistredUserInfoTableViewController.swift b/iGap/Controller/View Controllers/Chat and User Info/IGRegistredUserInfoTableViewController.swift index b3a6d2b..ba3a61f 100644 --- a/iGap/Controller/View Controllers/Chat and User Info/IGRegistredUserInfoTableViewController.swift +++ b/iGap/Controller/View Controllers/Chat and User Info/IGRegistredUserInfoTableViewController.swift @@ -56,6 +56,11 @@ class IGRegistredUserInfoTableViewController: UITableViewController , UIGestureR let navigationController = self.navigationController as! IGNavigationController navigationController.interactivePopGestureRecognizer?.delegate = self } + + override func viewWillAppear(_ animated: Bool) { + self.tableView.isUserInteractionEnabled = true + + } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() @@ -116,6 +121,7 @@ class IGRegistredUserInfoTableViewController: UITableViewController , UIGestureR } } case 2: + self.tableView.isUserInteractionEnabled = false self.performSegue(withIdentifier: "showCreateGroupPage", sender: self) default: diff --git a/iGap/Controller/View Controllers/Setting/IGDeleteAccountTableViewController.swift b/iGap/Controller/View Controllers/Setting/IGDeleteAccountTableViewController.swift index c0006e2..a970e15 100644 --- a/iGap/Controller/View Controllers/Setting/IGDeleteAccountTableViewController.swift +++ b/iGap/Controller/View Controllers/Setting/IGDeleteAccountTableViewController.swift @@ -30,6 +30,8 @@ class IGDeleteAccountTableViewController: UITableViewController , UIGestureRecog } override func viewDidAppear(_ animated: Bool) { hud.hide(animated: true) + self.tableView.isUserInteractionEnabled = true + } @@ -40,6 +42,7 @@ class IGDeleteAccountTableViewController: UITableViewController , UIGestureRecog return 1 } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + self.tableView.isUserInteractionEnabled = false getDeleteToken() } override func didReceiveMemoryWarning() { diff --git a/iGap/Controller/View Controllers/Setting/IGSettingChatCatchTableViewController.swift b/iGap/Controller/View Controllers/Setting/IGSettingChatCatchTableViewController.swift index 9fe690c..e162002 100644 --- a/iGap/Controller/View Controllers/Setting/IGSettingChatCatchTableViewController.swift +++ b/iGap/Controller/View Controllers/Setting/IGSettingChatCatchTableViewController.swift @@ -24,9 +24,19 @@ class IGSettingChatCatchTableViewController: UITableViewController { let backgroundImageView = UIImageView(image: backImage) self.tableView.backgroundView = backgroundImageView } + + override func viewDidAppear(_ animated: Bool) { + self.tableView.isUserInteractionEnabled = true + } + override func viewWillAppear(_ animated: Bool) { + self.tableView.isUserInteractionEnabled = true + + } + override func numberOfSections(in tableView: UITableView) -> Int { return 3 } + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { var numberOfRow : Int = 0 switch section { @@ -63,9 +73,11 @@ class IGSettingChatCatchTableViewController: UITableViewController { } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { if indexPath.section == 0 && indexPath.row == 0 { + self.tableView.isUserInteractionEnabled = false performSegue(withIdentifier: "GoToKeepMediaAfterTimePage", sender: self) } if indexPath.section == 1 && indexPath.row == 0 || indexPath.section == 2{ + self.tableView.isUserInteractionEnabled = false performSegue(withIdentifier: "GoToCachedDataItemsPage", sender: self) if indexPath.section == 2{ let currentCell = tableView.cellForRow(at: indexPath) as?IGSettingChatCatchContactAndGroupsTableViewCell diff --git a/iGap/Controller/View Controllers/Setting/IGSettingChatTableViewController.swift b/iGap/Controller/View Controllers/Setting/IGSettingChatTableViewController.swift index c7c20fd..6f74c0b 100644 --- a/iGap/Controller/View Controllers/Setting/IGSettingChatTableViewController.swift +++ b/iGap/Controller/View Controllers/Setting/IGSettingChatTableViewController.swift @@ -18,9 +18,18 @@ class IGSettingChatTableViewController: UITableViewController { let backgroundImageView = UIImageView(image: backImage) self.tableView.backgroundView = backgroundImageView } + + override func viewDidAppear(_ animated: Bool) { + self.tableView.isUserInteractionEnabled = true + } + override func viewWillAppear(_ animated: Bool) { + self.tableView.isUserInteractionEnabled = true + } + override func numberOfSections(in tableView: UITableView) -> Int { return 5 } + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { var numberOfRows : Int = 0 switch section { @@ -41,6 +50,7 @@ class IGSettingChatTableViewController: UITableViewController { return numberOfRows } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + // if indexPath.section == 0 { // switch indexPath.row { // case 0: @@ -57,9 +67,11 @@ class IGSettingChatTableViewController: UITableViewController { // performSegue(withIdentifier: "GoToCacheSettingsPage", sender: self) // } if indexPath.section == 0 && indexPath.row == 0 { + self.tableView.isUserInteractionEnabled = false performSegue(withIdentifier: "GoToCacheSettingsPage", sender: self) } if indexPath.section == 1 || indexPath.section == 2{ + self.tableView.isUserInteractionEnabled = false performSegue(withIdentifier: "GoToAutoDownloadTypePage", sender: self) } if indexPath.section == 4 { diff --git a/iGap/Controller/View Controllers/Setting/IGSettingContactBlockListTableViewController.swift b/iGap/Controller/View Controllers/Setting/IGSettingContactBlockListTableViewController.swift index 404d854..e048c72 100644 --- a/iGap/Controller/View Controllers/Setting/IGSettingContactBlockListTableViewController.swift +++ b/iGap/Controller/View Controllers/Setting/IGSettingContactBlockListTableViewController.swift @@ -64,6 +64,14 @@ class IGSettingContactBlockListTableViewController: UITableViewController , UIGe break } } + } + + override func viewDidAppear(_ animated: Bool) { + self.tableView.isUserInteractionEnabled = true + } + override func viewWillAppear(_ animated: Bool) { + self.tableView.isUserInteractionEnabled = true + } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() @@ -94,6 +102,7 @@ class IGSettingContactBlockListTableViewController: UITableViewController , UIGe override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let lastRowIndex = self.tableView.numberOfRows(inSection: 0) - 1 if indexPath.row == lastRowIndex{ + self.tableView.isUserInteractionEnabled = false performSegue(withIdentifier: "GoToChooseContactAddToBlockListPage", sender: self) } } diff --git a/iGap/Controller/View Controllers/Setting/IGSettingContactsTableViewController.swift b/iGap/Controller/View Controllers/Setting/IGSettingContactsTableViewController.swift index 6b3c4a2..ff318cd 100644 --- a/iGap/Controller/View Controllers/Setting/IGSettingContactsTableViewController.swift +++ b/iGap/Controller/View Controllers/Setting/IGSettingContactsTableViewController.swift @@ -143,6 +143,7 @@ class IGSettingContactsTableViewController: UITableViewController,UISearchResult override func viewDidAppear(_ animated: Bool) { self.navigationController?.extendedLayoutIncludesOpaqueBars = true + self.tableView.isUserInteractionEnabled = true } @IBAction func addBarButtonClicked(_ sender: UIBarButtonItem) { @@ -244,6 +245,7 @@ class IGSettingContactsTableViewController: UITableViewController,UISearchResult override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { if resultSearchController.isActive == false { if indexPath.section == 0 && indexPath.row == 0 { + self.tableView.isUserInteractionEnabled = false performSegue(withIdentifier: "GoToBlockListPage", sender: self) } else { self.hud = MBProgressHUD.showAdded(to: self.view, animated: true) diff --git a/iGap/Controller/View Controllers/Setting/IGSettingPrivacy&SecurityPasscodeLockTableViewController.swift b/iGap/Controller/View Controllers/Setting/IGSettingPrivacy&SecurityPasscodeLockTableViewController.swift index 243a76e..e425e15 100644 --- a/iGap/Controller/View Controllers/Setting/IGSettingPrivacy&SecurityPasscodeLockTableViewController.swift +++ b/iGap/Controller/View Controllers/Setting/IGSettingPrivacy&SecurityPasscodeLockTableViewController.swift @@ -26,9 +26,20 @@ class IGSettingPrivacy_SecurityPasscodeLockTableViewController: UITableViewContr let navigationItem = self.navigationItem as! IGNavigationItem navigationItem.addNavigationViewItems(rightItemText: nil, title: "Passcode Lock") } + + override func viewDidAppear(_ animated: Bool) { + self.tableView.isUserInteractionEnabled = true + + } + override func viewWillAppear(_ animated: Bool) { + self.tableView.isUserInteractionEnabled = true + + } + override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } + override func numberOfSections(in tableView: UITableView) -> Int { if loadItForSecendTime == false { return 1 @@ -62,7 +73,8 @@ class IGSettingPrivacy_SecurityPasscodeLockTableViewController: UITableViewContr default: break } - self.performSegue(withIdentifier: "EnterPassCode", sender: self) + self.tableView.isUserInteractionEnabled = false + self.performSegue(withIdentifier: "EnterPassCode", sender: self) } if loadItForSecendTime == true{ if indexPath.section == 1 { diff --git a/iGap/Controller/View Controllers/Setting/IGSettingPrivacy&SecurityTableViewController.swift b/iGap/Controller/View Controllers/Setting/IGSettingPrivacy&SecurityTableViewController.swift index 5258a44..044a068 100644 --- a/iGap/Controller/View Controllers/Setting/IGSettingPrivacy&SecurityTableViewController.swift +++ b/iGap/Controller/View Controllers/Setting/IGSettingPrivacy&SecurityTableViewController.swift @@ -146,6 +146,7 @@ class IGSettingPrivacy_SecurityTableViewController: UITableViewController , UIGe } override func viewWillAppear(_ animated: Bool) { + self.tableView.isUserInteractionEnabled = true fetchBlockedContactsFromServer() numberOfBlockedContacts.text = "\(blockedUsers.count) Contact " if let avatarPrivacy = userPrivacy?.avatar { @@ -254,20 +255,25 @@ class IGSettingPrivacy_SecurityTableViewController: UITableViewController , UIGe override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { selectedIndexPath = indexPath if indexPath.section == 0 && indexPath.row == 0 { - performSegue(withIdentifier: "GoToBlockListPageFromPrivacyAndSecurity", sender: self) + self.tableView.isUserInteractionEnabled = false + performSegue(withIdentifier: "GoToBlockListPageFromPrivacyAndSecurity", sender: self) //selectedIndexPath = indexPath } if indexPath.section == 0 && indexPath.row != 0 { - performSegue(withIdentifier: "GoToWhoCanSeeYourPrivacyAndPolicyPage", sender: self) + self.tableView.isUserInteractionEnabled = false + performSegue(withIdentifier: "GoToWhoCanSeeYourPrivacyAndPolicyPage", sender: self) } if indexPath.section == 1 { switch indexPath.row { case 1 : + self.tableView.isUserInteractionEnabled = false performSegue(withIdentifier: "GoToPassCodeLockSettingsPage", sender: self) case 2 : + self.tableView.isUserInteractionEnabled = false performSegue(withIdentifier: "GoToTwoStepVerificationPage", sender: self) case 0 : + self.tableView.isUserInteractionEnabled = false performSegue(withIdentifier: "GoToActiveSessionListPage", sender: self) default: break diff --git a/iGap/Controller/View Controllers/Setting/IGSettingPrivacyAndSecurityActiveSessionsTableViewController.swift b/iGap/Controller/View Controllers/Setting/IGSettingPrivacyAndSecurityActiveSessionsTableViewController.swift index dd37623..4a76611 100644 --- a/iGap/Controller/View Controllers/Setting/IGSettingPrivacyAndSecurityActiveSessionsTableViewController.swift +++ b/iGap/Controller/View Controllers/Setting/IGSettingPrivacyAndSecurityActiveSessionsTableViewController.swift @@ -34,7 +34,8 @@ class IGSettingPrivacyAndSecurityActiveSessionsTableViewController: UITableViewC } override func viewWillAppear(_ animated: Bool) { - + self.tableView.isUserInteractionEnabled = true + } override func numberOfSections(in tableView: UITableView) -> Int { @@ -138,12 +139,14 @@ class IGSettingPrivacyAndSecurityActiveSessionsTableViewController: UITableViewC override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + if indexPath.section != otherSessions.count + 1 { if indexPath.section == 0 { selectedSession = currentSession } else { selectedSession = otherSessions[indexPath.section - 1] } + self.tableView.isUserInteractionEnabled = false performSegue(withIdentifier: "GoToActiveSessionDetailsPage", sender: self) } else { let logoutConfirmAlertView = UIAlertController(title: "Are you sure you want to Terminate All Sessions?", message: nil, preferredStyle: .actionSheet) diff --git a/iGap/Controller/View Controllers/Setting/IGSettingTableViewController.swift b/iGap/Controller/View Controllers/Setting/IGSettingTableViewController.swift index dcab0fd..853d76f 100644 --- a/iGap/Controller/View Controllers/Setting/IGSettingTableViewController.swift +++ b/iGap/Controller/View Controllers/Setting/IGSettingTableViewController.swift @@ -12,7 +12,9 @@ import UIKit import RealmSwift import IGProtoBuff import INSPhotoGalleryFramework - +import RxRealm +import RxSwift +import Gifu class IGSettingTableViewController: UITableViewController { @IBOutlet weak var usernameLabel: UILabel! @@ -23,18 +25,29 @@ class IGSettingTableViewController: UITableViewController { let borderName = CALayer() let width = CGFloat(0.5) var shareContent = NSString() + var user : IGRegisteredUser? + var avatars: [IGAvatar] = [] + var deleteView: IGTappableView? + var userAvatar: IGAvatar? + var downloadIndicatorMainView : IGDownloadUploadIndicatorView? + + + let disposeBag = DisposeBag() override func viewDidLoad() { super.viewDidLoad() + requestToGetAvatarList() let currentUserId = IGAppManager.sharedManager.userID() + let realm = try! Realm() let predicate = NSPredicate(format: "id = %lld", currentUserId!) if let userInDb = realm.objects(IGRegisteredUser.self).filter(predicate).first { userAvatarView.setUser(userInDb) usernameLabel.text = userInDb.displayName - //let tap = UITapGestureRecognizer.init(target: self, action: ((self.showAvatar(avatar:userInDb.avatar!)))) - //userAvatarView.addGestureRecognizer(tap) - userAvatarView.isUserInteractionEnabled = true + user = userInDb + userAvatarView.avatarImageView?.isUserInteractionEnabled = true + let tap = UITapGestureRecognizer.init(target: self, action: #selector(self.handleTap(recognizer:))) + userAvatarView.avatarImageView?.addGestureRecognizer(tap) let navigationItem = self.navigationItem as! IGNavigationItem navigationItem.addModalViewItems(leftItemText: nil, rightItemText: "Done", title: "Settings") @@ -55,13 +68,182 @@ class IGSettingTableViewController: UITableViewController { self.tableView.backgroundView = UIImageView(image: UIImage(named: "IG_Settigns_Bg")) tableView.tableFooterView = UIView() imagePicker.delegate = self + + + } + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + self.tableView.isUserInteractionEnabled = true + requestToGetAvatarList() + } + override func viewWillAppear(_ animated: Bool) { + self.tableView.isUserInteractionEnabled = true + + } + + func requestToGetAvatarList() { + if let currentUserId = IGAppManager.sharedManager.userID() { + IGUserAvatarGetListRequest.Generator.generate(userId: currentUserId).success({ (protoResponse) in + DispatchQueue.main.async { + switch protoResponse { + case let UserAvatarGetListoResponse as IGPUserAvatarGetListResponse: + let responseAvatars = IGUserAvatarGetListRequest.Handler.interpret(response: UserAvatarGetListoResponse, userId: currentUserId) + self.avatars = responseAvatars + for avatar in self.avatars { + let avatarView = IGImageView() + avatarView.setImage(avatar: avatar) + } + + + default: + break + } + } + }).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() + } + } + + func handleTap(recognizer:UITapGestureRecognizer) { + if recognizer.state == .ended { + if let userAvatar = user?.avatar { + showAvatar( avatar: userAvatar) + } + } } - func showAvatar(avatar: IGAvatar) { - let photos = [IGMedia(avatar: avatar)] + var avatarPhotos : [INSPhotoViewable]? + var galleryPhotos: INSPhotosViewController? + func showAvatar(avatar : IGAvatar) { + var photos: [INSPhotoViewable] = self.avatars.map { (avatar) -> IGMedia in + // setMediaIndicator(avatar: avatar) + return IGMedia(avatar: avatar) + } + avatarPhotos = photos let currentPhoto = photos[0] - let galleryPreview = INSPhotosViewController(photos: photos, initialPhoto: currentPhoto, referenceView: nil) + + let deleteViewFrame = CGRect(x:320, y:595, width: 25 , height:25) + let trashImageView = UIImageView() + trashImageView.image = UIImage(named: "IG_Trash_avatar") + trashImageView.frame = CGRect(x: 0, y: 0, width: 25, height: 25) + deleteView = IGTappableView(frame: deleteViewFrame) + deleteView?.addSubview(trashImageView) + let downloadViewFrame = self.view.bounds + deleteView?.addAction { + self.didTapOnTrashButton() + } + downloadIndicatorMainView = IGDownloadUploadIndicatorView(frame: downloadViewFrame) + let galleryPreview = INSPhotosViewController(photos: photos, initialPhoto: currentPhoto, referenceView: nil, deleteView: deleteView, downloadView: nil) + galleryPhotos = galleryPreview present(galleryPreview, animated: true, completion: nil) + + } + + func setMediaIndicator(avatar: IGAvatar) { + if let msgAttachment = avatar.file { + if let messageAttachmentVariableInCache = IGAttachmentManager.sharedManager.getRxVariable(attachmentPrimaryKeyId: msgAttachment.primaryKeyId!) { + self.userAvatar?.file = messageAttachmentVariableInCache.value + } else { + self.userAvatar?.file = msgAttachment.detach() + let attachmentRef = ThreadSafeReference(to: msgAttachment) + IGAttachmentManager.sharedManager.add(attachmentRef: attachmentRef) + self.userAvatar?.file = IGAttachmentManager.sharedManager.getRxVariable(attachmentPrimaryKeyId: msgAttachment.primaryKeyId!)?.value + } + + + if let variableInCache = IGAttachmentManager.sharedManager.getRxVariable(attachmentPrimaryKeyId: msgAttachment.primaryKeyId!) { + self.userAvatar?.file = variableInCache.value + variableInCache.asObservable().subscribe({ (event) in + DispatchQueue.main.async { + self.updateAttachmentDownloadUploadIndicatorView() + } + }).addDisposableTo(disposeBag) + } else { + } + + //MARK: ▶︎ Rx End + //self.forwardedMessageAudioAndVoiceViewHeightConstraint.constant = 0 + self.userAvatarView.isHidden = false + self.downloadIndicatorMainView?.isHidden = false + let progress = Progress(totalUnitCount: 100) + progress.completedUnitCount = 0 + + // self.sharedMediaImageView.setThumbnail(for: msgAttachment) + // self.forwardedMessageMediaContainerViewHeightConstraint.constant = messageSizes.forwardedMessageAttachmentHeight //+ 20 + + if msgAttachment.status != .ready { + self.downloadIndicatorMainView?.size = msgAttachment.sizeToString() + self.downloadIndicatorMainView?.delegate = self + } + + + } + + } + + + func updateAttachmentDownloadUploadIndicatorView() { + if let attachment = self.userAvatar?.file { + + if attachment.status == .ready { + self.downloadIndicatorMainView?.setState(attachment.status) + setThumbnailForAttachments() + if attachment.type == .image { + // self.currentPhoto.setThumbnail(for: attachment) + } + return + } + + + switch attachment.type { + case .video, .image: + self.downloadIndicatorMainView?.setFileType(.media) + self.downloadIndicatorMainView?.setState(attachment.status) + if attachment.status == .downloading || attachment.status == .uploading { + self.downloadIndicatorMainView?.setPercentage(attachment.downloadUploadPercent) + } + default: + break + } + } + + } + + func setThumbnailForAttachments() { + if let attachment = self.userAvatar?.file { + // self.currentPhoto.isHidden = false + + } + } + + + func didTapOnTrashButton() { + +// galleryPhotos?.currentPhotoViewController = { [weak self] photo in +// if let index = self?.avatarPhotos?.index(where: {$0 === photo}) { +// print(self?.avatars[index].id) +// // let indexPath = IndexPath(item: index, section: 0) +// //let cell = collectionView.cellForItem(at: indexPath) as? ExampleCollectionViewCell +// } +// return nil +// } +// if let index = self.avatarPhotos?.index(where: {$0 === photo}) { +// print(avatars[index].id) +// +// } + } override func numberOfSections(in tableView: UITableView) -> Int { @@ -82,19 +264,29 @@ class IGSettingTableViewController: UITableViewController { } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + + if indexPath.section == 0 && indexPath.row == 0 { + self.tableView.isUserInteractionEnabled = false performSegue(withIdentifier: "GoToAccountSettingPage", sender: self) } if indexPath.section == 1 && indexPath.row == 0 { + self.tableView.isUserInteractionEnabled = false + performSegue(withIdentifier: "GoToContactListPage", sender: self) } if indexPath.section == 1 && indexPath.row == 2 { + self.tableView.isUserInteractionEnabled = false + performSegue(withIdentifier: "GoToChatSettingPage", sender: self) } if indexPath.section == 1 && indexPath.row == 3 { + self.tableView.isUserInteractionEnabled = false + performSegue(withIdentifier: "GoToNotificationSettingsPage", sender: self) } if indexPath.section == 1 && indexPath.row == 1 { + self.tableView.isUserInteractionEnabled = false performSegue(withIdentifier: "GoToPrivacyAndPolicySettingsPage", sender: self) } if indexPath.section == 2 && indexPath.row == 0 { @@ -104,6 +296,7 @@ class IGSettingTableViewController: UITableViewController { present(activityViewController, animated: true, completion: {}) } if indexPath.section == 2 && indexPath.row == 1 { + self.tableView.isUserInteractionEnabled = false performSegue(withIdentifier: "GoToAboutSettingPage", sender: self) } } @@ -223,3 +416,24 @@ extension IGSettingTableViewController: UIImagePickerControllerDelegate { extension IGSettingTableViewController: UINavigationControllerDelegate { } +extension IGSettingTableViewController: IGDownloadUploadIndicatorViewDelegate { + func downloadUploadIndicatorDidTapOnStart(_ indicator: IGDownloadUploadIndicatorView) { + if self.userAvatar?.file?.status == .downloading { + return + } + + if let attachment = self.userAvatar?.file { + IGDownloadManager.sharedManager.download(file: attachment, previewType: .originalFile, completion: { + + }, failure: { + + }) + } + + } + + func downloadUploadIndicatorDidTapOnCancel(_ indicator: IGDownloadUploadIndicatorView) { + + } +} + diff --git a/iGap/Controller/View Controllers/Setting/iGAccountTableViewController.swift b/iGap/Controller/View Controllers/Setting/iGAccountTableViewController.swift index 9a992dc..f214194 100644 --- a/iGap/Controller/View Controllers/Setting/iGAccountTableViewController.swift +++ b/iGap/Controller/View Controllers/Setting/iGAccountTableViewController.swift @@ -40,6 +40,7 @@ class IGAccountTableViewController: UITableViewController , UINavigationControll override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) + self.tableView.isUserInteractionEnabled = true changeBackButtonItemPosition() if currentUser.email == nil { getUserEmail() @@ -110,23 +111,29 @@ class IGAccountTableViewController: UITableViewController , UINavigationControll } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - if indexPath.section == 0 && indexPath.row == 0 { + self.tableView.isUserInteractionEnabled = false performSegue(withIdentifier: "GoToNicknamePage", sender: self) } // if indexPath.section == 1 && indexPath.row == 0 { + // self.tableView.isUserInteractionEnabled = false + // performSegue(withIdentifier: "GoToPhoneNumberPage", sender: self) // } if indexPath.section == 1 && indexPath.row == 1 { + self.tableView.isUserInteractionEnabled = false performSegue(withIdentifier: "GoToUsernamePage", sender: self) } if indexPath.section == 1 && indexPath.row == 2 { + self.tableView.isUserInteractionEnabled = false performSegue(withIdentifier: "GoToEmailPage", sender: self) } if indexPath.section == 2 && indexPath.row == 0 { + self.tableView.isUserInteractionEnabled = false performSegue(withIdentifier: "GoToDeleteAccountPage", sender: self) } if indexPath.section == 2 && indexPath.row == 1 { + self.tableView.isUserInteractionEnabled = false performSegue(withIdentifier: "GoToSelfDestructionTimePage", sender: self) } if indexPath.section == 3 && indexPath.row == 0 { diff --git a/iGap/Controller/View Controllers/Setting/iGSettingAboutTableViewController.swift b/iGap/Controller/View Controllers/Setting/iGSettingAboutTableViewController.swift index d5cea3c..35ed8e7 100644 --- a/iGap/Controller/View Controllers/Setting/iGSettingAboutTableViewController.swift +++ b/iGap/Controller/View Controllers/Setting/iGSettingAboutTableViewController.swift @@ -27,6 +27,9 @@ class IGSettingAboutTableViewController: UITableViewController , UIGestureRecogn let navigationController = self.navigationController as! IGNavigationController navigationController.interactivePopGestureRecognizer?.delegate = self } + override func viewDidAppear(_ animated: Bool) { + self.tableView.isUserInteractionEnabled = true + } // MARK: - Table view data source override func numberOfSections(in tableView: UITableView) -> Int { @@ -56,13 +59,16 @@ class IGSettingAboutTableViewController: UITableViewController , UIGestureRecogn switch indexPath.row { case 0: index = indexPath.row + self.tableView.isUserInteractionEnabled = false performSegue(withIdentifier: "GoToWebPage", sender: self) case 1: index = indexPath.row - performSegue(withIdentifier: "GoToWebPage", sender: self) + self.tableView.isUserInteractionEnabled = false + performSegue(withIdentifier: "GoToWebPage", sender: self) case 2: index = indexPath.row - performSegue(withIdentifier: "GoToWebPage", sender: self) + self.tableView.isUserInteractionEnabled = false + performSegue(withIdentifier: "GoToWebPage", sender: self) default: break } diff --git a/iGap/Controller/View Controllers/Splash and Register/IGRegistrationStepPhoneViewController.swift b/iGap/Controller/View Controllers/Splash and Register/IGRegistrationStepPhoneViewController.swift index 9e021ba..ebce98f 100644 --- a/iGap/Controller/View Controllers/Splash and Register/IGRegistrationStepPhoneViewController.swift +++ b/iGap/Controller/View Controllers/Splash and Register/IGRegistrationStepPhoneViewController.swift @@ -30,6 +30,7 @@ class IGRegistrationStepPhoneViewController: UIViewController { var registrationResponse : (username:String, userId:Int64, authorHash:String, verificationMethod: IGVerificationCodeSendMethod, resendDelay:Int32, codeDigitsCount:Int32, codeRegex:String)? var hud = MBProgressHUD() private let disposeBag = DisposeBag() + var connectionStatus: IGAppManager.ConnectionStatus? private func updateNavigationBarBasedOnNetworkStatus(_ status: IGAppManager.ConnectionStatus) { let navigationItem = self.navigationItem as! IGNavigationItem @@ -37,9 +38,11 @@ class IGRegistrationStepPhoneViewController: UIViewController { switch status { case .waitingForNetwork: navigationItem.setNavigationItemForWaitingForNetwork() + connectionStatus = .waitingForNetwork break case .connecting: navigationItem.setNavigationItemForConnecting() + connectionStatus = .connecting if selectedCountry == nil { selectedCountry = IGCountryInfo.defaultCountry() } @@ -48,6 +51,7 @@ class IGRegistrationStepPhoneViewController: UIViewController { case .connected: self.setDefaultNavigationItem() self.getUserCurrentLocation() + connectionStatus = .connected break } } @@ -65,6 +69,7 @@ class IGRegistrationStepPhoneViewController: UIViewController { IGAppManager.sharedManager.connectionStatus.asObservable().subscribe(onNext: { (connectionStatus) in DispatchQueue.main.async { self.updateNavigationBarBasedOnNetworkStatus(connectionStatus) + } }, onError: { (error) in @@ -124,6 +129,13 @@ class IGRegistrationStepPhoneViewController: UIViewController { } func didTapOnNext() { + if connectionStatus == .waitingForNetwork || connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + + } else { if let phone = phoneNumberField.text { let phoneSpaceLess = phone.replacingOccurrences(of: " ", with: "") if IGGlobal.matches(for: (selectedCountry?.codeRegex)!, in: phoneSpaceLess) { @@ -234,6 +246,7 @@ class IGRegistrationStepPhoneViewController: UIViewController { }) //self.performSegue(withIdentifier: "showRegistration", sender: self) + } } diff --git a/iGap/Controller/View Controllers/Tabbar Sub Controllers/IGChannelsTableViewController.swift b/iGap/Controller/View Controllers/Tabbar Sub Controllers/IGChannelsTableViewController.swift index 57e69fa..a5c6696 100644 --- a/iGap/Controller/View Controllers/Tabbar Sub Controllers/IGChannelsTableViewController.swift +++ b/iGap/Controller/View Controllers/Tabbar Sub Controllers/IGChannelsTableViewController.swift @@ -15,6 +15,10 @@ import RealmSwift import RxRealm import RxSwift import RxCocoa +import MGSwipeTableCell +import MBProgressHUD + + class IGChannelsTableViewController: UITableViewController { @@ -22,6 +26,10 @@ class IGChannelsTableViewController: UITableViewController { var cellIdentifer = IGChatRoomListTableViewCell.cellReuseIdentifier() var rooms: Results? = nil var notificationToken: NotificationToken? + var connectionStatus: IGAppManager.ConnectionStatus? + var hud = MBProgressHUD() + + private let disposeBag = DisposeBag() override func viewDidLoad() { super.viewDidLoad() @@ -70,6 +78,7 @@ class IGChannelsTableViewController: UITableViewController { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) + self.tableView.isUserInteractionEnabled = true //self.setTabbarHidden(false, animated: true) } @@ -109,11 +118,157 @@ class IGChannelsTableViewController: UITableViewController { let cell: IGChatRoomListTableViewCell = self.tableView.dequeueReusableCell(withIdentifier: cellIdentifer) as! IGChatRoomListTableViewCell cell.setRoom(room: rooms![indexPath.row]) + cell.rightButtons = + [MGSwipeButton(title: "Delete", backgroundColor: UIColor(red: 252.0/255.0, green: 23.0/255.0, blue: 22.0/255.0, alpha: 1), callback: { (sender: MGSwipeTableCell!) -> Bool in + let room = cell.room! + //let room = self.rooms![indexPath.row] + let title = room.title != nil ? room.title! : "Delete" + let alertC = UIAlertController(title: title, message: "What do you want to do?", preferredStyle: .actionSheet) + let clear = UIAlertAction(title: "Clear History", style: .default, handler: { (action) in + switch room.type{ + case .chat: + if self.connectionStatus == .waitingForNetwork || self.connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + + } else { + self.clearChatMessageHistory(room: room) + } + case .group: + if self.connectionStatus == .waitingForNetwork || self.connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + + } else { + self.clearGroupMessageHistory(room: room) + } + default: + break + } + + }) + + let remove = UIAlertAction(title: "Delete", style: .destructive, handler: { (action) in + switch room.type { + case .chat: + if self.connectionStatus == .waitingForNetwork || self.connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + + } else { + self.deleteChat(room: room) + } + case .group: + if self.connectionStatus == .waitingForNetwork || self.connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + + } else { + self.deleteGroup(room: room) + } + default: + break + } + }) + + + + let leave = UIAlertAction(title: "Leave", style: .destructive, handler: { (action) in + switch room.type { + case .chat: + break + case .group: + if self.connectionStatus == .waitingForNetwork || self.connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + + + } else { + self.leaveGroup(room: room) + } + case .channel: + if self.connectionStatus == .waitingForNetwork || self.connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + + + } else { + self.leaveChannel(room: room) + } + } + }) + + let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: { (action) in + + }) + + + if room.type == .chat || room.type == .group { + alertC.addAction(clear) + } + if room.chatRoom != nil { + alertC.addAction(remove) + } else { + if let groupRoom = room.groupRoom { + if groupRoom.role == .owner { + alertC.addAction(leave) + alertC.addAction(remove) + } else{ + alertC.addAction(leave) + } + } else if let channel = room.channelRoom { + if channel.role == .owner { + alertC.addAction(remove) + alertC.addAction(leave) + } else{ + alertC.addAction(leave) + } + } + } + + + alertC.addAction(cancel) + + self.present(alertC, animated: true, completion: { + + }) + + return true + })] + cell.rightSwipeSettings.transition = MGSwipeTransition.border + + + cell.leftExpansion.buttonIndex = 0 + cell.leftExpansion.fillOnTrigger = true + cell.leftExpansion.threshold = 2.0 + + cell.rightExpansion.buttonIndex = 0 + cell.rightExpansion.fillOnTrigger = true + cell.rightExpansion.threshold = 1.5 + + + cell.separatorInset = UIEdgeInsets(top: 0, left: 82.0, bottom: 0, right: 0) + cell.layoutMargins = UIEdgeInsets.zero + + return cell } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { selectedRoomForSegue = rooms![indexPath.row] + self.tableView.isUserInteractionEnabled = false performSegue(withIdentifier: "showRoomMessages", sender: self) } @@ -139,3 +294,191 @@ class IGChannelsTableViewController: UITableViewController { // } } } + +extension IGChannelsTableViewController { + func clearChatMessageHistory(room: IGRoom) { + self.hud = MBProgressHUD.showAdded(to: self.view.superview!, animated: true) + self.hud.mode = .indeterminate + IGChatClearMessageRequest.Generator.generate(room: room).success({ (protoResponse) in + DispatchQueue.main.async { + switch protoResponse { + case let clearChatMessages as IGPChatClearMessageResponse: + IGChatClearMessageRequest.Handler.interpret(response: clearChatMessages) + default: + break + } + self.hud.hide(animated: true) + } + }).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.hud.hide(animated: true) + self.present(alert, animated: true, completion: nil) + } + default: + DispatchQueue.main.async { + self.hud.hide(animated: true) + } + break + } + + }).send() + } + + func clearGroupMessageHistory(room: IGRoom) { + self.hud = MBProgressHUD.showAdded(to: self.view.superview!, animated: true) + self.hud.mode = .indeterminate + IGGroupClearMessageRequest.Generator.generate(group: room).success({ (protoResponse) in + DispatchQueue.main.async { + switch protoResponse { + case let deleteGroupMessageHistory as IGPGroupClearMessageResponse: + IGGroupClearMessageRequest.Handler.interpret(response: deleteGroupMessageHistory) + default: + break + } + self.hud.hide(animated: true) + } + }).error({ (errorCode , waitTime) in + DispatchQueue.main.async { + switch errorCode { + case .timeout: + 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 + } + self.hud.hide(animated: true) + } + }).send() + } + + func deleteChat(room: IGRoom) { + self.hud = MBProgressHUD.showAdded(to: self.view.superview!, animated: true) + self.hud.mode = .indeterminate + IGChatDeleteRequest.Generator.generate(room: room).success({ (protoResponse) in + DispatchQueue.main.async { + switch protoResponse { + case let deleteChat as IGPChatDeleteResponse: + IGChatDeleteRequest.Handler.interpret(response: deleteChat) + default: + break + } + self.hud.hide(animated: true) + } + }).error({ (errorCode , waitTime) in + DispatchQueue.main.async { + switch errorCode { + case .timeout: + 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.hud.hide(animated: true) + self.present(alert, animated: true, completion: nil) + default: + break + } + self.hud.hide(animated: true) + } + + }).send() + } + + func deleteGroup(room: IGRoom) { + self.hud = MBProgressHUD.showAdded(to: self.view.superview!, animated: true) + self.hud.mode = .indeterminate + IGGroupDeleteRequest.Generator.generate(group: room).success({ (protoResponse) in + DispatchQueue.main.async { + switch protoResponse { + case let deleteGroup as IGPGroupDeleteResponse: + IGGroupDeleteRequest.Handler.interpret(response: deleteGroup) + default: + break + } + self.hud.hide(animated: true) + } + }).error({ (errorCode , waitTime) in + DispatchQueue.main.async { + switch errorCode { + case .timeout: + 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 + } + self.hud.hide(animated: true) + } + }).send() + } + + func leaveGroup(room: IGRoom) { + self.hud = MBProgressHUD.showAdded(to: self.view.superview!, animated: true) + self.hud.mode = .indeterminate + IGGroupLeftRequest.Generator.generate(room: room).success{ (protoResponse) in + DispatchQueue.main.async { + switch protoResponse { + case let response as IGPGroupLeftResponse: + IGGroupLeftRequest.Handler.interpret(response: response) + default: + break + } + self.hud.hide(animated: true) + } + }.error { (errorCode, waitTime) in + DispatchQueue.main.async { + switch errorCode { + case .timeout: + 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: + let alert = UIAlertController(title: "Error", message: "There was an error leaving this group.", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + } + self.hud.hide(animated: true) + } + }.send() + } + + func leaveChannel(room: IGRoom) { + self.hud = MBProgressHUD.showAdded(to: self.view.superview!, animated: true) + self.hud.mode = .indeterminate + IGChannelLeftRequest.Generator.generate(room: room).success { (protoResponse) in + DispatchQueue.main.async { + switch protoResponse { + case let response as IGPChannelLeftResponse: + IGChannelLeftRequest.Handler.interpret(response: response) + default: + break + } + self.hud.hide(animated: true) + } + }.error { (errorCode, waitTime) in + DispatchQueue.main.async { + switch errorCode { + case .timeout: + 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: + let alert = UIAlertController(title: "Error", message: "There was an error leaving this channel.", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + } + self.hud.hide(animated: true) + } + }.send() + } +} diff --git a/iGap/Controller/View Controllers/Tabbar Sub Controllers/IGChatsTableViewController.swift b/iGap/Controller/View Controllers/Tabbar Sub Controllers/IGChatsTableViewController.swift index cc3fdac..67538e2 100644 --- a/iGap/Controller/View Controllers/Tabbar Sub Controllers/IGChatsTableViewController.swift +++ b/iGap/Controller/View Controllers/Tabbar Sub Controllers/IGChatsTableViewController.swift @@ -15,6 +15,8 @@ import RealmSwift import RxRealm import RxSwift import RxCocoa +import MGSwipeTableCell +import MBProgressHUD class IGChatsTableViewController: UITableViewController { @@ -22,6 +24,9 @@ class IGChatsTableViewController: UITableViewController { var cellIdentifer = IGChatRoomListTableViewCell.cellReuseIdentifier() var rooms: Results? = nil var notificationToken: NotificationToken? + var hud = MBProgressHUD() + var connectionStatus: IGAppManager.ConnectionStatus? + override func viewDidLoad() { super.viewDidLoad() @@ -69,6 +74,7 @@ class IGChatsTableViewController: UITableViewController { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) + self.tableView.isUserInteractionEnabled = true //self.setTabbarHidden(false, animated: true) } @@ -109,11 +115,156 @@ class IGChatsTableViewController: UITableViewController { let cell: IGChatRoomListTableViewCell = self.tableView.dequeueReusableCell(withIdentifier: cellIdentifer) as! IGChatRoomListTableViewCell cell.setRoom(room: rooms![indexPath.row]) + cell.rightButtons = + [MGSwipeButton(title: "Delete", backgroundColor: UIColor(red: 252.0/255.0, green: 23.0/255.0, blue: 22.0/255.0, alpha: 1), callback: { (sender: MGSwipeTableCell!) -> Bool in + let room = cell.room! + //let room = self.rooms![indexPath.row] + let title = room.title != nil ? room.title! : "Delete" + let alertC = UIAlertController(title: title, message: "What do you want to do?", preferredStyle: .actionSheet) + let clear = UIAlertAction(title: "Clear History", style: .default, handler: { (action) in + switch room.type{ + case .chat: + if self.connectionStatus == .waitingForNetwork || self.connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + + } else { + self.clearChatMessageHistory(room: room) + } + case .group: + if self.connectionStatus == .waitingForNetwork || self.connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + + } else { + self.clearGroupMessageHistory(room: room) + } + default: + break + } + + }) + + let remove = UIAlertAction(title: "Delete", style: .destructive, handler: { (action) in + switch room.type { + case .chat: + if self.connectionStatus == .waitingForNetwork || self.connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + + } else { + self.deleteChat(room: room) + } + case .group: + if self.connectionStatus == .waitingForNetwork || self.connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + + } else { + self.deleteGroup(room: room) + } + default: + break + } + }) + + + + let leave = UIAlertAction(title: "Leave", style: .destructive, handler: { (action) in + switch room.type { + case .chat: + break + case .group: + if self.connectionStatus == .waitingForNetwork || self.connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + + + } else { + self.leaveGroup(room: room) + } + case .channel: + if self.connectionStatus == .waitingForNetwork || self.connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + + + } else { + self.leaveChannel(room: room) + } + } + }) + + let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: { (action) in + + }) + + + if room.type == .chat || room.type == .group { + alertC.addAction(clear) + } + if room.chatRoom != nil { + alertC.addAction(remove) + } else { + if let groupRoom = room.groupRoom { + if groupRoom.role == .owner { + alertC.addAction(leave) + alertC.addAction(remove) + } else{ + alertC.addAction(leave) + } + } else if let channel = room.channelRoom { + if channel.role == .owner { + alertC.addAction(remove) + alertC.addAction(leave) + } else{ + alertC.addAction(leave) + } + } + } + + + alertC.addAction(cancel) + + self.present(alertC, animated: true, completion: { + + }) + + return true + })] + cell.rightSwipeSettings.transition = MGSwipeTransition.border + + + cell.leftExpansion.buttonIndex = 0 + cell.leftExpansion.fillOnTrigger = true + cell.leftExpansion.threshold = 2.0 + + cell.rightExpansion.buttonIndex = 0 + cell.rightExpansion.fillOnTrigger = true + cell.rightExpansion.threshold = 1.5 + + + cell.separatorInset = UIEdgeInsets(top: 0, left: 82.0, bottom: 0, right: 0) + cell.layoutMargins = UIEdgeInsets.zero + return cell } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { selectedRoomForSegue = rooms![indexPath.row] + self.tableView.isUserInteractionEnabled = false performSegue(withIdentifier: "showRoomMessages", sender: self) } @@ -140,3 +291,191 @@ class IGChatsTableViewController: UITableViewController { } } +extension IGChatsTableViewController { + func clearChatMessageHistory(room: IGRoom) { + self.hud = MBProgressHUD.showAdded(to: self.view.superview!, animated: true) + self.hud.mode = .indeterminate + IGChatClearMessageRequest.Generator.generate(room: room).success({ (protoResponse) in + DispatchQueue.main.async { + switch protoResponse { + case let clearChatMessages as IGPChatClearMessageResponse: + IGChatClearMessageRequest.Handler.interpret(response: clearChatMessages) + default: + break + } + self.hud.hide(animated: true) + } + }).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.hud.hide(animated: true) + self.present(alert, animated: true, completion: nil) + } + default: + DispatchQueue.main.async { + self.hud.hide(animated: true) + } + break + } + + }).send() + } + + func clearGroupMessageHistory(room: IGRoom) { + self.hud = MBProgressHUD.showAdded(to: self.view.superview!, animated: true) + self.hud.mode = .indeterminate + IGGroupClearMessageRequest.Generator.generate(group: room).success({ (protoResponse) in + DispatchQueue.main.async { + switch protoResponse { + case let deleteGroupMessageHistory as IGPGroupClearMessageResponse: + IGGroupClearMessageRequest.Handler.interpret(response: deleteGroupMessageHistory) + default: + break + } + self.hud.hide(animated: true) + } + }).error({ (errorCode , waitTime) in + DispatchQueue.main.async { + switch errorCode { + case .timeout: + 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 + } + self.hud.hide(animated: true) + } + }).send() + } + + func deleteChat(room: IGRoom) { + self.hud = MBProgressHUD.showAdded(to: self.view.superview!, animated: true) + self.hud.mode = .indeterminate + IGChatDeleteRequest.Generator.generate(room: room).success({ (protoResponse) in + DispatchQueue.main.async { + switch protoResponse { + case let deleteChat as IGPChatDeleteResponse: + IGChatDeleteRequest.Handler.interpret(response: deleteChat) + default: + break + } + self.hud.hide(animated: true) + } + }).error({ (errorCode , waitTime) in + DispatchQueue.main.async { + switch errorCode { + case .timeout: + 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.hud.hide(animated: true) + self.present(alert, animated: true, completion: nil) + default: + break + } + self.hud.hide(animated: true) + } + + }).send() + } + + func deleteGroup(room: IGRoom) { + self.hud = MBProgressHUD.showAdded(to: self.view.superview!, animated: true) + self.hud.mode = .indeterminate + IGGroupDeleteRequest.Generator.generate(group: room).success({ (protoResponse) in + DispatchQueue.main.async { + switch protoResponse { + case let deleteGroup as IGPGroupDeleteResponse: + IGGroupDeleteRequest.Handler.interpret(response: deleteGroup) + default: + break + } + self.hud.hide(animated: true) + } + }).error({ (errorCode , waitTime) in + DispatchQueue.main.async { + switch errorCode { + case .timeout: + 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 + } + self.hud.hide(animated: true) + } + }).send() + } + + func leaveGroup(room: IGRoom) { + self.hud = MBProgressHUD.showAdded(to: self.view.superview!, animated: true) + self.hud.mode = .indeterminate + IGGroupLeftRequest.Generator.generate(room: room).success{ (protoResponse) in + DispatchQueue.main.async { + switch protoResponse { + case let response as IGPGroupLeftResponse: + IGGroupLeftRequest.Handler.interpret(response: response) + default: + break + } + self.hud.hide(animated: true) + } + }.error { (errorCode, waitTime) in + DispatchQueue.main.async { + switch errorCode { + case .timeout: + 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: + let alert = UIAlertController(title: "Error", message: "There was an error leaving this group.", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + } + self.hud.hide(animated: true) + } + }.send() + } + + func leaveChannel(room: IGRoom) { + self.hud = MBProgressHUD.showAdded(to: self.view.superview!, animated: true) + self.hud.mode = .indeterminate + IGChannelLeftRequest.Generator.generate(room: room).success { (protoResponse) in + DispatchQueue.main.async { + switch protoResponse { + case let response as IGPChannelLeftResponse: + IGChannelLeftRequest.Handler.interpret(response: response) + default: + break + } + self.hud.hide(animated: true) + } + }.error { (errorCode, waitTime) in + DispatchQueue.main.async { + switch errorCode { + case .timeout: + 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: + let alert = UIAlertController(title: "Error", message: "There was an error leaving this channel.", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + } + self.hud.hide(animated: true) + } + }.send() + } +} + diff --git a/iGap/Controller/View Controllers/Tabbar Sub Controllers/IGGroupsTableViewController.swift b/iGap/Controller/View Controllers/Tabbar Sub Controllers/IGGroupsTableViewController.swift index a83585d..be95e42 100644 --- a/iGap/Controller/View Controllers/Tabbar Sub Controllers/IGGroupsTableViewController.swift +++ b/iGap/Controller/View Controllers/Tabbar Sub Controllers/IGGroupsTableViewController.swift @@ -15,6 +15,8 @@ import RxRealm import RxSwift import RxCocoa import IGProtoBuff +import MGSwipeTableCell +import MBProgressHUD class IGGroupsTableViewController: UITableViewController { @@ -22,7 +24,10 @@ class IGGroupsTableViewController: UITableViewController { var cellIdentifer = IGChatRoomListTableViewCell.cellReuseIdentifier() var rooms: Results? = nil var notificationToken: NotificationToken? - + var hud = MBProgressHUD() + var connectionStatus: IGAppManager.ConnectionStatus? + + override func viewDidLoad() { super.viewDidLoad() @@ -68,7 +73,7 @@ class IGGroupsTableViewController: UITableViewController { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - //self.setTabbarHidden(false, animated: true) + self.tableView.isUserInteractionEnabled = true } override func didReceiveMemoryWarning() { @@ -108,11 +113,157 @@ class IGGroupsTableViewController: UITableViewController { let cell: IGChatRoomListTableViewCell = self.tableView.dequeueReusableCell(withIdentifier: cellIdentifer) as! IGChatRoomListTableViewCell cell.setRoom(room: rooms![indexPath.row]) + cell.rightButtons = + [MGSwipeButton(title: "Delete", backgroundColor: UIColor(red: 252.0/255.0, green: 23.0/255.0, blue: 22.0/255.0, alpha: 1), callback: { (sender: MGSwipeTableCell!) -> Bool in + let room = cell.room! + //let room = self.rooms![indexPath.row] + let title = room.title != nil ? room.title! : "Delete" + let alertC = UIAlertController(title: title, message: "What do you want to do?", preferredStyle: .actionSheet) + let clear = UIAlertAction(title: "Clear History", style: .default, handler: { (action) in + switch room.type{ + case .chat: + if self.connectionStatus == .waitingForNetwork || self.connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + + } else { + self.clearChatMessageHistory(room: room) + } + case .group: + if self.connectionStatus == .waitingForNetwork || self.connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + + } else { + self.clearGroupMessageHistory(room: room) + } + default: + break + } + + }) + + let remove = UIAlertAction(title: "Delete", style: .destructive, handler: { (action) in + switch room.type { + case .chat: + if self.connectionStatus == .waitingForNetwork || self.connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + + } else { + self.deleteChat(room: room) + } + case .group: + if self.connectionStatus == .waitingForNetwork || self.connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + + } else { + self.deleteGroup(room: room) + } + default: + break + } + }) + + + + let leave = UIAlertAction(title: "Leave", style: .destructive, handler: { (action) in + switch room.type { + case .chat: + break + case .group: + if self.connectionStatus == .waitingForNetwork || self.connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + + + } else { + self.leaveGroup(room: room) + } + case .channel: + if self.connectionStatus == .waitingForNetwork || self.connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + + + } else { + self.leaveChannel(room: room) + } + } + }) + + let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: { (action) in + + }) + + + if room.type == .chat || room.type == .group { + alertC.addAction(clear) + } + if room.chatRoom != nil { + alertC.addAction(remove) + } else { + if let groupRoom = room.groupRoom { + if groupRoom.role == .owner { + alertC.addAction(leave) + alertC.addAction(remove) + } else{ + alertC.addAction(leave) + } + } else if let channel = room.channelRoom { + if channel.role == .owner { + alertC.addAction(remove) + alertC.addAction(leave) + } else{ + alertC.addAction(leave) + } + } + } + + + alertC.addAction(cancel) + + self.present(alertC, animated: true, completion: { + + }) + + return true + })] + cell.rightSwipeSettings.transition = MGSwipeTransition.border + + + cell.leftExpansion.buttonIndex = 0 + cell.leftExpansion.fillOnTrigger = true + cell.leftExpansion.threshold = 2.0 + + cell.rightExpansion.buttonIndex = 0 + cell.rightExpansion.fillOnTrigger = true + cell.rightExpansion.threshold = 1.5 + + + cell.separatorInset = UIEdgeInsets(top: 0, left: 82.0, bottom: 0, right: 0) + cell.layoutMargins = UIEdgeInsets.zero + + return cell } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { selectedRoomForSegue = rooms![indexPath.row] + self.tableView.isUserInteractionEnabled = false performSegue(withIdentifier: "showRoomMessages", sender: self) } @@ -139,3 +290,192 @@ class IGGroupsTableViewController: UITableViewController { } } + +extension IGGroupsTableViewController { + func clearChatMessageHistory(room: IGRoom) { + self.hud = MBProgressHUD.showAdded(to: self.view.superview!, animated: true) + self.hud.mode = .indeterminate + IGChatClearMessageRequest.Generator.generate(room: room).success({ (protoResponse) in + DispatchQueue.main.async { + switch protoResponse { + case let clearChatMessages as IGPChatClearMessageResponse: + IGChatClearMessageRequest.Handler.interpret(response: clearChatMessages) + default: + break + } + self.hud.hide(animated: true) + } + }).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.hud.hide(animated: true) + self.present(alert, animated: true, completion: nil) + } + default: + DispatchQueue.main.async { + self.hud.hide(animated: true) + } + break + } + + }).send() + } + + func clearGroupMessageHistory(room: IGRoom) { + self.hud = MBProgressHUD.showAdded(to: self.view.superview!, animated: true) + self.hud.mode = .indeterminate + IGGroupClearMessageRequest.Generator.generate(group: room).success({ (protoResponse) in + DispatchQueue.main.async { + switch protoResponse { + case let deleteGroupMessageHistory as IGPGroupClearMessageResponse: + IGGroupClearMessageRequest.Handler.interpret(response: deleteGroupMessageHistory) + default: + break + } + self.hud.hide(animated: true) + } + }).error({ (errorCode , waitTime) in + DispatchQueue.main.async { + switch errorCode { + case .timeout: + 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 + } + self.hud.hide(animated: true) + } + }).send() + } + + func deleteChat(room: IGRoom) { + self.hud = MBProgressHUD.showAdded(to: self.view.superview!, animated: true) + self.hud.mode = .indeterminate + IGChatDeleteRequest.Generator.generate(room: room).success({ (protoResponse) in + DispatchQueue.main.async { + switch protoResponse { + case let deleteChat as IGPChatDeleteResponse: + IGChatDeleteRequest.Handler.interpret(response: deleteChat) + default: + break + } + self.hud.hide(animated: true) + } + }).error({ (errorCode , waitTime) in + DispatchQueue.main.async { + switch errorCode { + case .timeout: + 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.hud.hide(animated: true) + self.present(alert, animated: true, completion: nil) + default: + break + } + self.hud.hide(animated: true) + } + + }).send() + } + + func deleteGroup(room: IGRoom) { + self.hud = MBProgressHUD.showAdded(to: self.view.superview!, animated: true) + self.hud.mode = .indeterminate + IGGroupDeleteRequest.Generator.generate(group: room).success({ (protoResponse) in + DispatchQueue.main.async { + switch protoResponse { + case let deleteGroup as IGPGroupDeleteResponse: + IGGroupDeleteRequest.Handler.interpret(response: deleteGroup) + default: + break + } + self.hud.hide(animated: true) + } + }).error({ (errorCode , waitTime) in + DispatchQueue.main.async { + switch errorCode { + case .timeout: + 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 + } + self.hud.hide(animated: true) + } + }).send() + } + + func leaveGroup(room: IGRoom) { + self.hud = MBProgressHUD.showAdded(to: self.view.superview!, animated: true) + self.hud.mode = .indeterminate + IGGroupLeftRequest.Generator.generate(room: room).success{ (protoResponse) in + DispatchQueue.main.async { + switch protoResponse { + case let response as IGPGroupLeftResponse: + IGGroupLeftRequest.Handler.interpret(response: response) + default: + break + } + self.hud.hide(animated: true) + } + }.error { (errorCode, waitTime) in + DispatchQueue.main.async { + switch errorCode { + case .timeout: + 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: + let alert = UIAlertController(title: "Error", message: "There was an error leaving this group.", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + } + self.hud.hide(animated: true) + } + }.send() + } + + func leaveChannel(room: IGRoom) { + self.hud = MBProgressHUD.showAdded(to: self.view.superview!, animated: true) + self.hud.mode = .indeterminate + IGChannelLeftRequest.Generator.generate(room: room).success { (protoResponse) in + DispatchQueue.main.async { + switch protoResponse { + case let response as IGPChannelLeftResponse: + IGChannelLeftRequest.Handler.interpret(response: response) + default: + break + } + self.hud.hide(animated: true) + } + }.error { (errorCode, waitTime) in + DispatchQueue.main.async { + switch errorCode { + case .timeout: + 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: + let alert = UIAlertController(title: "Error", message: "There was an error leaving this channel.", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + } + self.hud.hide(animated: true) + } + }.send() + } +} + diff --git a/iGap/Controller/View Controllers/Tabbar Sub Controllers/IGRecentsTableViewController.swift b/iGap/Controller/View Controllers/Tabbar Sub Controllers/IGRecentsTableViewController.swift index 41e6c7d..bc0c6db 100644 --- a/iGap/Controller/View Controllers/Tabbar Sub Controllers/IGRecentsTableViewController.swift +++ b/iGap/Controller/View Controllers/Tabbar Sub Controllers/IGRecentsTableViewController.swift @@ -26,6 +26,7 @@ class IGRecentsTableViewController: UITableViewController { var rooms: Results? = nil var notificationToken: NotificationToken? var hud = MBProgressHUD() + var connectionStatus: IGAppManager.ConnectionStatus? private let disposeBag = DisposeBag() @@ -34,11 +35,14 @@ class IGRecentsTableViewController: UITableViewController { switch status { case .waitingForNetwork: navigationItem.setNavigationItemForWaitingForNetwork() + connectionStatus = .waitingForNetwork break case .connecting: navigationItem.setNavigationItemForConnecting() + connectionStatus = .connecting break case .connected: + connectionStatus = .connected self.setDefaultNavigationItem() break } @@ -152,6 +156,7 @@ class IGRecentsTableViewController: UITableViewController { self.tableView.deleteRows(at: deletions.map { IndexPath(row: $0, section: 0) }, with: .none) self.tableView.reloadRows(at: modifications.map { IndexPath(row: $0, section: 0) }, with: .none) self.tableView.endUpdates() + self.tableView.reloadData() self.setTabbarBadge() break case .error(let err): @@ -175,14 +180,17 @@ class IGRecentsTableViewController: UITableViewController { selector: #selector(segueToChatNotificationReceived(_:)), name: NSNotification.Name(rawValue: kIGNotificationNameDidCreateARoom), object: nil) - } + } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) + self.tableView.isUserInteractionEnabled = true + } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) + self.tableView.isUserInteractionEnabled = true } override func didReceiveMemoryWarning() { @@ -343,9 +351,25 @@ class IGRecentsTableViewController: UITableViewController { let clear = UIAlertAction(title: "Clear History", style: .default, handler: { (action) in switch room.type{ case .chat: + if self.connectionStatus == .waitingForNetwork || self.connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + + } else { self.clearChatMessageHistory(room: room) + } case .group: + if self.connectionStatus == .waitingForNetwork || self.connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + + } else { self.clearGroupMessageHistory(room: room) + } default: break } @@ -355,9 +379,25 @@ class IGRecentsTableViewController: UITableViewController { let remove = UIAlertAction(title: "Delete", style: .destructive, handler: { (action) in switch room.type { case .chat: + if self.connectionStatus == .waitingForNetwork || self.connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + + } else { self.deleteChat(room: room) + } case .group: + if self.connectionStatus == .waitingForNetwork || self.connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + + } else { self.deleteGroup(room: room) + } default: break } @@ -370,9 +410,27 @@ class IGRecentsTableViewController: UITableViewController { case .chat: break case .group: + if self.connectionStatus == .waitingForNetwork || self.connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + + + } else { self.leaveGroup(room: room) + } case .channel: + if self.connectionStatus == .waitingForNetwork || self.connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + + + } else { self.leaveChannel(room: room) + } } }) @@ -433,6 +491,7 @@ class IGRecentsTableViewController: UITableViewController { override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { selectedRoomForSegue = rooms![indexPath.row] + self.tableView.isUserInteractionEnabled = false performSegue(withIdentifier: "showRoomMessages", sender: self) } @@ -495,6 +554,7 @@ class IGRecentsTableViewController: UITableViewController { } + func segueToChatNotificationReceived(_ aNotification: Notification) { if let roomId = aNotification.userInfo?["room"] as? Int64 { let predicate = NSPredicate(format: "id = %d", roomId) @@ -539,7 +599,7 @@ class IGRecentsTableViewController: UITableViewController { } //MARK:- Room Clear, Delete, Leave -extension IGRecentsTableViewController{ +extension IGRecentsTableViewController { func clearChatMessageHistory(room: IGRoom) { self.hud = MBProgressHUD.showAdded(to: self.view.superview!, animated: true) self.hud.mode = .indeterminate diff --git a/iGap/General/IGGlobal.swift b/iGap/General/IGGlobal.swift index 3de2830..e5a4089 100644 --- a/iGap/General/IGGlobal.swift +++ b/iGap/General/IGGlobal.swift @@ -13,6 +13,7 @@ import ProtocolBuffers let kIGUserLoggedInNotificationName = "im.igap.ios.user.logged.in" let kIGNotificationNameDidCreateARoom = "im.igap.ios.room.created" +let kIGNoticationForPushUserExpire = "im.igap.ios.user.expire" let statusBarTappedNotification = Notification(name: Notification.Name(rawValue: "im.igap.statusbarTapped")) diff --git a/iGap/Libraries/Chat Screen/Controller/IGMessageViewController.swift b/iGap/Libraries/Chat Screen/Controller/IGMessageViewController.swift index d0bd123..add9185 100644 --- a/iGap/Libraries/Chat Screen/Controller/IGMessageViewController.swift +++ b/iGap/Libraries/Chat Screen/Controller/IGMessageViewController.swift @@ -82,7 +82,7 @@ class IGMessageViewController: UIViewController, DidSelectLocationDelegate , UIG @IBOutlet weak var inputBarOriginalMessageViewSenderNameLabel: UILabel! @IBOutlet weak var inputBarOriginalMessageViewBodyTextLabel: UILabel! @IBOutlet weak var scrollToBottomContainerView: UIView! - + @IBOutlet weak var scrollToBottomContainerViewConstraint: NSLayoutConstraint! private let disposeBag = DisposeBag() var isFetchingRoomHistory: Bool = false var isInMessageViewController : Bool = true @@ -96,6 +96,7 @@ class IGMessageViewController: UIViewController, DidSelectLocationDelegate , UIG var bouncingViewWhileRecord: UIView? var initialLongTapOnRecordButtonPosition: CGPoint? var collectionViewTopInsetOffset: CGFloat = 0.0 + var connectionStatus : IGAppManager.ConnectionStatus? //var messages = [IGRoomMessage]() @@ -129,6 +130,22 @@ class IGMessageViewController: UIViewController, DidSelectLocationDelegate , UIG //MARK: - Initilizers override func viewDidLoad() { super.viewDidLoad() + + IGAppManager.sharedManager.connectionStatus.asObservable().subscribe(onNext: { (connectionStatus) in + DispatchQueue.main.async { + self.updateConnectionStatus(connectionStatus) + + } + }, onError: { (error) in + + }, onCompleted: { + + }, onDisposed: { + + }).addDisposableTo(disposeBag) + + + self.addNotificationObserverForTapOnStatusBar() var canBecomeFirstResponder: Bool { return true } let navigationItem = self.navigationItem as! IGNavigationItem @@ -168,6 +185,8 @@ class IGMessageViewController: UIViewController, DidSelectLocationDelegate , UIG } else { inputBarContainerView.isHidden = true collectionViewTopInsetOffset = -54.0 + 8.0 + + } } else { @@ -280,7 +299,6 @@ class IGMessageViewController: UIViewController, DidSelectLocationDelegate , UIG UIView.animate(withDuration: 0.2, animations: { self.collectionView.alpha = 1.0 }) - break case .update(_, let deletions, let insertions, let modifications): @@ -330,6 +348,8 @@ class IGMessageViewController: UIViewController, DidSelectLocationDelegate , UIG break } } + + } override func viewWillAppear(_ animated: Bool) { @@ -431,7 +451,6 @@ class IGMessageViewController: UIViewController, DidSelectLocationDelegate , UIG - //MARK - Send Seen Status private func setMessagesRead() { if let room = self.room { @@ -612,15 +631,34 @@ class IGMessageViewController: UIViewController, DidSelectLocationDelegate , UIG }) } + func updateConnectionStatus(_ status: IGAppManager.ConnectionStatus) { + + switch status { + case .connected: + connectionStatus = .connected + case .connecting: + connectionStatus = .connecting + case .waitingForNetwork: + connectionStatus = .waitingForNetwork + } + + } + + + //MARK: IBActions @IBAction func didTapOnSendButton(_ sender: UIButton) { if currentAttachment == nil && inputTextView.text == "" && selectedMessageToForwardToThisRoom == nil { return } - - + if connectionStatus == .waitingForNetwork || connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + }else { if selectedMessageToEdit != nil { - switch room!.type { + switch room!.type { case .chat: IGChatEditMessageRequest.Generator.generate(message: selectedMessageToEdit!, newText: inputTextView.text, room: room!).success({ (protoResponse) in IGChatEditMessageRequest.Handler.interpret(response: protoResponse) @@ -650,6 +688,7 @@ class IGMessageViewController: UIViewController, DidSelectLocationDelegate , UIG }).send() } + selectedMessageToEdit = nil self.inputTextView.text = "" self.setInputBarHeight() @@ -713,6 +752,7 @@ class IGMessageViewController: UIViewController, DidSelectLocationDelegate , UIG self.selectedMessageToReply = nil self.currentAttachment = nil self.setInputBarHeight() + } } @@ -1474,6 +1514,9 @@ extension IGMessageViewController: UICollectionViewDelegateFlowLayout { if scrollView.contentOffset.y > 100 { self.scrollToBottomContainerView.isHidden = false } else { + if room!.isReadOnly { + scrollToBottomContainerViewConstraint.constant = -40 + } self.scrollToBottomContainerView.isHidden = true } } @@ -1637,7 +1680,14 @@ extension IGMessageViewController: IGMessageGeneralCollectionViewCellDelegate { self.performSegue(withIdentifier: "showForwardMessageTable", sender: self) }) let edit = UIAlertAction(title: "Edit", style: .default, handler: { (action) in + if self.connectionStatus == .waitingForNetwork || self.connectionStatus == .connecting { + let alert = UIAlertController(title: "Error", message: "No Network Connection", preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) + alert.addAction(okAction) + self.present(alert, animated: true, completion: nil) + }else { self.editMessage(cellMessage) + } }) let more = UIAlertAction(title: "More", style: .default, handler: { (action) in for visibleCell in self.collectionView.visibleCells { diff --git a/iGap/Libraries/Chat Screen/View/IGMessageCollectionViewCell.swift b/iGap/Libraries/Chat Screen/View/IGMessageCollectionViewCell.swift index 68edaf7..303b31c 100644 --- a/iGap/Libraries/Chat Screen/View/IGMessageCollectionViewCell.swift +++ b/iGap/Libraries/Chat Screen/View/IGMessageCollectionViewCell.swift @@ -575,7 +575,7 @@ class IGMessageCollectionViewCell: IGMessageGeneralCollectionViewCell { self.forwardedMessageMediaImageView.prepareForAnimation(withGIFData: data) self.forwardedMessageMediaImageView.startAnimatingGIF() } else { - //auto download + self.downloadUploadIndicatorDidTapOnStart(self.forwardedMediaDownloadUploadIndicatorView) } } @@ -1037,6 +1037,20 @@ class IGMessageCollectionViewCell: IGMessageGeneralCollectionViewCell { func setThumbnailForForwardedAttachments() { + if let attachment = self.forwardedAttachment { + self.attachmentThumbnailImageView.isHidden = false + if attachment.type == .voice { + self.attachmentThumbnailImageView.image = UIImage(named: "IG_Message_Cell_Voice") + } else { + switch attachment.fileTypeBasedOnNameExtension { + case .docx: + self.attachmentThumbnailImageView.image = UIImage(named: "IG_Message_Cell_File_Doc") + default: + self.attachmentThumbnailImageView.image = UIImage(named: "IG_Message_Cell_File_Generic") + } + } + } + } } @@ -1054,6 +1068,14 @@ extension IGMessageCollectionViewCell: IGDownloadUploadIndicatorViewDelegate { }) } + if let forwardAttachment = self.forwardedAttachment { + IGDownloadManager.sharedManager.download(file: forwardAttachment, previewType: .originalFile, completion: { + + }, failure: { + + }) + + } } func downloadUploadIndicatorDidTapOnCancel(_ indicator: IGDownloadUploadIndicatorView) { diff --git a/iGap/Model/AppDelegate/AppDelegate.swift b/iGap/Model/AppDelegate/AppDelegate.swift index bea8a19..735a8d7 100644 --- a/iGap/Model/AppDelegate/AppDelegate.swift +++ b/iGap/Model/AppDelegate/AppDelegate.swift @@ -63,7 +63,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate { return true } - + + func applicationWillResignActive(_ application: UIApplication) { } diff --git a/iGap/Model/Factories/IGFactory.swift b/iGap/Model/Factories/IGFactory.swift index 7958194..c1415a7 100644 --- a/iGap/Model/Factories/IGFactory.swift +++ b/iGap/Model/Factories/IGFactory.swift @@ -24,7 +24,7 @@ fileprivate class IGFactoryTask: NSObject { var error: (()->())? var status: Status = .pending var randomID: String = "" - + var isUpdateStatusRunning : Bool = false override init() { self.task = {} self.randomID = IGGlobal.randomString(length: 64) @@ -726,6 +726,7 @@ class IGFactory: NSObject { //MARK: -------------------------------------------------------- //MARK: ▶︎▶︎ User func updateUserStatus(_ userId: Int64, status: IGRegisteredUser.IGLastSeenStatus) { + print ("◉ Executing Task: " + #function) let task = IGFactoryTask() task.task = { @@ -1135,6 +1136,46 @@ class IGFactory: NSObject { self.performNextFactoryTaskIfPossible() } + func updateUserInfoExpired(_ userId: Int64) { + let task = IGFactoryTask() + task.task = { + IGFactoryTask(dependencyUserTask: userId, cacheID: nil).success { + IGDatabaseManager.shared.perfrmOnDatabaseThread { + print ("◉ Executing Task: " + #function) + let predicate = NSPredicate(format: "id = %lld", userId) + if let userInDb = try! Realm().objects(IGRegisteredUser.self).filter(predicate).first { + try! IGDatabaseManager.shared.realm.write { + if userInDb.lastSeenStatus == .online { + self.updateUserStatus(userId, status: .longTimeAgo) + } else if userInDb.lastSeenStatus == .longTimeAgo { + self.updateUserStatus(userId, status: .online) + + } + NotificationCenter.default.post(name: NSNotification.Name(rawValue: kIGNoticationForPushUserExpire), + object: nil, + userInfo: ["user": userId]) + + + } + } + + IGFactory.shared.performInFactoryQueue { + task.success!() + } + } + }.error { + task.error!() + }.execute() + } + task.success { + self.removeTaskFromQueueAndPerformNext(task) + }.error { + self.removeTaskFromQueueAndPerformNext(task) + }.addToQueue() //.addAsHighPriorityToQueue() + self.performNextFactoryTaskIfPossible() + + } + func saveBlockedUsers(_ blockedUsers : [IGPUserContactsGetBlockedListResponse.IGPUser]){ for blockedUser in blockedUsers { let task = IGFactoryTask() @@ -1347,7 +1388,7 @@ class IGFactory: NSObject { let predicate = NSPredicate(format: "id = %lld", userId) if let userInDb = IGDatabaseManager.shared.realm.objects(IGRegisteredUser.self).filter(predicate).first { try! IGDatabaseManager.shared.realm.write { - userInDb.avatar = avatar + // userInDb.avatar = avatar } } IGFactory.shared.performInFactoryQueue { diff --git a/iGap/Model/Managers/IGAppManager.swift b/iGap/Model/Managers/IGAppManager.swift index e3cd4d5..f2327be 100644 --- a/iGap/Model/Managers/IGAppManager.swift +++ b/iGap/Model/Managers/IGAppManager.swift @@ -96,14 +96,11 @@ class IGAppManager: NSObject { public func setUserLoginSuccessful() { isUserLoggedIn.value = true NotificationCenter.default.post(name: NSNotification.Name(rawValue: kIGUserLoggedInNotificationName), object: nil) - // self.setUserUpdateStatus(status: .online) - //IGContactManager.sharedManager.sendContactsToServer() - //IGContactManager.sharedManager.getContactListFromServer() + } public func isUserLoggiedIn() -> Bool { if isUserLoggedIn.value == true { - self.setUserUpdateStatus(status: .online) } return isUserLoggedIn.value } diff --git a/iGap/Model/Managers/Request Manager/IGRequestManager.swift b/iGap/Model/Managers/Request Manager/IGRequestManager.swift index 3ca5f0e..8921dd7 100644 --- a/iGap/Model/Managers/Request Manager/IGRequestManager.swift +++ b/iGap/Model/Managers/Request Manager/IGRequestManager.swift @@ -49,6 +49,8 @@ let protoClassesLookupTable: [Int: (proto: GeneratedMessageProtocol.Type, repons IGUserProfileGetNicknameRequest.Handler.self as IGRequest.Handler.Type), 30114: (IGPUserAvatarAddResponse.self as GeneratedMessageProtocol.Type, IGUserAvatarAddRequest.Handler.self as IGRequest.Handler.Type), + 30116: (IGPUserAvatarGetListResponse.self as GeneratedMessageProtocol.Type, + IGUserAvatarGetListRequest.Handler.self as IGRequest.Handler.Type), 30117: (IGPUserInfoResponse.self as GeneratedMessageProtocol.Type, IGUserInfoRequest.Handler.self as IGRequest.Handler.Type), 30118: (IGPUserGetDeleteTokenResponse.self as GeneratedMessageProtocol.Type, @@ -82,6 +84,7 @@ let protoClassesLookupTable: [Int: (proto: GeneratedMessageProtocol.Type, repons 30144: (IGPUserPrivacySetRuleResponse.self as GeneratedMessageProtocol.Type, IGUserPrivacySetRuleRequest.Handler.self as IGRequest.Handler.Type), + //Chat: 302xx 30200: (IGPChatGetRoomResponse.self as GeneratedMessageProtocol.Type, IGChatGetRoomRequest.Handler.self as IGRequest.Handler.Type), @@ -229,7 +232,8 @@ let protoClassesLookupTable: [Int: (proto: GeneratedMessageProtocol.Type, repons IGClientJoinByInviteLinkRequest.Handler.self as IGRequest.Handler.Type), 30609: (IGPClientJoinByUsernameResponse.self as GeneratedMessageProtocol.Type, IGClientJoinByUsernameRequest.Handler.self as IGRequest.Handler.Type), - + 30613: (IGPClientCountRoomHistoryResponse.self as GeneratedMessageProtocol.Type, + IGClientCountRoomHistoryRequest.Handler.self as IGRequest.Handler.Type), //File: 307xx 30700: (IGPFileUploadOptionResponse.self as GeneratedMessageProtocol.Type, @@ -245,6 +249,10 @@ let protoClassesLookupTable: [Int: (proto: GeneratedMessageProtocol.Type, repons 30705: (IGPFileDownloadResponse.self as GeneratedMessageProtocol.Type, IGFileDownloadRequest.Handler.self as IGRequest.Handler.Type), + //Push: 600xx + 60002: (IGPPushUserInfoExpiredResponse.self as GeneratedMessageProtocol.Type, + IGPushUserInfoExpiredRequest.Handler.self as IGRequest.Handler.Type) + ] //login is not required for these methods diff --git a/iGap/Model/Objects/IGMedia.swift b/iGap/Model/Objects/IGMedia.swift index 11bfa19..bc29cc5 100644 --- a/iGap/Model/Objects/IGMedia.swift +++ b/iGap/Model/Objects/IGMedia.swift @@ -23,6 +23,7 @@ class IGMedia: INSPhotoViewable, Equatable { var attributedTitle: NSAttributedString? var file: IGFile? + init(message: IGRoomMessage, forwardedMedia: Bool) { if let attachment = forwardedMedia ? message.forwardedFrom?.attachment : message.attachment { file = attachment @@ -31,6 +32,7 @@ class IGMedia: INSPhotoViewable, Equatable { if let text = message.message { attributedTitle = NSAttributedString(string: text) } + } } diff --git a/iGap/Model/Objects/Requests/IGPushResponse.swift b/iGap/Model/Objects/Requests/IGPushResponse.swift new file mode 100644 index 0000000..de4c63c --- /dev/null +++ b/iGap/Model/Objects/Requests/IGPushResponse.swift @@ -0,0 +1,40 @@ +// +// IGPushResponse.swift +// iGap +// +// Created by PC on 5/3/17. +// Copyright © 2017 RooyeKhat Media. All rights reserved. +// + +import Foundation +import IGProtoBuff +import ProtocolBuffers + + +class IGPushUserInfoExpiredRequest : IGRequest { + class Generator: IGRequest.Generator { + class func generate() { + + } + } + + class Handler : IGRequest.Handler { + class func interpret( response responseProtoMessage: IGPPushUserInfoExpiredResponse) { + let userID = responseProtoMessage.igpUserId + IGFactory.shared.updateUserInfoExpired(userID) + + } + + override class func handlePush(responseProtoMessage:GeneratedResponseMessage) { + switch responseProtoMessage { + case let pushUserInfoExpireResponse as IGPPushUserInfoExpiredResponse: + self.interpret(response: pushUserInfoExpireResponse) + break + default: + break + } + + } + } +} + diff --git a/iGap/Model/Objects/Requests/IGRequestClient.swift b/iGap/Model/Objects/Requests/IGRequestClient.swift index 36f377e..cf83c06 100644 --- a/iGap/Model/Objects/Requests/IGRequestClient.swift +++ b/iGap/Model/Objects/Requests/IGRequestClient.swift @@ -109,7 +109,7 @@ class IGClientGetRoomHistoryRequest : IGRequest { class Handler : IGRequest.Handler{ class func interpret(response responseProtoMessage:IGPClientGetRoomHistoryResponse, roomId: Int64) { //-> [IGRoomMessage]{ - IGFactory.shared.saveIgpMessagesToDatabase(responseProtoMessage.igpMessage, for: roomId, updateLastMessage: false , isFromSharedMedia: true) + IGFactory.shared.saveIgpMessagesToDatabase(responseProtoMessage.igpMessage, for: roomId, updateLastMessage: false , isFromSharedMedia: false) // var messages = [IGRoomMessage]() // for igpMessage in responseProtoMessage.igpMessage { @@ -257,3 +257,33 @@ class IGClientJoinByUsernameRequest: IGRequest { } } +class IGClientCountRoomHistoryRequest: IGRequest { + class Generator: IGRequest.Generator { + class func generate(roomID: Int64) -> IGRequestWrapper { + let clientCountRoomHistoryRequestBuilder = IGPClientCountRoomHistory.Builder() + clientCountRoomHistoryRequestBuilder.setIgpRoomId(roomID) + return IGRequestWrapper(messageBuilder: clientCountRoomHistoryRequestBuilder, actionID: 613) + + } + } + class Handler: IGRequest.Handler { + class func interpret( response responseProtoMessage : IGPClientCountRoomHistoryResponse) -> (media: Int32 , image: Int32 , video: Int32 , gif: Int32 , voice: Int32 , file: Int32 , audio: Int32, url: Int32 ) { + let mediaCount = responseProtoMessage.igpMedia + let imageCount = responseProtoMessage.igpImage + let videoCount = responseProtoMessage.igpVideo + let audioCount = responseProtoMessage.igpAudio + let voiceCount = responseProtoMessage.igpVoice + let gifCount = responseProtoMessage.igpGif + let fileCount = responseProtoMessage.igpFile + let urlCount = responseProtoMessage.igpUrl + + return (media: mediaCount , image: imageCount , video: videoCount , gif: gifCount , voice: voiceCount , file: fileCount , audio: audioCount, url: urlCount ) + + + } + override class func handlePush(responseProtoMessage: GeneratedResponseMessage) {} + } + +} + + diff --git a/iGap/Model/Objects/Requests/IGRequestFile.swift b/iGap/Model/Objects/Requests/IGRequestFile.swift index b04fd2f..592cf8d 100644 --- a/iGap/Model/Objects/Requests/IGRequestFile.swift +++ b/iGap/Model/Objects/Requests/IGRequestFile.swift @@ -118,6 +118,8 @@ class IGFileUploadStatusRequest : IGRequest { status = .processing case .processed: status = .processed + default: + status = .unknown } } else { status = .unknown diff --git a/iGap/Model/Objects/Requests/IGRequestUser.swift b/iGap/Model/Objects/Requests/IGRequestUser.swift index f6375a2..ad8698c 100644 --- a/iGap/Model/Objects/Requests/IGRequestUser.swift +++ b/iGap/Model/Objects/Requests/IGRequestUser.swift @@ -436,10 +436,26 @@ class IGUserAvatarDeleteRequest : IGRequest { //MARK: - class IGUserAvatarGetListRequest : IGRequest { class Generator : IGRequest.Generator{ + class func generate(userId: Int64) -> IGRequestWrapper { + let userAvatarGetListRequestBuilder = IGPUserAvatarGetList.Builder() + userAvatarGetListRequestBuilder.setIgpUserId(userId) + return IGRequestWrapper(messageBuilder: userAvatarGetListRequestBuilder, actionID: 116) + } } - class Handler : IGRequest.Handler{ + class Handler : IGRequest.Handler { + class func interpret(response responseProtoMessage:IGPUserAvatarGetListResponse , userId: Int64) -> Array { + let igpAvatars = responseProtoMessage.igpAvatar + var igAvatars : Array = [] + for igpAvatar in igpAvatars { +// IGFactory.shared.updateUserAvatar(userId, igpAvatar: igpAvatar) + let igavatar = IGAvatar(igpAvatar: igpAvatar) + igAvatars.append(igavatar) + } + return igAvatars + + } override class func handlePush(responseProtoMessage: GeneratedResponseMessage) {} override class func error() {} override class func timeout() {} @@ -453,10 +469,12 @@ class IGUserInfoRequest : IGRequest { let userInfoRequestBuilder = IGPUserInfo.Builder() userInfoRequestBuilder.setIgpUserId(userID) return IGRequestWrapper(messageBuilder: userInfoRequestBuilder, actionID: 117) + } } class Handler : IGRequest.Handler{ + override class func handlePush(responseProtoMessage: GeneratedResponseMessage) {} override class func error() {} override class func timeout() {} diff --git a/iGap/Supporting FIles/Info.plist b/iGap/Supporting FIles/Info.plist index 05b2e39..737f719 100644 --- a/iGap/Supporting FIles/Info.plist +++ b/iGap/Supporting FIles/Info.plist @@ -15,9 +15,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.0.9 + 0.0.10 CFBundleVersion - 297 + 300 Fabric APIKey @@ -32,8 +32,15 @@ + LSApplicationCategoryType + LSRequiresIPhoneOS + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + NSCameraUsageDescription iGap needs to access your camera NSContactsUsageDescription diff --git a/iGap/VIew/Assets.xcassets/Settings/IG_Trash_avatar.imageset/Contents.json b/iGap/VIew/Assets.xcassets/Settings/IG_Trash_avatar.imageset/Contents.json new file mode 100644 index 0000000..007f219 --- /dev/null +++ b/iGap/VIew/Assets.xcassets/Settings/IG_Trash_avatar.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "Trash-50.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "Trash_100.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "Trash-150.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/iGap/VIew/Assets.xcassets/Settings/IG_Trash_avatar.imageset/Trash-150.png b/iGap/VIew/Assets.xcassets/Settings/IG_Trash_avatar.imageset/Trash-150.png new file mode 100644 index 0000000..3b9c3ee Binary files /dev/null and b/iGap/VIew/Assets.xcassets/Settings/IG_Trash_avatar.imageset/Trash-150.png differ diff --git a/iGap/VIew/Assets.xcassets/Settings/IG_Trash_avatar.imageset/Trash-50.png b/iGap/VIew/Assets.xcassets/Settings/IG_Trash_avatar.imageset/Trash-50.png new file mode 100644 index 0000000..f1e1073 Binary files /dev/null and b/iGap/VIew/Assets.xcassets/Settings/IG_Trash_avatar.imageset/Trash-50.png differ diff --git a/iGap/VIew/Assets.xcassets/Settings/IG_Trash_avatar.imageset/Trash_100.png b/iGap/VIew/Assets.xcassets/Settings/IG_Trash_avatar.imageset/Trash_100.png new file mode 100644 index 0000000..67c1ba1 Binary files /dev/null and b/iGap/VIew/Assets.xcassets/Settings/IG_Trash_avatar.imageset/Trash_100.png differ diff --git a/iGap/VIew/Base.lproj/Main.storyboard b/iGap/VIew/Base.lproj/Main.storyboard index b6dea9e..240bb14 100644 --- a/iGap/VIew/Base.lproj/Main.storyboard +++ b/iGap/VIew/Base.lproj/Main.storyboard @@ -972,6 +972,7 @@ Please wait 0:59 + @@ -4376,10 +4377,6 @@ with iGap right now - - - - @@ -4410,10 +4407,6 @@ with iGap right now - - - - @@ -4444,10 +4437,6 @@ with iGap right now - - - - @@ -4478,10 +4467,6 @@ with iGap right now - - - - @@ -4512,10 +4497,6 @@ with iGap right now - - - - @@ -4546,10 +4527,6 @@ with iGap right now - - - - @@ -4571,18 +4548,12 @@ with iGap right now - - - - - - @@ -4719,10 +4690,10 @@ with iGap right now + - @@ -4850,9 +4821,9 @@ with iGap right now - + - + @@ -4878,12 +4849,12 @@ with iGap right now - + - + @@ -4953,10 +4924,10 @@ with iGap right now + + - - diff --git a/iGap/VIew/IGChannelAndGroupSharedMediaAudioAndLinkTableViewController.swift b/iGap/VIew/IGChannelAndGroupSharedMediaAudioAndLinkTableViewController.swift index 751a63e..d56720a 100644 --- a/iGap/VIew/IGChannelAndGroupSharedMediaAudioAndLinkTableViewController.swift +++ b/iGap/VIew/IGChannelAndGroupSharedMediaAudioAndLinkTableViewController.swift @@ -36,6 +36,9 @@ class IGChannelAndGroupSharedMediaAudioAndLinkTableViewController: UITableViewCo navigationController.interactivePopGestureRecognizer?.delegate = self } + override func viewDidAppear(_ animated: Bool) { + self.tableView.isUserInteractionEnabled = true + } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() @@ -119,6 +122,7 @@ class IGChannelAndGroupSharedMediaAudioAndLinkTableViewController: UITableViewCo } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + self.tableView.isUserInteractionEnabled = false if sharedMedia[indexPath.row].type == .voice { let musicPlayer = IGMusicViewController() musicPlayer.attachment = sharedMedia[indexPath.row].attachment diff --git a/iGap/VIew/IGSettingStoryboard.storyboard b/iGap/VIew/IGSettingStoryboard.storyboard index 636806c..5ab96d0 100644 --- a/iGap/VIew/IGSettingStoryboard.storyboard +++ b/iGap/VIew/IGSettingStoryboard.storyboard @@ -160,7 +160,7 @@ - + @@ -191,7 +191,7 @@ - + @@ -1158,7 +1158,7 @@ To proceed, confirm that your new number can recieve SMS or calls and tap Next t - + @@ -2192,8 +2192,8 @@ To proceed, confirm that your new number can recieve SMS or calls and tap Next t -