From 59f129da8145f5ac172b59dc67cd4ef16c827648 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 24 Jun 2015 14:44:56 +0800 Subject: [PATCH] reportAction --- .../ConversationViewController.swift | 60 +++++++++++++++++++ .../ConversationMoreView.swift | 11 ++++ 2 files changed, 71 insertions(+) diff --git a/Yep/ViewControllers/Conversation/ConversationViewController.swift b/Yep/ViewControllers/Conversation/ConversationViewController.swift index 9745e725..b5a5fbd0 100644 --- a/Yep/ViewControllers/Conversation/ConversationViewController.swift +++ b/Yep/ViewControllers/Conversation/ConversationViewController.swift @@ -914,11 +914,71 @@ class ConversationViewController: BaseViewController { moreView.removeFromSuperview() } + moreView.reportAction = { + self.report() + moreView.removeFromSuperview() + } + moreView.frame = view.bounds view.window?.addSubview(moreView) } + func report() { + let reportWithReason: ReportReason -> Void = { [unowned self] reason in + + if let user = self.conversation.withFriend { + let profileUser = ProfileUser.UserType(user) + + reportProfileUser(profileUser, forReason: reason, failureHandler: { (reason, errorMessage) in + defaultFailureHandler(reason, errorMessage) + + if let errorMessage = errorMessage { + dispatch_async(dispatch_get_main_queue()) { + YepAlert.alertSorry(message: errorMessage, inViewController: self) + } + } + + }, completion: { success in + dispatch_async(dispatch_get_main_queue()) { + YepAlert.alert(title: NSLocalizedString("Success", comment: ""), message: NSLocalizedString("Report recorded!", comment: ""), dismissTitle: NSLocalizedString("OK", comment: ""), inViewController: self, withDismissAction: nil) + } + }) + } + } + + let reportAlertController = UIAlertController(title: NSLocalizedString("Report Reason", comment: ""), message: nil, preferredStyle: .ActionSheet) + + let pornoReasonAction: UIAlertAction = UIAlertAction(title: ReportReason.Porno.description, style: .Default) { action -> Void in + reportWithReason(.Porno) + } + reportAlertController.addAction(pornoReasonAction) + + let advertisingReasonAction: UIAlertAction = UIAlertAction(title: ReportReason.Advertising.description, style: .Default) { action -> Void in + reportWithReason(.Advertising) + } + reportAlertController.addAction(advertisingReasonAction) + + let scamsReasonAction: UIAlertAction = UIAlertAction(title: ReportReason.Scams.description, style: .Default) { action -> Void in + reportWithReason(.Scams) + } + reportAlertController.addAction(scamsReasonAction) + + let otherReasonAction: UIAlertAction = UIAlertAction(title: ReportReason.Other("").description, style: .Default) { action -> Void in + YepAlert.textInput(title: NSLocalizedString("Other Reason", comment: ""), placeholder: nil, oldText: nil, confirmTitle: NSLocalizedString("OK", comment: ""), cancelTitle: NSLocalizedString("Cancel", comment: ""), inViewController: self, withConfirmAction: { text in + reportWithReason(.Other(text)) + }, cancelAction: nil) + } + reportAlertController.addAction(otherReasonAction) + + let cancelAction: UIAlertAction = UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .Cancel) { action -> Void in + self.dismissViewControllerAnimated(true, completion: nil) + } + reportAlertController.addAction(cancelAction) + + self.presentViewController(reportAlertController, animated: true, completion: nil) + } + /* func showProfile() { performSegueWithIdentifier("showProfile", sender: nil) diff --git a/Yep/Views/ConversationMore/ConversationMoreView.swift b/Yep/Views/ConversationMore/ConversationMoreView.swift index 923914d2..11933a4c 100644 --- a/Yep/Views/ConversationMore/ConversationMoreView.swift +++ b/Yep/Views/ConversationMore/ConversationMoreView.swift @@ -133,6 +133,8 @@ class ConversationMoreView: UIView { var showProfileAction: (() -> Void)? + var reportAction: (() -> Void)? + override func didMoveToSuperview() { super.didMoveToSuperview() @@ -258,6 +260,15 @@ extension ConversationMoreView: UITableViewDataSource, UITableViewDelegate { case .ShowProfile: showProfileAction?() + case .Report: + reportAction?() + + case .Block: + break + + case .Cancel: + removeFromSuperview() + default: break }