From 266c7ed201568dda92e5569e5862585aa7ee2961 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 28 Aug 2018 16:22:49 -0400 Subject: [PATCH] Don't open redundant VCs --- Tusker.xcodeproj/project.pbxproj | 8 ++++---- ...atus+Equatable.swift => Mastodon+Equatable.swift} | 6 ++++++ ...IViewController+StatusTableViewCellDelegate.swift | 12 ++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) rename Tusker/Extensions/{Status+Equatable.swift => Mastodon+Equatable.swift} (68%) diff --git a/Tusker.xcodeproj/project.pbxproj b/Tusker.xcodeproj/project.pbxproj index bcd8d04c..dedf768b 100644 --- a/Tusker.xcodeproj/project.pbxproj +++ b/Tusker.xcodeproj/project.pbxproj @@ -25,7 +25,7 @@ D667E5F12134D5050057A976 /* UIViewController+StatusTableViewCellDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D667E5F02134D5050057A976 /* UIViewController+StatusTableViewCellDelegate.swift */; }; D667E5F32135BC260057A976 /* Conversation.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D667E5F22135BC260057A976 /* Conversation.storyboard */; }; D667E5F52135BCD50057A976 /* ConversationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D667E5F42135BCD50057A976 /* ConversationViewController.swift */; }; - D667E5F82135C3040057A976 /* Status+Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = D667E5F72135C3040057A976 /* Status+Equatable.swift */; }; + D667E5F82135C3040057A976 /* Mastodon+Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = D667E5F72135C3040057A976 /* Mastodon+Equatable.swift */; }; D6BED16F212663DA00F02DA0 /* SwiftSoup.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D6BED16E212663DA00F02DA0 /* SwiftSoup.framework */; }; D6BED170212663DA00F02DA0 /* SwiftSoup.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D6BED16E212663DA00F02DA0 /* SwiftSoup.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; D6BED174212667E900F02DA0 /* StatusTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6BED173212667E900F02DA0 /* StatusTableViewCell.swift */; }; @@ -93,7 +93,7 @@ D667E5F02134D5050057A976 /* UIViewController+StatusTableViewCellDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+StatusTableViewCellDelegate.swift"; sourceTree = ""; }; D667E5F22135BC260057A976 /* Conversation.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Conversation.storyboard; sourceTree = ""; }; D667E5F42135BCD50057A976 /* ConversationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationViewController.swift; sourceTree = ""; }; - D667E5F72135C3040057A976 /* Status+Equatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Status+Equatable.swift"; sourceTree = ""; }; + D667E5F72135C3040057A976 /* Mastodon+Equatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Mastodon+Equatable.swift"; sourceTree = ""; }; D6BED16E212663DA00F02DA0 /* SwiftSoup.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftSoup.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D6BED173212667E900F02DA0 /* StatusTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusTableViewCell.swift; sourceTree = ""; }; D6D4DDCC212518A000E1C4BB /* Tusker.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Tusker.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -145,7 +145,7 @@ isa = PBXGroup; children = ( D667E5F02134D5050057A976 /* UIViewController+StatusTableViewCellDelegate.swift */, - D667E5F72135C3040057A976 /* Status+Equatable.swift */, + D667E5F72135C3040057A976 /* Mastodon+Equatable.swift */, ); path = Extensions; sourceTree = ""; @@ -399,7 +399,7 @@ 04DACE8C212CB14B009840C4 /* MainTabBarViewController.swift in Sources */, D667E5F52135BCD50057A976 /* ConversationViewController.swift in Sources */, D6F953F021251A2900CF0F2B /* MastodonController.swift in Sources */, - D667E5F82135C3040057A976 /* Status+Equatable.swift in Sources */, + D667E5F82135C3040057A976 /* Mastodon+Equatable.swift in Sources */, 04DACE8E212CC7CC009840C4 /* AvatarCache.swift in Sources */, D6BED174212667E900F02DA0 /* StatusTableViewCell.swift in Sources */, D64D0AAD2128D88B005A6F37 /* LocalData.swift in Sources */, diff --git a/Tusker/Extensions/Status+Equatable.swift b/Tusker/Extensions/Mastodon+Equatable.swift similarity index 68% rename from Tusker/Extensions/Status+Equatable.swift rename to Tusker/Extensions/Mastodon+Equatable.swift index ec1b5457..492de48f 100644 --- a/Tusker/Extensions/Status+Equatable.swift +++ b/Tusker/Extensions/Mastodon+Equatable.swift @@ -13,3 +13,9 @@ extension Status: Equatable { return lhs.id == rhs.id } } + +extension Account: Equatable { + public static func ==(lhs: Account, rhs: Account) -> Bool { + return lhs.id == rhs.id + } +} diff --git a/Tusker/Extensions/UIViewController+StatusTableViewCellDelegate.swift b/Tusker/Extensions/UIViewController+StatusTableViewCellDelegate.swift index 8bf0ff2f..1dc506d5 100644 --- a/Tusker/Extensions/UIViewController+StatusTableViewCellDelegate.swift +++ b/Tusker/Extensions/UIViewController+StatusTableViewCellDelegate.swift @@ -13,6 +13,12 @@ import SafariServices extension UIViewController: StatusTableViewCellDelegate { func selected(account: Account) { + // don't open if the account is the same as the current one + if let profileController = self as? ProfileTableViewController, + profileController.account == account { + return + } + guard let navigationController = navigationController else { fatalError("Can't show profile VC when not in navigation controller") } @@ -34,6 +40,12 @@ extension UIViewController: StatusTableViewCellDelegate { } func selected(status: Status) { + // don't open if the conversation is the same as the current one + if let conversationController = self as? ConversationViewController, + conversationController.mainStatus == status { + return + } + guard let navigationController = navigationController else { fatalError("Can't show conversation VC when not in navigation controller") }