parent
71fa3910a1
commit
266868376d
|
@ -9,8 +9,9 @@
|
||||||
import UIKit
|
import UIKit
|
||||||
import Pachyderm
|
import Pachyderm
|
||||||
|
|
||||||
class ConversationCollectionViewController: UIViewController, CollectionViewController {
|
class ConversationCollectionViewController: UIViewController, CollectionViewController, RefreshableViewController {
|
||||||
|
|
||||||
|
private unowned let conversationViewController: ConversationViewController
|
||||||
private let mastodonController: MastodonController
|
private let mastodonController: MastodonController
|
||||||
private let mainStatusID: String
|
private let mainStatusID: String
|
||||||
private let mainStatusState: CollapseState
|
private let mainStatusState: CollapseState
|
||||||
|
@ -22,11 +23,12 @@ class ConversationCollectionViewController: UIViewController, CollectionViewCont
|
||||||
}
|
}
|
||||||
private var dataSource: UICollectionViewDiffableDataSource<Section, Item>!
|
private var dataSource: UICollectionViewDiffableDataSource<Section, Item>!
|
||||||
|
|
||||||
init(for mainStatusID: String, state: CollapseState, mastodonController: MastodonController) {
|
init(for mainStatusID: String, state: CollapseState, conversationViewController: ConversationViewController) {
|
||||||
self.mainStatusID = mainStatusID
|
self.mainStatusID = mainStatusID
|
||||||
self.mainStatusState = state
|
self.mainStatusState = state
|
||||||
self.statusIDToScrollToOnLoad = mainStatusID
|
self.statusIDToScrollToOnLoad = mainStatusID
|
||||||
self.mastodonController = mastodonController
|
self.conversationViewController = conversationViewController
|
||||||
|
self.mastodonController = conversationViewController.mastodonController
|
||||||
|
|
||||||
super.init(nibName: nil, bundle: nil)
|
super.init(nibName: nil, bundle: nil)
|
||||||
}
|
}
|
||||||
|
@ -68,6 +70,11 @@ class ConversationCollectionViewController: UIViewController, CollectionViewCont
|
||||||
collectionView.dragDelegate = self
|
collectionView.dragDelegate = self
|
||||||
collectionView.allowsFocus = true
|
collectionView.allowsFocus = true
|
||||||
|
|
||||||
|
#if !targetEnvironment(macCatalyst)
|
||||||
|
collectionView.refreshControl = UIRefreshControl()
|
||||||
|
collectionView.refreshControl!.addTarget(self, action: #selector(refresh), for: .valueChanged)
|
||||||
|
#endif
|
||||||
|
|
||||||
dataSource = createDataSource()
|
dataSource = createDataSource()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,9 +139,10 @@ class ConversationCollectionViewController: UIViewController, CollectionViewCont
|
||||||
}
|
}
|
||||||
|
|
||||||
func addTree(_ tree: ConversationTree, mainStatus: StatusMO) {
|
func addTree(_ tree: ConversationTree, mainStatus: StatusMO) {
|
||||||
var snapshot = dataSource.snapshot()
|
var snapshot = NSDiffableDataSourceSnapshot<Section, Item>()
|
||||||
snapshot.deleteItems([.loadingIndicator])
|
snapshot.appendSections([.ancestors, .mainStatus])
|
||||||
let mainStatusItem = Item.status(id: mainStatusID, node: tree.mainStatus, state: mainStatusState, prevLink: mainStatus.inReplyToID != nil, nextLink: false)
|
let mainStatusItem = Item.status(id: mainStatusID, node: tree.mainStatus, state: mainStatusState, prevLink: mainStatus.inReplyToID != nil, nextLink: false)
|
||||||
|
snapshot.appendItems([mainStatusItem], toSection: .mainStatus)
|
||||||
let parentItems = tree.ancestors.enumerated().map { index, node in
|
let parentItems = tree.ancestors.enumerated().map { index, node in
|
||||||
Item.status(id: node.status.id, node: node, state: .unknown, prevLink: index > 0, nextLink: true)
|
Item.status(id: node.status.id, node: node, state: .unknown, prevLink: index > 0, nextLink: true)
|
||||||
}
|
}
|
||||||
|
@ -240,6 +248,15 @@ class ConversationCollectionViewController: UIViewController, CollectionViewCont
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc func refresh() {
|
||||||
|
Task {
|
||||||
|
await conversationViewController.refreshContext()
|
||||||
|
#if !targetEnvironment(macCatalyst)
|
||||||
|
self.collectionView.refreshControl!.endRefreshing()
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension ConversationCollectionViewController {
|
extension ConversationCollectionViewController {
|
||||||
|
|
|
@ -227,7 +227,7 @@ class ConversationViewController: UIViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private func mainStatusLoaded(_ mainStatus: StatusMO) {
|
private func mainStatusLoaded(_ mainStatus: StatusMO) {
|
||||||
let vc = ConversationCollectionViewController(for: mainStatus.id, state: mainStatusState, mastodonController: mastodonController)
|
let vc = ConversationCollectionViewController(for: mainStatus.id, state: mainStatusState, conversationViewController: self)
|
||||||
vc.statusIDToScrollToOnLoad = statusIDToScrollToOnLoad ?? mainStatus.id
|
vc.statusIDToScrollToOnLoad = statusIDToScrollToOnLoad ?? mainStatus.id
|
||||||
vc.showStatusesAutomatically = showStatusesAutomatically
|
vc.showStatusesAutomatically = showStatusesAutomatically
|
||||||
vc.addMainStatus(mainStatus)
|
vc.addMainStatus(mainStatus)
|
||||||
|
@ -290,6 +290,15 @@ class ConversationViewController: UIViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func refreshContext() async {
|
||||||
|
guard case .localID(let id) = mode,
|
||||||
|
let status = mastodonController.persistentContainer.status(for: id),
|
||||||
|
case .displaying(_) = state else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await loadTree(for: status)
|
||||||
|
}
|
||||||
|
|
||||||
private func showMainStatusNotFound() {
|
private func showMainStatusNotFound() {
|
||||||
let notFoundView = StatusNotFoundView(frame: .zero)
|
let notFoundView = StatusNotFoundView(frame: .zero)
|
||||||
notFoundView.translatesAutoresizingMaskIntoConstraints = false
|
notFoundView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
|
Loading…
Reference in New Issue