new FeedKind; attachments optional in feedInfo

This commit is contained in:
nixzhu
2015-11-21 09:07:32 +08:00
parent 38691408c6
commit 6c7a97202f
3 changed files with 14 additions and 18 deletions
+7 -3
View File
@@ -2587,7 +2587,6 @@ struct DiscoveredFeed: Hashable {
updatedUnixTime = feedInfo["updated_at"] as? NSTimeInterval,
creatorInfo = feedInfo["user"] as? JSONDictionary,
body = feedInfo["body"] as? String,
attachmentsData = feedInfo["attachments"] as? [JSONDictionary],
messagesCount = feedInfo["message_count"] as? Int else {
return nil
}
@@ -2604,7 +2603,8 @@ struct DiscoveredFeed: Hashable {
let distance = feedInfo["distance"] as? Double
let attachments = attachmentsData.map({ DiscoveredAttachment.fromJSONDictionary($0) }).flatMap({ $0 })
let attachmentsData = feedInfo["attachments"] as? [JSONDictionary]
let attachments = attachmentsData?.map({ DiscoveredAttachment.fromJSONDictionary($0) }).flatMap({ $0 }) ?? []
var skill: Skill?
if let skillInfo = feedInfo["skill"] as? JSONDictionary {
@@ -2718,7 +2718,11 @@ func feedsOfUser(userID: String, pageIndex: Int, perPage: Int, failureHandler: (
}
enum FeedKind: String {
case Normal = "normal"
case Text = "text"
case Image = "image"
case Video = "video"
case Audio = "audio"
case Location = "location"
case AppleMusic = "apple_music"
case AppleMovie = "apple_movie"
@@ -117,8 +117,6 @@ class FeedsViewController: BaseViewController {
let height: CGFloat
switch feed.kind {
case .Normal:
height = FeedCell.heightOfFeed(feed)
case .GithubRepo, .DribbbleShot:
height = FeedSocialWorkCell.heightOfFeed(feed)
default:
@@ -591,9 +589,6 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate {
let feed = feeds[indexPath.row]
switch feed.kind {
case .Normal:
let cell = tableView.dequeueReusableCellWithIdentifier(feedCellID) as! FeedCell
return cell
case .GithubRepo, .DribbbleShot:
let cell = tableView.dequeueReusableCellWithIdentifier(feedSocialWorkCellID) as! FeedSocialWorkCell
@@ -631,7 +626,12 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate {
switch feed.kind {
case .Normal:
case .GithubRepo, .DribbbleShot:
guard let cell = cell as? FeedSocialWorkCell else {
break
}
default:
guard let cell = cell as? FeedCell else {
break
@@ -715,14 +715,6 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate {
}
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
case .GithubRepo, .DribbbleShot:
guard let cell = cell as? FeedSocialWorkCell else {
break
}
default:
break
}
case Section.LoadMore.rawValue:
@@ -486,7 +486,7 @@ class NewFeedViewController: UIViewController {
}
createFeedWithKind(.Normal, message: message, attachments: mediaInfo, sharedStuff: nil, coordinate: coordinate, skill: self?.pickedSkill, allowComment: true, failureHandler: { [weak self] reason, errorMessage in
createFeedWithKind(.Image, message: message, attachments: mediaInfo, sharedStuff: nil, 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)