Compare commits

..

No commits in common. "afc2bfcf6b36f736dc9b3aa223d2c22310081d81" and "036791bd39425d0b502e7230a5faf7753f73e300" have entirely different histories.

8 changed files with 26 additions and 423 deletions

View File

@ -12,10 +12,6 @@ public class List: Decodable {
public let id: String public let id: String
public let title: String public let title: String
public var timeline: Timeline {
return .list(id: id)
}
public static func getAccounts(_ list: List, range: RequestRange = .default) -> Request<[Account]> { public static func getAccounts(_ list: List, range: RequestRange = .default) -> Request<[Account]> {
var request = Request<[Account]>(method: .get, path: "/api/v1/lists/\(list.id)/accounts") var request = Request<[Account]>(method: .get, path: "/api/v1/lists/\(list.id)/accounts")
request.range = range request.range = range
@ -30,15 +26,15 @@ public class List: Decodable {
return Request<Empty>(method: .delete, path: "/api/v1/lists/\(list.id)") return Request<Empty>(method: .delete, path: "/api/v1/lists/\(list.id)")
} }
public static func add(_ list: List, accounts accountIDs: [String]) -> Request<Empty> { public static func add(_ list: List, accounts: [Account]) -> Request<Empty> {
return Request<Empty>(method: .post, path: "/api/v1/lists/\(list.id)/accounts", body: .parameters( return Request<Empty>(method: .post, path: "/api/v1/lists/\(list.id)/accounts", body: .parameters(
"account_ids" => accountIDs "account_ids" => accounts.map { $0.id }
)) ))
} }
public static func remove(_ list: List, accounts accountIDs: [String]) -> Request<Empty> { public static func remove(_ list: List, accounts: [Account]) -> Request<Empty> {
return Request<Empty>(method: .delete, path: "/api/v1/lists/\(list.id)/accounts", body: .parameters( return Request<Empty>(method: .delete, path: "/api/v1/lists/\(list.id)/accounts", body: .parameters(
"account_ids" => accountIDs "account_ids" => accounts.map { $0.id }
)) ))
} }

View File

@ -84,8 +84,6 @@
D627943E23A564D400D38C68 /* ExploreViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D627943D23A564D400D38C68 /* ExploreViewController.swift */; }; D627943E23A564D400D38C68 /* ExploreViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D627943D23A564D400D38C68 /* ExploreViewController.swift */; };
D627944723A6AC9300D38C68 /* BasicTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D627944623A6AC9300D38C68 /* BasicTableViewCell.xib */; }; D627944723A6AC9300D38C68 /* BasicTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D627944623A6AC9300D38C68 /* BasicTableViewCell.xib */; };
D627944A23A6AD6100D38C68 /* BookmarksTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D627944923A6AD6100D38C68 /* BookmarksTableViewController.swift */; }; D627944A23A6AD6100D38C68 /* BookmarksTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D627944923A6AD6100D38C68 /* BookmarksTableViewController.swift */; };
D627944D23A9A03D00D38C68 /* ListTimelineViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D627944C23A9A03D00D38C68 /* ListTimelineViewController.swift */; };
D627944F23A9C99800D38C68 /* EditListAccountsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D627944E23A9C99800D38C68 /* EditListAccountsViewController.swift */; };
D627FF76217E923E00CC0648 /* DraftsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = D627FF75217E923E00CC0648 /* DraftsManager.swift */; }; D627FF76217E923E00CC0648 /* DraftsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = D627FF75217E923E00CC0648 /* DraftsManager.swift */; };
D627FF79217E950100CC0648 /* DraftsTableViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D627FF78217E950100CC0648 /* DraftsTableViewController.xib */; }; D627FF79217E950100CC0648 /* DraftsTableViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D627FF78217E950100CC0648 /* DraftsTableViewController.xib */; };
D627FF7B217E951500CC0648 /* DraftsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D627FF7A217E951500CC0648 /* DraftsTableViewController.swift */; }; D627FF7B217E951500CC0648 /* DraftsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D627FF7A217E951500CC0648 /* DraftsTableViewController.swift */; };
@ -357,8 +355,6 @@
D627943D23A564D400D38C68 /* ExploreViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExploreViewController.swift; sourceTree = "<group>"; }; D627943D23A564D400D38C68 /* ExploreViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExploreViewController.swift; sourceTree = "<group>"; };
D627944623A6AC9300D38C68 /* BasicTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = BasicTableViewCell.xib; sourceTree = "<group>"; }; D627944623A6AC9300D38C68 /* BasicTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = BasicTableViewCell.xib; sourceTree = "<group>"; };
D627944923A6AD6100D38C68 /* BookmarksTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarksTableViewController.swift; sourceTree = "<group>"; }; D627944923A6AD6100D38C68 /* BookmarksTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarksTableViewController.swift; sourceTree = "<group>"; };
D627944C23A9A03D00D38C68 /* ListTimelineViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListTimelineViewController.swift; sourceTree = "<group>"; };
D627944E23A9C99800D38C68 /* EditListAccountsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditListAccountsViewController.swift; sourceTree = "<group>"; };
D627FF75217E923E00CC0648 /* DraftsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DraftsManager.swift; sourceTree = "<group>"; }; D627FF75217E923E00CC0648 /* DraftsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DraftsManager.swift; sourceTree = "<group>"; };
D627FF78217E950100CC0648 /* DraftsTableViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = DraftsTableViewController.xib; sourceTree = "<group>"; }; D627FF78217E950100CC0648 /* DraftsTableViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = DraftsTableViewController.xib; sourceTree = "<group>"; };
D627FF7A217E951500CC0648 /* DraftsTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DraftsTableViewController.swift; sourceTree = "<group>"; }; D627FF7A217E951500CC0648 /* DraftsTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DraftsTableViewController.swift; sourceTree = "<group>"; };
@ -743,15 +739,6 @@
path = Bookmarks; path = Bookmarks;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
D627944B23A9A02400D38C68 /* Lists */ = {
isa = PBXGroup;
children = (
D627944C23A9A03D00D38C68 /* ListTimelineViewController.swift */,
D627944E23A9C99800D38C68 /* EditListAccountsViewController.swift */,
);
path = Lists;
sourceTree = "<group>";
};
D627FF77217E94F200CC0648 /* Drafts */ = { D627FF77217E94F200CC0648 /* Drafts */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -787,7 +774,6 @@
D641C787213DD862004B4513 /* Compose */, D641C787213DD862004B4513 /* Compose */,
D627943C23A5635D00D38C68 /* Explore */, D627943C23A5635D00D38C68 /* Explore */,
D6BC9DD8232D8BCA002CA326 /* Search */, D6BC9DD8232D8BCA002CA326 /* Search */,
D627944B23A9A02400D38C68 /* Lists */,
D641C788213DD86D004B4513 /* Large Image */, D641C788213DD86D004B4513 /* Large Image */,
0411610422B4571E0030A9B7 /* Attachment */, 0411610422B4571E0030A9B7 /* Attachment */,
0411610522B457290030A9B7 /* Gallery */, 0411610522B457290030A9B7 /* Gallery */,
@ -1640,14 +1626,12 @@
D6F953F021251A2900CF0F2B /* MastodonController.swift in Sources */, D6F953F021251A2900CF0F2B /* MastodonController.swift in Sources */,
0411610022B442870030A9B7 /* AttachmentViewController.swift in Sources */, 0411610022B442870030A9B7 /* AttachmentViewController.swift in Sources */,
D611C2CF232DC61100C86A49 /* HashtagTableViewCell.swift in Sources */, D611C2CF232DC61100C86A49 /* HashtagTableViewCell.swift in Sources */,
D627944F23A9C99800D38C68 /* EditListAccountsViewController.swift in Sources */,
D627943723A552C200D38C68 /* BookmarkStatusActivity.swift in Sources */, D627943723A552C200D38C68 /* BookmarkStatusActivity.swift in Sources */,
D62D2426217ABF63005076CC /* UserActivityType.swift in Sources */, D62D2426217ABF63005076CC /* UserActivityType.swift in Sources */,
D66362712136338600C9CBA2 /* ComposeViewController.swift in Sources */, D66362712136338600C9CBA2 /* ComposeViewController.swift in Sources */,
D6BC9DD7232D7811002CA326 /* TimelinesPageViewController.swift in Sources */, D6BC9DD7232D7811002CA326 /* TimelinesPageViewController.swift in Sources */,
D6028B9B2150811100F223B9 /* MastodonCache.swift in Sources */, D6028B9B2150811100F223B9 /* MastodonCache.swift in Sources */,
D6A3BC802321B7E600FD64D5 /* FollowNotificationGroupTableViewCell.swift in Sources */, D6A3BC802321B7E600FD64D5 /* FollowNotificationGroupTableViewCell.swift in Sources */,
D627944D23A9A03D00D38C68 /* ListTimelineViewController.swift in Sources */,
D62D2422217AA7E1005076CC /* UserActivityManager.swift in Sources */, D62D2422217AA7E1005076CC /* UserActivityManager.swift in Sources */,
D60D2B8223844C71001B87A3 /* BaseStatusTableViewCell.swift in Sources */, D60D2B8223844C71001B87A3 /* BaseStatusTableViewCell.swift in Sources */,
D62D2424217ABF3F005076CC /* NSUserActivity+Extensions.swift in Sources */, D62D2424217ABF3F005076CC /* NSUserActivity+Extensions.swift in Sources */,

View File

@ -8,15 +8,16 @@
import UIKit import UIKit
import Combine import Combine
import Pachyderm
class ExploreViewController: EnhancedTableViewController { class ExploreViewController: EnhancedTableViewController {
var dataSource: DataSource! var dataSource: UITableViewDiffableDataSource<Section, Item>!
var resultsController: SearchResultsViewController! var resultsController: SearchResultsViewController!
var searchController: UISearchController! var searchController: UISearchController!
let searchSubject = PassthroughSubject<String?, Never>()
init() { init() {
super.init(style: .insetGrouped) super.init(style: .insetGrouped)
@ -34,33 +35,26 @@ class ExploreViewController: EnhancedTableViewController {
tableView.register(UINib(nibName: "BasicTableViewCell", bundle: .main), forCellReuseIdentifier: "basicCell") tableView.register(UINib(nibName: "BasicTableViewCell", bundle: .main), forCellReuseIdentifier: "basicCell")
dataSource = DataSource(tableView: tableView, cellProvider: { (tableView, indexPath, item) -> UITableViewCell? in dataSource = DataSource(tableView: tableView, cellProvider: { (tableView, indexPath, item) -> UITableViewCell? in
let cell = tableView.dequeueReusableCell(withIdentifier: "basicCell", for: indexPath)
switch item { switch item {
case .bookmarks: case .bookmarks:
let cell = tableView.dequeueReusableCell(withIdentifier: "basicCell", for: indexPath)
cell.imageView!.image = UIImage(systemName: "bookmark.fill") cell.imageView!.image = UIImage(systemName: "bookmark.fill")
cell.textLabel!.text = NSLocalizedString("Bookmarks", comment: "bookmarks nav item title") cell.textLabel!.text = NSLocalizedString("Bookmarks", comment: "bookmarks nav item title")
cell.accessoryType = .disclosureIndicator cell.accessoryType = .disclosureIndicator
case let .list(list):
cell.imageView!.image = nil
cell.textLabel!.text = list.title
cell.accessoryType = .disclosureIndicator
case .addList:
cell.imageView!.image = UIImage(systemName: "plus")
cell.textLabel!.text = NSLocalizedString("New List...", comment: "new list nav item title")
cell.accessoryType = .none
}
return cell return cell
case let .list(id):
let cell = tableView.dequeueReusableCell(withIdentifier: "basicCell", for: indexPath)
cell.imageView!.image = nil
cell.textLabel!.text = id
cell.accessoryType = .disclosureIndicator
return cell
}
}) })
dataSource.exploreController = self
var snapshot = NSDiffableDataSourceSnapshot<Section, Item>() var snapshot = NSDiffableDataSourceSnapshot<Section, Item>()
snapshot.appendSections([.bookmarks, .lists]) snapshot.appendSections([.bookmarks, .lists])
snapshot.appendItems([.bookmarks], toSection: .bookmarks) snapshot.appendItems([.bookmarks], toSection: .bookmarks)
snapshot.appendItems([.addList], toSection: .lists)
// the initial, static items should not be displayed with an animation // the initial, static items should not be displayed with an animation
UIView.performWithoutAnimation { UIView.performWithoutAnimation {
dataSource.apply(snapshot) dataSource.apply(snapshot)
@ -76,26 +70,6 @@ class ExploreViewController: EnhancedTableViewController {
navigationItem.searchController = searchController navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = false navigationItem.hidesSearchBarWhenScrolling = false
reloadLists()
}
func reloadLists() {
let request = MastodonController.client.getLists()
MastodonController.client.run(request) { (response) in
guard case let .success(lists, _) = response else {
fatalError()
}
var snapshot = self.dataSource.snapshot()
snapshot.deleteSections([.lists])
snapshot.appendSections([.lists])
snapshot.appendItems(lists.map { .list($0) } + [.addList], toSection: .lists)
DispatchQueue.main.async {
self.dataSource.apply(snapshot)
}
}
} }
// MARK: - Table view delegate // MARK: - Table view delegate
@ -108,36 +82,9 @@ class ExploreViewController: EnhancedTableViewController {
case .bookmarks: case .bookmarks:
show(BookmarksTableViewController(), sender: nil) show(BookmarksTableViewController(), sender: nil)
case let .list(list): case let .list(id):
show(ListTimelineViewController(for: list), sender: nil) show(TimelineTableViewController(for: .list(id: id)), sender: nil)
case .addList:
tableView.selectRow(at: nil, animated: true, scrollPosition: .none)
let alert = UIAlertController(title: NSLocalizedString("New List", comment: "new list alert title"), message: NSLocalizedString("Choose a title for your new list", comment: "new list alert message"), preferredStyle: .alert)
alert.addTextField(configurationHandler: nil)
alert.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: "new list alert cancel button"), style: .cancel, handler: nil))
alert.addAction(UIAlertAction(title: NSLocalizedString("Create List", comment: "new list create button"), style: .default, handler: { (_) in
guard let title = alert.textFields?.first?.text else {
fatalError()
} }
let request = MastodonController.client.createList(title: title)
MastodonController.client.run(request) { (response) in
guard case let .success(list, _) = response else { fatalError() }
self.reloadLists()
DispatchQueue.main.async {
self.show(ListTimelineViewController(for: list), sender: nil)
}
}
}))
present(alert, animated: true)
}
}
override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
return .delete
} }
} }
@ -149,38 +96,9 @@ extension ExploreViewController {
} }
enum Item: Hashable { enum Item: Hashable {
case bookmarks case bookmarks
case list(List) case list(id: String)
case addList
static func == (lhs: ExploreViewController.Item, rhs: ExploreViewController.Item) -> Bool {
switch (lhs, rhs) {
case (.bookmarks, .bookmarks):
return true
case let (.list(a), .list(b)):
return a.id == b.id
case (.addList, .addList):
return true
default:
return false
} }
}
func hash(into hasher: inout Hasher) {
switch self {
case .bookmarks:
hasher.combine("bookmarks")
case let .list(list):
hasher.combine("list")
hasher.combine(list.id)
case .addList:
hasher.combine("addList")
}
}
}
class DataSource: UITableViewDiffableDataSource<Section, Item> { class DataSource: UITableViewDiffableDataSource<Section, Item> {
weak var exploreController: ExploreViewController?
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
switch section { switch section {
case 1: case 1:
@ -189,40 +107,5 @@ extension ExploreViewController {
return nil return nil
} }
} }
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
if case .list(_) = itemIdentifier(for: indexPath) {
return true
}
return false
}
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
guard editingStyle == .delete,
case let .list(list) = itemIdentifier(for: indexPath) else {
return
}
let title = String(format: NSLocalizedString("Are you sure want to delete the '%@' list?", comment: "delete list alert title"), list.title)
let alert = UIAlertController(title: title, message: nil, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: "delete list alert cancel button"), style: .cancel, handler: nil))
alert.addAction(UIAlertAction(title: NSLocalizedString("Delete List", comment: "delete list alert confirm button"), style: .destructive, handler: { (_) in
let request = List.delete(list)
MastodonController.client.run(request) { (response) in
guard case .success(_, _) = response else {
fatalError()
}
var snapshot = self.snapshot()
snapshot.deleteItems([.list(list)])
DispatchQueue.main.async {
self.apply(snapshot)
}
}
}))
self.exploreController?.present(alert, animated: true)
}
} }
} }

View File

@ -1,171 +0,0 @@
//
// EditListAccountsViewController.swift
// Tusker
//
// Created by Shadowfacts on 12/17/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
//
import UIKit
import Pachyderm
class EditListAccountsViewController: EnhancedTableViewController {
let list: List
var dataSource: DataSource!
var nextRange: RequestRange?
var searchResultsController: SearchResultsViewController!
var searchController: UISearchController!
init(list: List) {
self.list = list
super.init(style: .plain)
title = String(format: NSLocalizedString("Edit %@", comment: "edit list screen title"), list.title)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemeneted")
}
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UINib(nibName: "AccountTableViewCell", bundle: .main), forCellReuseIdentifier: "accountCell")
tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 66
dataSource = DataSource(tableView: tableView, cellProvider: { (tableView, indexPath, item) -> UITableViewCell? in
guard case let .account(id) = item else { fatalError() }
let cell = tableView.dequeueReusableCell(withIdentifier: "accountCell", for: indexPath) as! AccountTableViewCell
cell.updateUI(accountID: id)
return cell
})
dataSource.editListAccountsController = self
searchResultsController = SearchResultsViewController()
searchResultsController.delegate = self
searchResultsController.onlySections = [.accounts]
searchController = UISearchController(searchResultsController: searchResultsController)
searchController.hidesNavigationBarDuringPresentation = false
searchController.searchResultsUpdater = searchResultsController
searchController.searchBar.autocapitalizationType = .none
searchController.searchBar.placeholder = NSLocalizedString("Search for accounts to add", comment: "edit list search field placeholder")
searchController.searchBar.delegate = searchResultsController
definesPresentationContext = true
navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = false
navigationItem.rightBarButtonItem = UIBarButtonItem(title: NSLocalizedString("Rename", comment: "rename list button title"), style: .plain, target: self, action: #selector(renameButtonPressed))
loadAccounts()
}
func loadAccounts() {
let request = List.getAccounts(list)
MastodonController.client.run(request) { (response) in
guard case let .success(accounts, pagination) = response else {
fatalError()
}
self.nextRange = pagination?.older
MastodonCache.addAll(accounts: accounts)
var snapshot = self.dataSource.snapshot()
snapshot.deleteSections([.accounts])
snapshot.appendSections([.accounts])
snapshot.appendItems(accounts.map { .account(id: $0.id) })
DispatchQueue.main.async {
self.dataSource.apply(snapshot)
}
}
}
// MARK: - Table view delegate
override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
return .delete
}
// MARK: - Interaction
@objc func renameButtonPressed() {
let alert = UIAlertController(title: NSLocalizedString("Rename List", comment: "rename list alert title"), message: nil, preferredStyle: .alert)
alert.addTextField { (textField) in
textField.text = self.list.title
}
alert.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: "rename list alert cancel button"), style: .cancel, handler: nil))
alert.addAction(UIAlertAction(title: NSLocalizedString("Rename", comment: "renaem list alert rename button"), style: .default, handler: { (_) in
guard let text = alert.textFields?.first?.text else {
fatalError()
}
let request = List.update(self.list, title: text)
MastodonController.client.run(request) { (response) in
guard case .success(_, _) = response else {
fatalError()
}
// todo: show success message somehow
}
}))
present(alert, animated: true)
}
}
extension EditListAccountsViewController {
enum Section: Hashable {
case accounts
}
enum Item: Hashable {
case account(id: String)
}
class DataSource: UITableViewDiffableDataSource<Section, Item> {
weak var editListAccountsController: EditListAccountsViewController?
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
guard editingStyle == .delete,
case let .account(id) = itemIdentifier(for: indexPath) else {
return
}
let request = List.remove(editListAccountsController!.list, accounts: [id])
MastodonController.client.run(request) { (response) in
guard case .success(_, _) = response else {
fatalError()
}
self.editListAccountsController?.loadAccounts()
}
}
}
}
extension EditListAccountsViewController: SearchResultsViewControllerDelegate {
func selectedSearchResult(account accountID: String) {
let request = List.add(list, accounts: [accountID])
MastodonController.client.run(request) { (response) in
guard case .success(_, _) = response else {
fatalError()
}
self.loadAccounts()
DispatchQueue.main.async {
self.searchController.isActive = false
}
}
}
}

View File

@ -1,51 +0,0 @@
//
// ListTimelineViewController.swift
// Tusker
//
// Created by Shadowfacts on 12/17/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
//
import UIKit
import Pachyderm
class ListTimelineViewController: TimelineTableViewController {
let list: List
init(for list: List) {
self.list = list
super.init(for: .list(id: list.id))
title = list.title
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .edit, target: self, action: #selector(editButtonPressed))
}
// MARK: - Interaction
@objc func editButtonPressed() {
let editListAccountsController = EditListAccountsViewController(list: list)
editListAccountsController.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(doneButtonPressed))
let navController = UINavigationController(rootViewController: editListAccountsController)
present(navController, animated: true)
}
@objc func doneButtonPressed() {
dismiss(animated: true)
// todo: show loading indicator
timelineSegments = []
loadInitialStatuses()
}
}

View File

@ -14,29 +14,14 @@ fileprivate let accountCell = "accountCell"
fileprivate let statusCell = "statusCell" fileprivate let statusCell = "statusCell"
fileprivate let hashtagCell = "hashtagCell" fileprivate let hashtagCell = "hashtagCell"
protocol SearchResultsViewControllerDelegate: class {
func selectedSearchResult(account accountID: String)
func selectedSearchResult(hashtag: Hashtag)
func selectedSearchResult(status statusID: String)
}
extension SearchResultsViewControllerDelegate {
func selectedSearchResult(account accountID: String) {}
func selectedSearchResult(hashtag: Hashtag) {}
func selectedSearchResult(status statusID: String) {}
}
class SearchResultsViewController: EnhancedTableViewController { class SearchResultsViewController: EnhancedTableViewController {
weak var exploreNavigationController: UINavigationController? weak var exploreNavigationController: UINavigationController?
weak var delegate: SearchResultsViewControllerDelegate?
var dataSource: UITableViewDiffableDataSource<Section, Item>! var dataSource: UITableViewDiffableDataSource<Section, Item>!
var activityIndicator: UIActivityIndicatorView! var activityIndicator: UIActivityIndicatorView!
var onlySections: [Section] = Section.allCases
let searchSubject = PassthroughSubject<String?, Never>() let searchSubject = PassthroughSubject<String?, Never>()
var currentQuery: String? var currentQuery: String?
@ -129,16 +114,16 @@ class SearchResultsViewController: EnhancedTableViewController {
guard self.currentQuery == query else { return } guard self.currentQuery == query else { return }
var snapshot = NSDiffableDataSourceSnapshot<Section, Item>() var snapshot = NSDiffableDataSourceSnapshot<Section, Item>()
if self.onlySections.contains(.accounts) && !results.accounts.isEmpty { if !results.accounts.isEmpty {
snapshot.appendSections([.accounts]) snapshot.appendSections([.accounts])
snapshot.appendItems(results.accounts.map { .account($0.id) }, toSection: .accounts) snapshot.appendItems(results.accounts.map { .account($0.id) }, toSection: .accounts)
MastodonCache.addAll(accounts: results.accounts) MastodonCache.addAll(accounts: results.accounts)
} }
if self.onlySections.contains(.hashtags) && !results.hashtags.isEmpty { if !results.hashtags.isEmpty {
snapshot.appendSections([.hashtags]) snapshot.appendSections([.hashtags])
snapshot.appendItems(results.hashtags.map { .hashtag($0) }, toSection: .hashtags) snapshot.appendItems(results.hashtags.map { .hashtag($0) }, toSection: .hashtags)
} }
if self.onlySections.contains(.statuses) && !results.statuses.isEmpty { if !results.statuses.isEmpty {
snapshot.appendSections([.statuses]) snapshot.appendSections([.statuses])
snapshot.appendItems(results.statuses.map { .status($0.id, .unknown) }, toSection: .statuses) snapshot.appendItems(results.statuses.map { .status($0.id, .unknown) }, toSection: .statuses)
MastodonCache.addAll(statuses: results.statuses) MastodonCache.addAll(statuses: results.statuses)
@ -148,25 +133,6 @@ class SearchResultsViewController: EnhancedTableViewController {
} }
} }
// MARK: - Table view delegate
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let delegate = delegate {
switch dataSource.itemIdentifier(for: indexPath) {
case nil:
return
case let .account(id):
delegate.selectedSearchResult(account: id)
case let .hashtag(hashtag):
delegate.selectedSearchResult(hashtag: hashtag)
case let .status(id, _):
delegate.selectedSearchResult(status: id)
}
} else {
super.tableView(tableView, didSelectRowAt: indexPath)
}
}
} }
extension SearchResultsViewController { extension SearchResultsViewController {

View File

@ -70,10 +70,6 @@ class TimelineTableViewController: EnhancedTableViewController {
tableView.prefetchDataSource = self tableView.prefetchDataSource = self
guard MastodonController.client?.accessToken != nil else { return } guard MastodonController.client?.accessToken != nil else { return }
loadInitialStatuses()
}
func loadInitialStatuses() {
let request = MastodonController.client.getStatuses(timeline: timeline) let request = MastodonController.client.getStatuses(timeline: timeline)
MastodonController.client.run(request) { response in MastodonController.client.run(request) { response in
guard case let .success(statuses, pagination) = response else { fatalError() } guard case let .success(statuses, pagination) = response else { fatalError() }

View File

@ -1,15 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="15701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14865.1" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/> <device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies> <dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15703"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14819.2"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/> <capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
<objects> <objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/> <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="KGk-i7-Jjw" customClass="AccountTableViewCell" customModule="Tusker" customModuleProvider="target"> <tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="66" id="KGk-i7-Jjw" customClass="AccountTableViewCell" customModule="Tusker" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="320" height="66"/> <rect key="frame" x="0.0" y="0.0" width="320" height="66"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM"> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
@ -19,8 +19,8 @@
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Rp2-O5-Vew"> <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Rp2-O5-Vew">
<rect key="frame" x="16" y="8" width="50" height="50"/> <rect key="frame" x="16" y="8" width="50" height="50"/>
<constraints> <constraints>
<constraint firstAttribute="width" secondItem="Rp2-O5-Vew" secondAttribute="height" multiplier="1:1" id="1AQ-lU-ptd"/> <constraint firstAttribute="height" constant="50" id="NqI-m0-owe"/>
<constraint firstAttribute="height" priority="999" constant="50" id="NqI-m0-owe"/> <constraint firstAttribute="width" constant="50" id="lar-P0-gRh"/>
</constraints> </constraints>
</imageView> </imageView>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="Iif-9m-vM5"> <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="Iif-9m-vM5">