From ccfd59212e07cfa3b8b5a06bb25ac47d37827f4e Mon Sep 17 00:00:00 2001 From: nixzhu Date: Sat, 21 Nov 2015 09:52:11 +0800 Subject: [PATCH] createFeedWithKind GithubRepo --- Yep/Services/YepService.swift | 6 +-- .../NewFeed/NewFeedViewController.swift | 40 ++++++++++++++----- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/Yep/Services/YepService.swift b/Yep/Services/YepService.swift index 3ba59a5f..6ed63354 100644 --- a/Yep/Services/YepService.swift +++ b/Yep/Services/YepService.swift @@ -2733,7 +2733,7 @@ enum FeedKind: String { //case InstagramMedia = "instagram" } -func createFeedWithKind(kind: FeedKind, message: String, attachments: JSONDictionary?, sharedStuff: JSONDictionary?, coordinate: CLLocationCoordinate2D?, skill: Skill?, allowComment: Bool, failureHandler: ((Reason, String?) -> Void)?, completion: JSONDictionary -> Void) { +func createFeedWithKind(kind: FeedKind, message: String, attachments: JSONDictionary?, coordinate: CLLocationCoordinate2D?, skill: Skill?, allowComment: Bool, failureHandler: ((Reason, String?) -> Void)?, completion: JSONDictionary -> Void) { var requestParameters: JSONDictionary = [ "kind": kind.rawValue, @@ -2756,10 +2756,6 @@ func createFeedWithKind(kind: FeedKind, message: String, attachments: JSONDictio requestParameters["attachments"] = attachments } - if let sharedStuff = sharedStuff { - requestParameters["shared_stuff"] = sharedStuff - } - let parse: JSONDictionary -> JSONDictionary? = { data in return data } diff --git a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift index c9d98422..2575f971 100644 --- a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift +++ b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift @@ -380,13 +380,6 @@ class NewFeedViewController: UIViewController { func post(sender: UIBarButtonItem) { - guard socialWork == nil else { - - YepAlert.alertSorry(message: "Can NOT post Feed with Social Work yet.", inViewController: self) - - return - } - messageTextView.resignFirstResponder() let messageLength = (messageTextView.text as NSString).length @@ -486,9 +479,38 @@ class NewFeedViewController: UIViewController { } - let kind: FeedKind = uploadImageInfos.isEmpty ? . Text : .Image + var kind: FeedKind = uploadImageInfos.isEmpty ? .Text : .Image - createFeedWithKind(kind, message: message, attachments: mediaInfo, sharedStuff: nil, coordinate: coordinate, skill: self?.pickedSkill, allowComment: true, failureHandler: { [weak self] reason, errorMessage in + if let socialWork = self?.socialWork { + + guard let type = MessageSocialWorkType(rawValue: socialWork.type) else { + return + } + + switch type { + + case .GithubRepo: + guard let githubRepo = socialWork.githubRepo else { + break + } + + mediaInfo = [ + "github": [[ + "name": githubRepo.name, + "full_name": githubRepo.fullName, + "description": githubRepo.repoDescription, + "url": githubRepo.URLString, + ]] + ] + + kind = .GithubRepo + + default: + break + } + } + + createFeedWithKind(kind, message: message, attachments: mediaInfo, coordinate: coordinate, skill: self?.pickedSkill, allowComment: true, failureHandler: { [weak self] reason, errorMessage in defaultFailureHandler(reason, errorMessage: errorMessage) YepAlert.alertSorry(message: errorMessage ?? NSLocalizedString("Create feed failed!", comment: ""), inViewController: self)