From c95b10963eaf5a1d3603c599fa0053fadcc78808 Mon Sep 17 00:00:00 2001 From: Saeed Mozaffari iOS Date: Wed, 27 Dec 2017 18:02:43 +0330 Subject: [PATCH] Improvement delete avatar - need change later --- .../IGChannelInfoTableViewController.swift | 40 +++++++++++++++++++ .../IGGroupInfoTableViewController.swift | 39 ++++++++++++++++++ iGap/Supporting FIles/Info.plist | 2 +- 3 files changed, 80 insertions(+), 1 deletion(-) 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 eb8a538..cfb677b 100644 --- a/iGap/Controller/View Controllers/Channel and Group Info/IGChannelInfoTableViewController.swift +++ b/iGap/Controller/View Controllers/Channel and Group Info/IGChannelInfoTableViewController.swift @@ -426,6 +426,12 @@ class IGChannelInfoTableViewController: UITableViewController , UIGestureRecogni } } }) + + let deleteAction = UIAlertAction(title: "Delete Main Avatar", style: .destructive, handler: { + (alert: UIAlertAction!) -> Void in + self.deleteAvatar() + }) + let ChoosePhoto = UIAlertAction(title: "Choose Photo", style: .default, handler: { (alert: UIAlertAction!) -> Void in print("Choose Photo") @@ -446,6 +452,9 @@ class IGChannelInfoTableViewController: UITableViewController , UIGestureRecogni (alert: UIAlertAction!) -> Void in print("Cancelled") }) + if myRole == .owner || myRole == .admin { + optionMenu.addAction(deleteAction) + } optionMenu.addAction(ChoosePhoto) optionMenu.addAction(cancelAction) if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) == true { @@ -458,6 +467,37 @@ class IGChannelInfoTableViewController: UITableViewController , UIGestureRecogni self.present(optionMenu, animated: true, completion: nil) } + /* + * this method will be deleted main(latest) avatar + */ + func deleteAvatar(){ + let avatar = self.avatars[0] + IGChannelAvatarDeleteRequest.Generator.generate(avatarId: avatar.id, roomId: (room?.id)!).success({ (protoResponse) in + DispatchQueue.main.async { + switch protoResponse { + case let channelAvatarDeleteResponse as IGPChannelAvatarDeleteResponse : + IGChannelAvatarDeleteRequest.Handler.interpret(response: channelAvatarDeleteResponse) + self.avatarPhotos?.remove(at: 0) + self.avatars.remove(at: 0) + 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() + } // MARK: - Table view data source 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 b25bf6c..c57a21f 100644 --- a/iGap/Controller/View Controllers/Channel and Group Info/IGGroupInfoTableViewController.swift +++ b/iGap/Controller/View Controllers/Channel and Group Info/IGGroupInfoTableViewController.swift @@ -178,6 +178,12 @@ class IGGroupInfoTableViewController: UITableViewController , UIGestureRecognize } } }) + + let deleteAction = UIAlertAction(title: "Delete Main Avatar", style: .destructive, handler: { + (alert: UIAlertAction!) -> Void in + self.deleteAvatar() + }) + let ChoosePhoto = UIAlertAction(title: "Choose Photo", style: .default, handler: { (alert: UIAlertAction!) -> Void in print("Choose Photo") @@ -198,6 +204,10 @@ class IGGroupInfoTableViewController: UITableViewController , UIGestureRecognize (alert: UIAlertAction!) -> Void in print("Cancelled") }) + + if myRole == .owner || myRole == .admin { + optionMenu.addAction(deleteAction) + } optionMenu.addAction(ChoosePhoto) optionMenu.addAction(cancelAction) if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) == true { @@ -210,6 +220,35 @@ class IGGroupInfoTableViewController: UITableViewController , UIGestureRecognize self.present(optionMenu, animated: true, completion: nil) } + + func deleteAvatar(){ + let avatar = self.avatars[0] + IGGroupAvatarDeleteRequest.Generator.generate(avatarId: avatar.id, roomId: (room?.id)!).success({ (protoResponse) in + DispatchQueue.main.async { + switch protoResponse { + case let groupAvatarDeleteResponse as IGPGroupAvatarDeleteResponse : + IGGroupAvatarDeleteRequest.Handler.interpret(response: groupAvatarDeleteResponse) + self.avatarPhotos?.remove(at: 0) + self.avatars.remove(at: 0) + 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() + } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() diff --git a/iGap/Supporting FIles/Info.plist b/iGap/Supporting FIles/Info.plist index 71fd590..0a2cf7c 100644 --- a/iGap/Supporting FIles/Info.plist +++ b/iGap/Supporting FIles/Info.plist @@ -17,7 +17,7 @@ CFBundleShortVersionString 0.1.1 CFBundleVersion - 436 + 437 Fabric APIKey