parent
8b0c2f80b6
commit
90537f9d12
|
@ -221,10 +221,16 @@ class ConversationViewController: UIViewController {
|
||||||
completionHandler(nil)
|
completionHandler(nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if isLikelyMastodonRemoteStatus(url: url),
|
if isLikelyMastodonRemoteStatus(url: url) {
|
||||||
let (_, response) = try? await URLSession.appDefault.data(from: url, delegate: RedirectBlocker()),
|
var request = URLRequest(url: url)
|
||||||
let location = (response as? HTTPURLResponse)?.value(forHTTPHeaderField: "location") {
|
// Mastodon uses an intermediate redirect page for browsers which requires user input that we don't want.
|
||||||
effectiveURL = location
|
request.addValue("application/activity+json", forHTTPHeaderField: "accept")
|
||||||
|
if let (_, response) = try? await URLSession.appDefault.data(for: request, delegate: RedirectBlocker()),
|
||||||
|
let location = (response as? HTTPURLResponse)?.value(forHTTPHeaderField: "location") {
|
||||||
|
effectiveURL = location
|
||||||
|
} else {
|
||||||
|
effectiveURL = WebURL(url)!.serialized(excludingFragment: true)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
effectiveURL = WebURL(url)!.serialized(excludingFragment: true)
|
effectiveURL = WebURL(url)!.serialized(excludingFragment: true)
|
||||||
}
|
}
|
||||||
|
@ -232,9 +238,14 @@ class ConversationViewController: UIViewController {
|
||||||
let request = Client.search(query: effectiveURL, types: [.statuses], resolve: 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.compactMap(\.value).first(where: { $0.url?.serialized() == effectiveURL }) else {
|
let statuses = results.statuses.compactMap(\.value)
|
||||||
|
// Don't try to exactly match effective URL because the URL form Mastodon
|
||||||
|
// uses for the ActivityPub redirect doesn't match what's returned by the API.
|
||||||
|
// Instead we just assume that, if only one status was returned, it worked.
|
||||||
|
guard statuses.count == 1 else {
|
||||||
throw UnableToResolveError()
|
throw UnableToResolveError()
|
||||||
}
|
}
|
||||||
|
let status = statuses[0]
|
||||||
_ = mastodonController.persistentContainer.addOrUpdateOnViewContext(status: status)
|
_ = mastodonController.persistentContainer.addOrUpdateOnViewContext(status: status)
|
||||||
mode = .localID(status.id)
|
mode = .localID(status.id)
|
||||||
return status.id
|
return status.id
|
||||||
|
|
Loading…
Reference in New Issue