mirror of
https://github.com/wahyd4/Yep.git
synced 2026-08-09 21:05:53 +10:00
can deleteFeed when unsubscribe if user is feed's creator
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user