From b0ebef2cfd67f3911d671ded99d3debff6579214 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 7 Feb 2021 19:52:59 -0500 Subject: [PATCH] Only show Trending Hashtags and Profile Directory on Mastodon --- Tusker/Controllers/MastodonController.swift | 1 + .../Explore/ExploreViewController.swift | 20 +++++++++++-- .../Main/MainSidebarViewController.swift | 29 +++++++++++++++---- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/Tusker/Controllers/MastodonController.swift b/Tusker/Controllers/MastodonController.swift index 010b6db8..2c02d7be 100644 --- a/Tusker/Controllers/MastodonController.swift +++ b/Tusker/Controllers/MastodonController.swift @@ -115,6 +115,7 @@ class MastodonController: ObservableObject { } } + // todo: this should dedup requests func getOwnInstance(completion: ((Instance) -> Void)? = nil) { if let instance = self.instance { completion?(instance) diff --git a/Tusker/Screens/Explore/ExploreViewController.swift b/Tusker/Screens/Explore/ExploreViewController.swift index 1ff72b92..66c5de3b 100644 --- a/Tusker/Screens/Explore/ExploreViewController.swift +++ b/Tusker/Screens/Explore/ExploreViewController.swift @@ -51,6 +51,10 @@ class ExploreViewController: UIViewController, UICollectionViewDelegate { dataSource = createDataSource() applyInitialSnapshot() + if mastodonController.instance == nil { + mastodonController.getOwnInstance(completion: self.ownInstanceLoaded(_:)) + } + resultsController = SearchResultsViewController(mastodonController: mastodonController) resultsController.exploreNavigationController = self.navigationController! searchController = UISearchController(searchResultsController: resultsController) @@ -132,9 +136,12 @@ class ExploreViewController: UIViewController, UICollectionViewDelegate { let account = mastodonController.accountInfo! var snapshot = NSDiffableDataSourceSnapshot() - snapshot.appendSections(Section.allCases) + snapshot.appendSections(Section.allCases.filter { $0 != .discover }) snapshot.appendItems([.bookmarks], toSection: .bookmarks) - snapshot.appendItems([.trendingTags, .profileDirectory], toSection: .discover) + if case .mastodon = mastodonController.instance?.instanceType { + snapshot.insertSections([.discover], afterSection: .bookmarks) + snapshot.appendItems([.trendingTags, .profileDirectory], toSection: .discover) + } snapshot.appendItems([.addList], toSection: .lists) snapshot.appendItems(SavedDataManager.shared.sortedHashtags(for: account).map { .savedHashtag($0) }, toSection: .savedHashtags) snapshot.appendItems([.addSavedHashtag], toSection: .savedHashtags) @@ -145,6 +152,15 @@ class ExploreViewController: UIViewController, UICollectionViewDelegate { reloadLists() } + private func ownInstanceLoaded(_ instance: Instance) { + var snapshot = self.dataSource.snapshot() + if case .mastodon = instance.instanceType { + snapshot.insertSections([.discover], afterSection: .bookmarks) + snapshot.appendItems([.trendingTags, .profileDirectory], toSection: .discover) + } + self.dataSource.apply(snapshot) + } + private func reloadLists() { let request = Client.getLists() mastodonController.run(request) { (response) in diff --git a/Tusker/Screens/Main/MainSidebarViewController.swift b/Tusker/Screens/Main/MainSidebarViewController.swift index 32ab59a0..7eef7c8f 100644 --- a/Tusker/Screens/Main/MainSidebarViewController.swift +++ b/Tusker/Screens/Main/MainSidebarViewController.swift @@ -86,6 +86,10 @@ class MainSidebarViewController: UIViewController { applyInitialSnapshot() + if mastodonController.instance == nil { + mastodonController.getOwnInstance(completion: self.ownInstanceLoaded(_:)) + } + select(item: .tab(.timelines), animated: false) NotificationCenter.default.addObserver(self, selector: #selector(reloadSavedHashtags), name: .savedHashtagsChanged, object: nil) @@ -130,7 +134,7 @@ class MainSidebarViewController: UIViewController { private func applyInitialSnapshot() { var snapshot = NSDiffableDataSourceSnapshot() - snapshot.appendSections(Section.allCases) + snapshot.appendSections(Section.allCases.filter { $0 != .discover }) snapshot.appendItems([ .tab(.timelines), .tab(.notifications), @@ -141,10 +145,13 @@ class MainSidebarViewController: UIViewController { snapshot.appendItems([ .tab(.compose) ], toSection: .compose) - snapshot.appendItems([ - .trendingTags, - .profileDirectory, - ], toSection: .discover) + if case .mastodon = mastodonController.instance?.instanceType { + snapshot.insertSections([.discover], afterSection: .compose) + snapshot.appendItems([ + .trendingTags, + .profileDirectory, + ], toSection: .discover) + } dataSource.apply(snapshot, animatingDifferences: false) reloadLists() @@ -152,6 +159,18 @@ class MainSidebarViewController: UIViewController { reloadSavedInstances() } + private func ownInstanceLoaded(_ instance: Instance) { + var snapshot = self.dataSource.snapshot() + if case .mastodon = mastodonController.instance?.instanceType { + snapshot.insertSections([.discover], afterSection: .compose) + snapshot.appendItems([ + .trendingTags, + .profileDirectory, + ], toSection: .discover) + } + dataSource.apply(snapshot, animatingDifferences: false) + } + private func reloadLists() { let request = Client.getLists() mastodonController.run(request) { [weak self] (response) in