From ed58679abffabeb8a1525cd1b931526ffa838085 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 26 Jan 2016 13:30:33 +0800 Subject: [PATCH 1/4] rename OpenGraphInfo --- Yep/Realm/Models.swift | 26 ++++++++-------- .../ConversationViewController.swift | 30 +++++++++---------- .../ChatLeftTextURL/ChatLeftTextURLCell.swift | 6 ++-- .../ChatRightTextURLCell.swift | 6 ++-- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/Yep/Realm/Models.swift b/Yep/Realm/Models.swift index d23a47fd..4214190a 100644 --- a/Yep/Realm/Models.swift +++ b/Yep/Realm/Models.swift @@ -525,8 +525,8 @@ class Message: Object { return String(format: NSLocalizedString("%@ recalled a message.", comment: ""), nickname) } - dynamic var openGraphURLDetected: Bool = false - dynamic var openGraphURLInfo: FeedURLInfo? + dynamic var openGraphDetected: Bool = false + dynamic var openGraphInfo: OpenGraphInfo? dynamic var coordinate: Coordinate? @@ -592,8 +592,8 @@ class Message: Object { realm.delete(mediaMetaData) } - if let openGraphURLInfo = openGraphURLInfo { - realm.delete(openGraphURLInfo) + if let openGraphInfo = openGraphInfo { + realm.delete(openGraphInfo) } switch mediaType { @@ -821,7 +821,7 @@ class FeedLocation: Object { dynamic var coordinate: Coordinate? } -class FeedURLInfo: Object { +class OpenGraphInfo: Object { dynamic var URLString: String = "" dynamic var siteName: String = "" @@ -847,12 +847,12 @@ class FeedURLInfo: Object { self.thumbnailImageURLString = thumbnailImageURLString } - class func withURLString(URLString: String, inRealm realm: Realm) -> FeedURLInfo? { - return realm.objects(FeedURLInfo).filter("URLString = %@", URLString).first + class func withURLString(URLString: String, inRealm realm: Realm) -> OpenGraphInfo? { + return realm.objects(OpenGraphInfo).filter("URLString = %@", URLString).first } } -extension FeedURLInfo: FeedURLInfoType { +extension OpenGraphInfo: FeedURLInfoType { var URL: NSURL { return NSURL(string: URLString)! @@ -877,7 +877,7 @@ class Feed: Object { dynamic var socialWork: MessageSocialWork? dynamic var audio: FeedAudio? dynamic var location: FeedLocation? - dynamic var URLInfo: FeedURLInfo? + dynamic var openGraphInfo: OpenGraphInfo? dynamic var skill: UserSkill? @@ -1309,15 +1309,15 @@ func saveFeedWithDiscoveredFeed(feedData: DiscoveredFeed, group: Group, inRealm case .URL(let URLInfo): - guard feed.URLInfo == nil else { + guard feed.openGraphInfo == nil else { break } - let feedURLInfo = FeedURLInfo(URLString: URLInfo.URL.absoluteString, siteName: URLInfo.siteName, title: URLInfo.title, infoDescription: URLInfo.infoDescription, thumbnailImageURLString: URLInfo.thumbnailImageURLString) + let openGraphInfo = OpenGraphInfo(URLString: URLInfo.URL.absoluteString, siteName: URLInfo.siteName, title: URLInfo.title, infoDescription: URLInfo.infoDescription, thumbnailImageURLString: URLInfo.thumbnailImageURLString) - realm.add(feedURLInfo, update: true) + realm.add(openGraphInfo, update: true) - feed.URLInfo = feedURLInfo + feed.openGraphInfo = openGraphInfo } } } diff --git a/Yep/ViewControllers/Conversation/ConversationViewController.swift b/Yep/ViewControllers/Conversation/ConversationViewController.swift index 700cad60..daac0c60 100644 --- a/Yep/ViewControllers/Conversation/ConversationViewController.swift +++ b/Yep/ViewControllers/Conversation/ConversationViewController.swift @@ -269,7 +269,7 @@ enum ConversationFeed { } } case .FeedType(let feed): - if let URLInfo = feed.URLInfo { + if let URLInfo = feed.openGraphInfo { return URLInfo } } @@ -1887,7 +1887,7 @@ class ConversationViewController: BaseViewController { height = max(ceil(rect.height) + (11 * 2), YepConfig.chatCellAvatarSize()) - if message.openGraphURLInfo != nil { + if message.openGraphInfo != nil { height += 100 + 10 } @@ -3762,7 +3762,7 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi return cell } else { - if message.openGraphURLInfo != nil { + if message.openGraphInfo != nil { let cell = collectionView.dequeueReusableCellWithReuseIdentifier(chatLeftTextURLCellIdentifier, forIndexPath: indexPath) as! ChatLeftTextURLCell return cell @@ -3799,7 +3799,7 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi default: - if message.openGraphURLInfo != nil { + if message.openGraphInfo != nil { let cell = collectionView.dequeueReusableCellWithReuseIdentifier(chatRightTextURLCellIdentifier, forIndexPath: indexPath) as! ChatRightTextURLCell return cell @@ -3989,7 +3989,7 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi } } else { - if message.openGraphURLInfo != nil { + if message.openGraphInfo != nil { if let cell = cell as? ChatLeftTextURLCell { @@ -4191,7 +4191,7 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi }) } - if message.openGraphURLInfo != nil { + if message.openGraphInfo != nil { if let cell = cell as? ChatRightTextURLCell { @@ -4229,19 +4229,19 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi private func tryDetectOpenGraphForMessage(message: Message) { - guard !message.openGraphURLDetected else { + guard !message.openGraphDetected else { return } - func markMessageOpenGraphURLDetected() { + func markMessageOpenGraphDetected() { let _ = try? realm.write { - message.openGraphURLDetected = true + message.openGraphDetected = true } } let text = message.textContent guard let fisrtURL = text.yep_embeddedURLs.first else { - markMessageOpenGraphURLDetected() + markMessageOpenGraphDetected() return } @@ -4249,7 +4249,7 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi defaultFailureHandler(reason, errorMessage: errorMessage) dispatch_async(dispatch_get_main_queue()) { - markMessageOpenGraphURLDetected() + markMessageOpenGraphDetected() } }, completion: { _openGraph in @@ -4265,14 +4265,14 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi return } - let openGraphURLInfo = FeedURLInfo(URLString: _openGraph.URL.absoluteString, siteName: _openGraph.siteName ?? "", title: _openGraph.title ?? "", infoDescription: _openGraph.description ?? "", thumbnailImageURLString: _openGraph.previewImageURLString ?? "") + let openGraphInfo = OpenGraphInfo(URLString: _openGraph.URL.absoluteString, siteName: _openGraph.siteName ?? "", title: _openGraph.title ?? "", infoDescription: _openGraph.description ?? "", thumbnailImageURLString: _openGraph.previewImageURLString ?? "") let _ = try? strongSelf.realm.write { - strongSelf.realm.add(openGraphURLInfo, update: true) - message.openGraphURLInfo = openGraphURLInfo + strongSelf.realm.add(openGraphInfo, update: true) + message.openGraphInfo = openGraphInfo } - markMessageOpenGraphURLDetected() + markMessageOpenGraphDetected() // update UI strongSelf.clearHeightOfMessageWithKey(message.messageID) diff --git a/Yep/Views/Cells/ChatLeftTextURL/ChatLeftTextURLCell.swift b/Yep/Views/Cells/ChatLeftTextURL/ChatLeftTextURLCell.swift index 0120f19c..d59fd783 100644 --- a/Yep/Views/Cells/ChatLeftTextURL/ChatLeftTextURLCell.swift +++ b/Yep/Views/Cells/ChatLeftTextURL/ChatLeftTextURLCell.swift @@ -51,9 +51,9 @@ class ChatLeftTextURLCell: ChatLeftTextCell { let feedURLContainerViewFrame = CGRect(x: textContentTextView.frame.origin.x - 12 + 1, y: CGRectGetMaxY(textContentTextView.frame) + 8, width: width, height: 100) feedURLContainerView.frame = feedURLContainerViewFrame - if let openGraphURLInfo = message.openGraphURLInfo { - feedURLContainerView.configureWithFeedURLInfoType(openGraphURLInfo) - openGraphURL = openGraphURLInfo.URL + if let openGraphInfo = message.openGraphInfo { + feedURLContainerView.configureWithFeedURLInfoType(openGraphInfo) + openGraphURL = openGraphInfo.URL } } } diff --git a/Yep/Views/Cells/ChatRightTextURL/ChatRightTextURLCell.swift b/Yep/Views/Cells/ChatRightTextURL/ChatRightTextURLCell.swift index 6ad41e2e..39906682 100644 --- a/Yep/Views/Cells/ChatRightTextURL/ChatRightTextURLCell.swift +++ b/Yep/Views/Cells/ChatRightTextURL/ChatRightTextURLCell.swift @@ -52,9 +52,9 @@ class ChatRightTextURLCell: ChatRightTextCell { let feedURLContainerViewFrame = CGRect(x: fullWidth - 65 - width - 1, y: CGRectGetMaxY(textContainerView.frame) + 8, width: width, height: 100) feedURLContainerView.frame = feedURLContainerViewFrame - if let openGraphURLInfo = message.openGraphURLInfo { - feedURLContainerView.configureWithFeedURLInfoType(openGraphURLInfo) - openGraphURL = openGraphURLInfo.URL + if let openGraphInfo = message.openGraphInfo { + feedURLContainerView.configureWithFeedURLInfoType(openGraphInfo) + openGraphURL = openGraphInfo.URL } } } From 5e10eb4d105298c2f50a23be5e2d2980fed402a7 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 26 Jan 2016 13:42:23 +0800 Subject: [PATCH 2/4] new delete rules for Message & Feed --- Yep/AppDelegate.swift | 2 +- Yep/Realm/Models.swift | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Yep/AppDelegate.swift b/Yep/AppDelegate.swift index 53cc5816..4f9a4ebf 100644 --- a/Yep/AppDelegate.swift +++ b/Yep/AppDelegate.swift @@ -43,7 +43,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { let directory: NSURL = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier(YepConfig.appGroupID)! let realmPath = directory.URLByAppendingPathComponent("db.realm").path! - return Realm.Configuration(path: realmPath, schemaVersion: 22, migrationBlock: { migration, oldSchemaVersion in + return Realm.Configuration(path: realmPath, schemaVersion: 23, migrationBlock: { migration, oldSchemaVersion in }) } diff --git a/Yep/Realm/Models.swift b/Yep/Realm/Models.swift index 4214190a..61c612fa 100644 --- a/Yep/Realm/Models.swift +++ b/Yep/Realm/Models.swift @@ -592,8 +592,13 @@ class Message: Object { realm.delete(mediaMetaData) } + // 除非没有谁指向 openGraphInfo,不然不能删除它 if let openGraphInfo = openGraphInfo { - realm.delete(openGraphInfo) + if openGraphInfo.feeds.isEmpty { + if openGraphInfo.messages.count == 1, let first = openGraphInfo.messages.first where first == self { + realm.delete(openGraphInfo) + } + } } switch mediaType { @@ -829,6 +834,13 @@ class OpenGraphInfo: Object { dynamic var infoDescription: String = "" dynamic var thumbnailImageURLString: String = "" + var messages: [Message] { + return linkingObjects(Message.self, forProperty: "openGraphInfo") + } + var feeds: [Feed] { + return linkingObjects(Feed.self, forProperty: "openGraphInfo") + } + override class func primaryKey() -> String? { return "URLString" } @@ -926,6 +938,15 @@ class Feed: Object { realm.delete(location) } + // 除非没有谁指向 openGraphInfo,不然不能删除它 + if let openGraphInfo = openGraphInfo { + if openGraphInfo.messages.isEmpty { + if openGraphInfo.feeds.count == 1, let first = openGraphInfo.messages.first where first == self { + realm.delete(openGraphInfo) + } + } + } + realm.delete(self) } } From 79beea76a8382fe5f1e0df0b43ca96facb4d6501 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 26 Jan 2016 13:54:09 +0800 Subject: [PATCH 3/4] OpenGraphInfoType --- Yep.xcodeproj/project.pbxproj | 8 ++++---- .../{FeedURLInfoType.swift => OpenGraphInfoType.swift} | 4 ++-- Yep/Realm/Models.swift | 2 +- Yep/Services/YepService.swift | 2 +- .../Conversation/ConversationViewController.swift | 10 +++++----- .../Cells/ChatLeftTextURL/ChatLeftTextURLCell.swift | 2 +- .../Cells/ChatRightTextURL/ChatRightTextURLCell.swift | 2 +- Yep/Views/Cells/Feed/FeedURLCell.swift | 2 +- Yep/Views/ContainerViews/FeedURLContainerView.swift | 10 +++++----- Yep/Views/Feed/FeedView.swift | 6 +++--- 10 files changed, 24 insertions(+), 24 deletions(-) rename Yep/Protocols/{FeedURLInfoType.swift => OpenGraphInfoType.swift} (84%) diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index 0e977e62..9969e86c 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -264,7 +264,7 @@ 50CDBE491ACBAD3200459CE0 /* ChatLeftImageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50CDBE471ACBAD3200459CE0 /* ChatLeftImageCell.swift */; }; 50D45FC31C44D2300044C95A /* OpenGraphService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D45FC21C44D2300044C95A /* OpenGraphService.swift */; }; 50D4D0DB1AFA825B005AEB6F /* MediaControlView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D4D0DA1AFA825B005AEB6F /* MediaControlView.swift */; }; - 50DBDEF11C48C2240044E21B /* FeedURLInfoType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50DBDEF01C48C2240044E21B /* FeedURLInfoType.swift */; }; + 50DBDEF11C48C2240044E21B /* OpenGraphInfoType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50DBDEF01C48C2240044E21B /* OpenGraphInfoType.swift */; }; 50DBDEFD1C4CCB030044E21B /* ChatLeftTextURLCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50DBDEFB1C4CCB030044E21B /* ChatLeftTextURLCell.swift */; }; 50DBDF011C4CE75E0044E21B /* ChatRightTextURLCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50DBDEFF1C4CE75E0044E21B /* ChatRightTextURLCell.swift */; }; 50DBDF051C4DD9530044E21B /* CGSize+Yep.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50DBDF041C4DD9530044E21B /* CGSize+Yep.swift */; }; @@ -637,7 +637,7 @@ 50CDBE471ACBAD3200459CE0 /* ChatLeftImageCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ChatLeftImageCell.swift; path = Views/Cells/ChatLeftImage/ChatLeftImageCell.swift; sourceTree = ""; }; 50D45FC21C44D2300044C95A /* OpenGraphService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = OpenGraphService.swift; path = Services/OpenGraphService.swift; sourceTree = ""; }; 50D4D0DA1AFA825B005AEB6F /* MediaControlView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MediaControlView.swift; path = Views/Media/MediaControlView.swift; sourceTree = ""; }; - 50DBDEF01C48C2240044E21B /* FeedURLInfoType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedURLInfoType.swift; path = Protocols/FeedURLInfoType.swift; sourceTree = ""; }; + 50DBDEF01C48C2240044E21B /* OpenGraphInfoType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = OpenGraphInfoType.swift; path = Protocols/OpenGraphInfoType.swift; sourceTree = ""; }; 50DBDEFB1C4CCB030044E21B /* ChatLeftTextURLCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ChatLeftTextURLCell.swift; path = Views/Cells/ChatLeftTextURL/ChatLeftTextURLCell.swift; sourceTree = ""; }; 50DBDEFF1C4CE75E0044E21B /* ChatRightTextURLCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ChatRightTextURLCell.swift; path = Views/Cells/ChatRightTextURL/ChatRightTextURLCell.swift; sourceTree = ""; }; 50DBDF041C4DD9530044E21B /* CGSize+Yep.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "CGSize+Yep.swift"; path = "Extensions/CGSize+Yep.swift"; sourceTree = ""; }; @@ -2071,7 +2071,7 @@ 50DBDEF21C48C2290044E21B /* Protocols */ = { isa = PBXGroup; children = ( - 50DBDEF01C48C2240044E21B /* FeedURLInfoType.swift */, + 50DBDEF01C48C2240044E21B /* OpenGraphInfoType.swift */, ); name = Protocols; sourceTree = ""; @@ -2872,7 +2872,7 @@ 0A90187E1B01152800AE4B7F /* ProfileSocialAccountCell.swift in Sources */, 50F5AF831BBA67060033C9BC /* NewFeedViewController.swift in Sources */, 50FE29CD1C4786AE0067CA03 /* FeedURLCell.swift in Sources */, - 50DBDEF11C48C2240044E21B /* FeedURLInfoType.swift in Sources */, + 50DBDEF11C48C2240044E21B /* OpenGraphInfoType.swift in Sources */, 50894CF51AEA4A01000981AF /* SettingsUserCell.swift in Sources */, 84385C441B8592120071130D /* ShowStepGeniusViewController.swift in Sources */, 6A5632931BC911CB00397B53 /* DiscoverNormalUserCell.swift in Sources */, diff --git a/Yep/Protocols/FeedURLInfoType.swift b/Yep/Protocols/OpenGraphInfoType.swift similarity index 84% rename from Yep/Protocols/FeedURLInfoType.swift rename to Yep/Protocols/OpenGraphInfoType.swift index f976a754..5f75247a 100644 --- a/Yep/Protocols/FeedURLInfoType.swift +++ b/Yep/Protocols/OpenGraphInfoType.swift @@ -1,5 +1,5 @@ // -// FeedURLInfoType.swift +// OpenGraphInfoType.swift // Yep // // Created by nixzhu on 16/1/15. @@ -8,7 +8,7 @@ import Foundation -protocol FeedURLInfoType { +protocol OpenGraphInfoType { var URL: NSURL { get } diff --git a/Yep/Realm/Models.swift b/Yep/Realm/Models.swift index 61c612fa..44bf1494 100644 --- a/Yep/Realm/Models.swift +++ b/Yep/Realm/Models.swift @@ -864,7 +864,7 @@ class OpenGraphInfo: Object { } } -extension OpenGraphInfo: FeedURLInfoType { +extension OpenGraphInfo: OpenGraphInfoType { var URL: NSURL { return NSURL(string: URLString)! diff --git a/Yep/Services/YepService.swift b/Yep/Services/YepService.swift index 2ea09385..f92dd560 100644 --- a/Yep/Services/YepService.swift +++ b/Yep/Services/YepService.swift @@ -2959,7 +2959,7 @@ struct DiscoveredFeed: Hashable { } } - struct URLInfo: FeedURLInfoType { + struct URLInfo: OpenGraphInfoType { let URL: NSURL diff --git a/Yep/ViewControllers/Conversation/ConversationViewController.swift b/Yep/ViewControllers/Conversation/ConversationViewController.swift index daac0c60..4fc2149b 100644 --- a/Yep/ViewControllers/Conversation/ConversationViewController.swift +++ b/Yep/ViewControllers/Conversation/ConversationViewController.swift @@ -259,18 +259,18 @@ enum ConversationFeed { return nil } - var URLInfo: FeedURLInfoType? { + var openGraphInfo: OpenGraphInfoType? { switch self { case .DiscoveredFeedType(let discoveredFeed): if let attachment = discoveredFeed.attachment { - if case let .URL(URLInfo) = attachment { - return URLInfo + if case let .URL(openGraphInfo) = attachment { + return openGraphInfo } } case .FeedType(let feed): - if let URLInfo = feed.openGraphInfo { - return URLInfo + if let openGraphInfo = feed.openGraphInfo { + return openGraphInfo } } diff --git a/Yep/Views/Cells/ChatLeftTextURL/ChatLeftTextURLCell.swift b/Yep/Views/Cells/ChatLeftTextURL/ChatLeftTextURLCell.swift index d59fd783..a63a9790 100644 --- a/Yep/Views/Cells/ChatLeftTextURL/ChatLeftTextURLCell.swift +++ b/Yep/Views/Cells/ChatLeftTextURL/ChatLeftTextURLCell.swift @@ -52,7 +52,7 @@ class ChatLeftTextURLCell: ChatLeftTextCell { feedURLContainerView.frame = feedURLContainerViewFrame if let openGraphInfo = message.openGraphInfo { - feedURLContainerView.configureWithFeedURLInfoType(openGraphInfo) + feedURLContainerView.configureWithOpenGraphInfoType(openGraphInfo) openGraphURL = openGraphInfo.URL } } diff --git a/Yep/Views/Cells/ChatRightTextURL/ChatRightTextURLCell.swift b/Yep/Views/Cells/ChatRightTextURL/ChatRightTextURLCell.swift index 39906682..4637ab70 100644 --- a/Yep/Views/Cells/ChatRightTextURL/ChatRightTextURLCell.swift +++ b/Yep/Views/Cells/ChatRightTextURL/ChatRightTextURLCell.swift @@ -53,7 +53,7 @@ class ChatRightTextURLCell: ChatRightTextCell { feedURLContainerView.frame = feedURLContainerViewFrame if let openGraphInfo = message.openGraphInfo { - feedURLContainerView.configureWithFeedURLInfoType(openGraphInfo) + feedURLContainerView.configureWithOpenGraphInfoType(openGraphInfo) openGraphURL = openGraphInfo.URL } } diff --git a/Yep/Views/Cells/Feed/FeedURLCell.swift b/Yep/Views/Cells/Feed/FeedURLCell.swift index 06bc41bc..6bf4c9e4 100644 --- a/Yep/Views/Cells/Feed/FeedURLCell.swift +++ b/Yep/Views/Cells/Feed/FeedURLCell.swift @@ -62,7 +62,7 @@ class FeedURLCell: FeedBasicCell { if let attachment = feed.attachment { if case let .URL(URLInfo) = attachment { - feedURLContainerView.configureWithFeedURLInfoType(URLInfo) + feedURLContainerView.configureWithOpenGraphInfoType(URLInfo) feedURLContainerView.tapAction = { [weak self] in self?.tapURLInfoAction?(URL: URLInfo.URL) diff --git a/Yep/Views/ContainerViews/FeedURLContainerView.swift b/Yep/Views/ContainerViews/FeedURLContainerView.swift index a887d44e..432789f5 100644 --- a/Yep/Views/ContainerViews/FeedURLContainerView.swift +++ b/Yep/Views/ContainerViews/FeedURLContainerView.swift @@ -146,13 +146,13 @@ class FeedURLContainerView: UIView { tapAction?() } - func configureWithFeedURLInfoType(URLInfo: FeedURLInfoType) { + func configureWithOpenGraphInfoType(openGraphInfo: OpenGraphInfoType) { - siteNameLabel.text = URLInfo.siteName - titleLabel.text = URLInfo.title - descriptionLabel.text = URLInfo.infoDescription + siteNameLabel.text = openGraphInfo.siteName + titleLabel.text = openGraphInfo.title + descriptionLabel.text = openGraphInfo.infoDescription - if let thumbnailImageURL = NSURL(string: URLInfo.thumbnailImageURLString) { + if let thumbnailImageURL = NSURL(string: openGraphInfo.thumbnailImageURLString) { thumbnailImageView.kf_setImageWithURL(thumbnailImageURL, placeholderImage: nil) } else { thumbnailImageView.image = nil diff --git a/Yep/Views/Feed/FeedView.swift b/Yep/Views/Feed/FeedView.swift index c0d541b0..716b04f5 100644 --- a/Yep/Views/Feed/FeedView.swift +++ b/Yep/Views/Feed/FeedView.swift @@ -360,8 +360,8 @@ class FeedView: UIView { socialWorkContainerViewHeightConstraint.constant = 80 - if let URLInfo = feed.URLInfo { - feedURLContainerView.configureWithFeedURLInfoType(URLInfo) + if let openGraphInfo = feed.openGraphInfo { + feedURLContainerView.configureWithOpenGraphInfoType(openGraphInfo) } case .Image: @@ -512,7 +512,7 @@ class FeedView: UIView { } func tapURLInfo(sender: UITapGestureRecognizer) { - guard let URL = feed?.URLInfo?.URL else { + guard let URL = feed?.openGraphInfo?.URL else { return } From 65b1ed63e2f9e52e400d64cb78a47c88f8ab50a9 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 26 Jan 2016 14:01:08 +0800 Subject: [PATCH 4/4] struct OpenGraphInfo --- Yep/Realm/Models.swift | 4 ++-- Yep/Services/YepService.swift | 16 ++++++++-------- Yep/Views/Cells/Feed/FeedURLCell.swift | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Yep/Realm/Models.swift b/Yep/Realm/Models.swift index 44bf1494..50697fb4 100644 --- a/Yep/Realm/Models.swift +++ b/Yep/Realm/Models.swift @@ -1328,13 +1328,13 @@ func saveFeedWithDiscoveredFeed(feedData: DiscoveredFeed, group: Group, inRealm feed.location = feedLocation - case .URL(let URLInfo): + case .URL(let info): guard feed.openGraphInfo == nil else { break } - let openGraphInfo = OpenGraphInfo(URLString: URLInfo.URL.absoluteString, siteName: URLInfo.siteName, title: URLInfo.title, infoDescription: URLInfo.infoDescription, thumbnailImageURLString: URLInfo.thumbnailImageURLString) + let openGraphInfo = OpenGraphInfo(URLString: info.URL.absoluteString, siteName: info.siteName, title: info.title, infoDescription: info.infoDescription, thumbnailImageURLString: info.thumbnailImageURLString) realm.add(openGraphInfo, update: true) diff --git a/Yep/Services/YepService.swift b/Yep/Services/YepService.swift index f92dd560..57a161d7 100644 --- a/Yep/Services/YepService.swift +++ b/Yep/Services/YepService.swift @@ -2959,7 +2959,7 @@ struct DiscoveredFeed: Hashable { } } - struct URLInfo: OpenGraphInfoType { + struct OpenGraphInfo: OpenGraphInfoType { let URL: NSURL @@ -2968,7 +2968,7 @@ struct DiscoveredFeed: Hashable { let infoDescription: String let thumbnailImageURLString: String - static func fromJSONDictionary(json: JSONDictionary) -> URLInfo? { + static func fromJSONDictionary(json: JSONDictionary) -> OpenGraphInfo? { guard let URLString = json["url"] as? String, URL = NSURL(string: URLString), @@ -2979,7 +2979,7 @@ struct DiscoveredFeed: Hashable { return nil } - return URLInfo(URL: URL, siteName: siteName, title: title, infoDescription: infoDescription, thumbnailImageURLString: thumbnailImageURLString) + return OpenGraphInfo(URL: URL, siteName: siteName, title: title, infoDescription: infoDescription, thumbnailImageURLString: thumbnailImageURLString) } } @@ -2989,7 +2989,7 @@ struct DiscoveredFeed: Hashable { case Dribbble(DribbbleShot) case Audio(AudioInfo) case Location(LocationInfo) - case URL(URLInfo) + case URL(OpenGraphInfo) } let attachment: Attachment? @@ -3069,10 +3069,10 @@ struct DiscoveredFeed: Hashable { case .URL: if let - URLsData = feedInfo["attachments"] as? [JSONDictionary], - URLInfoDic = URLsData.first, - URLInfo = DiscoveredFeed.URLInfo.fromJSONDictionary(URLInfoDic) { - attachment = .URL(URLInfo) + openGraphInfosData = feedInfo["attachments"] as? [JSONDictionary], + openGraphInfoDict = openGraphInfosData.first, + openGraphInfo = DiscoveredFeed.OpenGraphInfo.fromJSONDictionary(openGraphInfoDict) { + attachment = .URL(openGraphInfo) } case .Image: diff --git a/Yep/Views/Cells/Feed/FeedURLCell.swift b/Yep/Views/Cells/Feed/FeedURLCell.swift index 6bf4c9e4..1885fdd1 100644 --- a/Yep/Views/Cells/Feed/FeedURLCell.swift +++ b/Yep/Views/Cells/Feed/FeedURLCell.swift @@ -60,12 +60,12 @@ class FeedURLCell: FeedBasicCell { } if let attachment = feed.attachment { - if case let .URL(URLInfo) = attachment { + if case let .URL(openGraphInfo) = attachment { - feedURLContainerView.configureWithOpenGraphInfoType(URLInfo) + feedURLContainerView.configureWithOpenGraphInfoType(openGraphInfo) feedURLContainerView.tapAction = { [weak self] in - self?.tapURLInfoAction?(URL: URLInfo.URL) + self?.tapURLInfoAction?(URL: openGraphInfo.URL) } } }