Add tapping mentions to show profiles

This commit is contained in:
Shadowfacts 2018-09-30 21:12:23 -04:00
parent c5937acaa4
commit 089dda8e90
3 changed files with 55 additions and 17 deletions

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14313.13.2" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="HMn-Wn-5Ab">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.15" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="HMn-Wn-5Ab">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.9"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.9"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>

View File

@ -31,11 +31,6 @@ class ProfileTableViewController: UITableViewController, PreferencesAdaptive {
var older: RequestRange?
var newer: RequestRange?
func getStatuses(for range: RequestRange = .default, completion: @escaping Client.Callback<[Status]>) {
let request = Account.getStatuses(accountID, range: range, onlyMedia: false, pinned: false, excludeReplies: !Preferences.shared.showRepliesInProfiles)
MastodonController.shared.client.run(request, completion: completion)
}
override func viewDidLoad() {
super.viewDidLoad()
@ -45,14 +40,33 @@ class ProfileTableViewController: UITableViewController, PreferencesAdaptive {
tableView.register(UINib(nibName: "StatusTableViewCell", bundle: nil), forCellReuseIdentifier: "statusCell")
tableView.register(UINib(nibName: "ProfileHeaderTableViewCell", bundle: nil), forCellReuseIdentifier: "headerCell")
updateUIForPreferences()
getStatuses { response in
guard case let .success(statuses, pagination) = response else { fatalError() }
MastodonCache.addAll(statuses: statuses)
self.statusIDs = statuses.map { $0.id }
self.older = pagination?.older
self.newer = pagination?.newer
if MastodonCache.account(for: accountID) != nil {
updateAccountUI()
} else {
let activityIndicator = UIActivityIndicatorView(style: .whiteLarge)
activityIndicator.color = .darkGray
activityIndicator.startAnimating()
activityIndicator.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(activityIndicator)
activityIndicator.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor)
activityIndicator.centerYAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerYAnchor)
MastodonCache.account(for: accountID) { (account) in
guard account != nil else {
let alert = UIAlertController(title: "Something Went Wrong", message: "Couldn't load the selected account", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (_) in
self.navigationController!.popViewController(animated: true)
}))
DispatchQueue.main.async {
self.present(alert, animated: true)
}
return
}
DispatchQueue.main.async {
activityIndicator.removeFromSuperview()
self.updateAccountUI()
self.tableView.reloadData()
}
}
}
}
@ -64,7 +78,22 @@ class ProfileTableViewController: UITableViewController, PreferencesAdaptive {
cell.updateUIForPreferences()
}
}
if MastodonCache.account(for: accountID) != nil {
updateUIForPreferences()
}
}
func updateAccountUI() {
updateUIForPreferences()
getStatuses() { response in
guard case let .success(statuses, pagination) = response else { fatalError() }
MastodonCache.addAll(statuses: statuses)
self.statusIDs = statuses.map { $0.id }
self.older = pagination?.older
self.newer = pagination?.newer
}
}
func updateUIForPreferences() {
@ -72,6 +101,11 @@ class ProfileTableViewController: UITableViewController, PreferencesAdaptive {
navigationItem.title = account.realDisplayName
}
func getStatuses(for range: RequestRange = .default, completion: @escaping Client.Callback<[Status]>) {
let request = Account.getStatuses(accountID, range: range, onlyMedia: false, pinned: false, excludeReplies: !Preferences.shared.showRepliesInProfiles)
MastodonController.shared.client.run(request, completion: completion)
}
func sendMessageMentioning() {
guard let account = MastodonCache.account(for: accountID) else { fatalError("Missing cached account \(accountID!)") }
let vc = ComposeViewController.create(mentioning: account.acct)
@ -97,7 +131,7 @@ class ProfileTableViewController: UITableViewController, PreferencesAdaptive {
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch section {
case 0:
return 1
return MastodonCache.account(for: accountID) == nil ? 0 : 1
case 1:
return statusIDs.count
default:

View File

@ -45,7 +45,11 @@ extension TuskerNavigationDelegate where Self: UIViewController {
}
func selected(mention: Mention) {
guard let navigationController = navigationController else {
fatalError("Can't show profile VC from mention when not in navigation controller")
}
let vc = ProfileTableViewController.create(for: mention.id)
navigationController.pushViewController(vc, animated: true)
}
func selected(tag: Hashtag) {