reportAction

This commit is contained in:
nixzhu
2015-06-24 14:44:56 +08:00
parent 9ee7f6dbdb
commit 59f129da81
2 changed files with 71 additions and 0 deletions
@@ -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)
@@ -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
}