forked from shadowfacts/Tusker
Only show Trending Hashtags and Profile Directory on Mastodon
This commit is contained in:
parent
bbb8707cb7
commit
b0ebef2cfd
|
@ -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)
|
||||
|
|
|
@ -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<Section, Item>()
|
||||
snapshot.appendSections(Section.allCases)
|
||||
snapshot.appendSections(Section.allCases.filter { $0 != .discover })
|
||||
snapshot.appendItems([.bookmarks], toSection: .bookmarks)
|
||||
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
|
||||
|
|
|
@ -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<Section, Item>()
|
||||
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)
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue