Compare commits
3 Commits
361ce456cf
...
126e8c8858
Author | SHA1 | Date |
---|---|---|
Shadowfacts | 126e8c8858 | |
Shadowfacts | dbc89509d7 | |
Shadowfacts | 0ba38e4a3a |
|
@ -11,6 +11,13 @@ import Pachyderm
|
||||||
import WebURL
|
import WebURL
|
||||||
import WebURLFoundationExtras
|
import WebURLFoundationExtras
|
||||||
|
|
||||||
|
private let mastodonRemoteStatusRegex = try! NSRegularExpression(pattern: "^/@.+@.+/\\d{18}")
|
||||||
|
private func isLikelyMastodonRemoteStatus(url: URL) -> Bool {
|
||||||
|
let path = url.path
|
||||||
|
let range = NSRange(location: 0, length: path.utf16.count)
|
||||||
|
return mastodonRemoteStatusRegex.numberOfMatches(in: path, range: range) == 1
|
||||||
|
}
|
||||||
|
|
||||||
class ConversationViewController: UIViewController {
|
class ConversationViewController: UIViewController {
|
||||||
|
|
||||||
weak var mastodonController: MastodonController!
|
weak var mastodonController: MastodonController!
|
||||||
|
@ -210,11 +217,24 @@ class ConversationViewController: UIViewController {
|
||||||
indicator.startAnimating()
|
indicator.startAnimating()
|
||||||
state = .loading(indicator)
|
state = .loading(indicator)
|
||||||
|
|
||||||
let url = WebURL(url)!.serialized(excludingFragment: true)
|
let effectiveURL: String
|
||||||
let request = Client.search(query: url, types: [.statuses], resolve: true)
|
class RedirectBlocker: NSObject, URLSessionTaskDelegate {
|
||||||
|
func urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest, completionHandler: @escaping (URLRequest?) -> Void) {
|
||||||
|
completionHandler(nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if isLikelyMastodonRemoteStatus(url: url),
|
||||||
|
let (_, response) = try? await URLSession.shared.data(from: url, delegate: RedirectBlocker()),
|
||||||
|
let location = (response as? HTTPURLResponse)?.value(forHTTPHeaderField: "location") {
|
||||||
|
effectiveURL = location
|
||||||
|
} else {
|
||||||
|
effectiveURL = WebURL(url)!.serialized(excludingFragment: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
let request = Client.search(query: effectiveURL, types: [.statuses], resolve: true)
|
||||||
do {
|
do {
|
||||||
let (results, _) = try await mastodonController.run(request)
|
let (results, _) = try await mastodonController.run(request)
|
||||||
guard let status = results.statuses.first(where: { $0.url?.serialized() == url }) else {
|
guard let status = results.statuses.first(where: { $0.url?.serialized() == effectiveURL }) else {
|
||||||
throw UnableToResolveError()
|
throw UnableToResolveError()
|
||||||
}
|
}
|
||||||
_ = mastodonController.persistentContainer.addOrUpdateOnViewContext(status: status)
|
_ = mastodonController.persistentContainer.addOrUpdateOnViewContext(status: status)
|
||||||
|
|
|
@ -144,7 +144,15 @@ class ExpandThreadCollectionViewCell: UICollectionViewListCell {
|
||||||
}
|
}
|
||||||
|
|
||||||
override func updateConfiguration(using state: UICellConfigurationState) {
|
override func updateConfiguration(using state: UICellConfigurationState) {
|
||||||
backgroundConfiguration = .appListPlainCell(for: state)
|
var config = UIBackgroundConfiguration.listGroupedCell().updated(for: state)
|
||||||
|
if state.isFocused {
|
||||||
|
// use default
|
||||||
|
} else if state.isHighlighted || state.isSelected {
|
||||||
|
config.backgroundColor = .appSelectedCellBackground
|
||||||
|
} else {
|
||||||
|
config.backgroundColor = .appSecondaryBackground
|
||||||
|
}
|
||||||
|
backgroundConfiguration = config
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,6 +115,14 @@ class MainSplitViewController: UISplitViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func show(_ vc: UIViewController, sender: Any?) {
|
||||||
|
if traitCollection.horizontalSizeClass == .regular {
|
||||||
|
secondaryNavController.show(vc, sender: sender)
|
||||||
|
} else {
|
||||||
|
super.show(vc, sender: sender)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@objc func handleSidebarCommandTimelines() {
|
@objc func handleSidebarCommandTimelines() {
|
||||||
sidebar.select(item: .tab(.timelines), animated: false)
|
sidebar.select(item: .tab(.timelines), animated: false)
|
||||||
select(item: .tab(.timelines))
|
select(item: .tab(.timelines))
|
||||||
|
|
|
@ -305,9 +305,11 @@ private class SplitSecondaryNavigationController: EnhancedNavigationViewControll
|
||||||
}
|
}
|
||||||
|
|
||||||
override func pushViewController(_ viewController: UIViewController, animated: Bool) {
|
override func pushViewController(_ viewController: UIViewController, animated: Bool) {
|
||||||
super.pushViewController(viewController, animated: animated)
|
if viewControllers.isEmpty {
|
||||||
|
configureSecondarySplitCloseButton(for: viewController)
|
||||||
|
}
|
||||||
|
|
||||||
configureSecondarySplitCloseButton(for: viewControllers.first!)
|
super.pushViewController(viewController, animated: animated)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func configureSecondarySplitCloseButton(for viewController: UIViewController) {
|
private func configureSecondarySplitCloseButton(for viewController: UIViewController) {
|
||||||
|
|
|
@ -205,6 +205,7 @@ enum PopoverSource {
|
||||||
private let statusPathRegex = try! NSRegularExpression(
|
private let statusPathRegex = try! NSRegularExpression(
|
||||||
pattern:
|
pattern:
|
||||||
"(^/@[a-z0-9_]+/\\d{18})" // mastodon
|
"(^/@[a-z0-9_]+/\\d{18})" // mastodon
|
||||||
|
+ "|(^/@.+@.+/\\d{18})" // mastodon remote
|
||||||
+ "|(^/notice/[a-z0-9]{18})" // pleroma
|
+ "|(^/notice/[a-z0-9]{18})" // pleroma
|
||||||
+ "|(^/notes/[a-z0-9]{10})" // misskey
|
+ "|(^/notes/[a-z0-9]{10})" // misskey
|
||||||
+ "|(^/p/[a-z0-9_]+/\\d{18})" // pixelfed
|
+ "|(^/p/[a-z0-9_]+/\\d{18})" // pixelfed
|
||||||
|
|
Loading…
Reference in New Issue