can deleteFeed when unsubscribe if user is feed's creator

This commit is contained in:
nixzhu
2015-10-29 17:52:53 +08:00
parent 0fcf722b73
commit 890982c06f
3 changed files with 60 additions and 37 deletions
+2 -8
View File
@@ -1118,7 +1118,7 @@ func deleteConversation(conversation: Conversation, inRealm realm: Realm, needLe
}
}
func tryDeleteOrClearHistoryOfConversation(conversation: Conversation, inViewController vc: UIViewController?, whenAfterClearedHistory afterClearedHistory: () -> Void, afterDeleted: () -> Void, orCanceled cancelled: () -> Void) {
func tryDeleteOrClearHistoryOfConversation(conversation: Conversation, inViewController vc: UIViewController, whenAfterClearedHistory afterClearedHistory: () -> Void, afterDeleted: () -> Void, orCanceled cancelled: () -> Void) {
guard let realm = conversation.realm else {
cancelled()
@@ -1159,12 +1159,6 @@ func tryDeleteOrClearHistoryOfConversation(conversation: Conversation, inViewCon
}
deleteAlertController.addAction(cancelAction)
if let vc = vc {
vc.presentViewController(deleteAlertController, animated: true, completion: nil)
} else {
delete()
afterDeleted()
}
vc.presentViewController(deleteAlertController, animated: true, completion: nil)
}
+15
View File
@@ -2475,6 +2475,21 @@ func createFeedWithMessage(message: String, attachments: JSONDictionary?, coordi
}
}
func deleteFeedWithFeedID(feedID: String, failureHandler: ((Reason, String?) -> Void)?, completion: () -> Void) {
let parse: JSONDictionary -> ()? = { data in
return
}
let resource = authJsonResource(path: "/api/v1/topics/\(feedID)", method: .DELETE, requestParameters: [:], parse: parse)
if let failureHandler = failureHandler {
apiRequest({_ in}, baseURL: baseURL, resource: resource, failure: failureHandler, completion: completion)
} else {
apiRequest({_ in}, baseURL: baseURL, resource: resource, failure: defaultFailureHandler, completion: completion)
}
}
// MARK: - Social Work
func authURLRequestWithURL(url: NSURL) -> NSURLRequest {
@@ -1558,39 +1558,53 @@ class ConversationViewController: BaseViewController {
moreView.unsubscribeAction = { [weak self] in
dispatch_async(dispatch_get_main_queue()) { [weak self] in
if let checkTypingStatusTimer = self?.checkTypingStatusTimer {
checkTypingStatusTimer.invalidate()
}
guard let conversation = self?.conversation else {
return
}
tryDeleteOrClearHistoryOfConversation(conversation, inViewController: nil, whenAfterClearedHistory: {
dispatch_async(dispatch_get_main_queue()) {
NSNotificationCenter.defaultCenter().postNotificationName(YepConfig.Notification.changedConversation, object: nil)
}
}, afterDeleted: {
dispatch_async(dispatch_get_main_queue()) {
NSNotificationCenter.defaultCenter().postNotificationName(YepConfig.Notification.changedConversation, object: nil)
}
}, orCanceled: {
let doDeleteConversation: () -> Void = {
})
self?.navigationController?.popViewControllerAnimated(true)
dispatch_async(dispatch_get_main_queue()) { [weak self] in
if let checkTypingStatusTimer = self?.checkTypingStatusTimer {
checkTypingStatusTimer.invalidate()
}
guard let conversation = self?.conversation, realm = conversation.realm else {
return
}
deleteConversation(conversation, inRealm: realm)
NSNotificationCenter.defaultCenter().postNotificationName(YepConfig.Notification.changedConversation, object: nil)
self?.navigationController?.popViewControllerAnimated(true)
}
}
guard let feed = self?.conversation.withGroup?.withFeed, feedCreator = feed.creator else {
return
}
let feedID = feed.feedID
let feedCreatorID = feedCreator.userID
// Feed
if feedCreatorID == YepUserDefaults.userID.value {
YepAlert.confirmOrCancel(title: NSLocalizedString("Delete", comment: ""), message: NSLocalizedString("Also delete this feed?", comment: ""), confirmTitle: NSLocalizedString("Delete", comment: ""), cancelTitle: NSLocalizedString("Not now", comment: ""), inViewController: self, withConfirmAction: {
doDeleteConversation()
deleteFeedWithFeedID(feedID, failureHandler: nil, completion: {
println("deleted feed: \(feedID)")
})
}, cancelAction: {
doDeleteConversation()
})
} else {
doDeleteConversation()
}
}
moreView.shareAction = { [weak self] in
guard let groupID = groupID, descriotion = descriotion else {