Compare commits

..

No commits in common. "7bdbd9f71a9d1e01aad7181b3f9bd0940d7003af" and "c7f3bac3305caedd99a60f4994b069fd29e51db8" have entirely different histories.

6 changed files with 22 additions and 30 deletions

View File

@ -68,7 +68,7 @@ class MastodonController: ObservableObject {
} }
func run<Result>(_ request: Request<Result>) async throws -> (Result, Pagination?) { func run<Result>(_ request: Request<Result>) async throws -> (Result, Pagination?) {
let result: (Result, Pagination?) = try await withCheckedThrowingContinuation({ continuation in return try await withCheckedThrowingContinuation({ continuation in
client.run(request) { response in client.run(request) { response in
switch response { switch response {
case .failure(let error): case .failure(let error):
@ -78,8 +78,6 @@ class MastodonController: ObservableObject {
} }
} }
}) })
try Task.checkCancellation()
return result
} }
/// - Returns: A tuple of client ID and client secret. /// - Returns: A tuple of client ID and client secret.

View File

@ -234,6 +234,7 @@ struct SheetOrPopover<V: View>: ViewModifier {
@Environment(\.horizontalSizeClass) var sizeClass @Environment(\.horizontalSizeClass) var sizeClass
func body(content: Content) -> some View { func body(content: Content) -> some View {
let _ = print("isPresented: \(isPresented)")
if sizeClass == .compact { if sizeClass == .compact {
content.sheet(isPresented: $isPresented, content: view) content.sheet(isPresented: $isPresented, content: view)
} else { } else {

View File

@ -12,8 +12,8 @@ import Combine
class ProfileStatusesViewController: UIViewController, TimelineLikeCollectionViewController { class ProfileStatusesViewController: UIViewController, TimelineLikeCollectionViewController {
weak var owner: ProfileViewController? unowned var owner: ProfileViewController
let mastodonController: MastodonController var mastodonController: MastodonController { owner.mastodonController }
private(set) var accountID: String! private(set) var accountID: String!
let kind: Kind let kind: Kind
var initialHeaderMode: HeaderMode? var initialHeaderMode: HeaderMode?
@ -37,7 +37,6 @@ class ProfileStatusesViewController: UIViewController, TimelineLikeCollectionVie
self.accountID = accountID self.accountID = accountID
self.kind = kind self.kind = kind
self.owner = owner self.owner = owner
self.mastodonController = owner.mastodonController
super.init(nibName: nil, bundle: nil) super.init(nibName: nil, bundle: nil)
@ -131,7 +130,7 @@ class ProfileStatusesViewController: UIViewController, TimelineLikeCollectionVie
let view = ProfileHeaderView.create() let view = ProfileHeaderView.create()
view.delegate = self.profileHeaderDelegate view.delegate = self.profileHeaderDelegate
view.updateUI(for: id) view.updateUI(for: id)
view.pagesSegmentedControl.selectedSegmentIndex = self.owner?.currentIndex ?? 0 view.pagesSegmentedControl.selectedSegmentIndex = self.owner.currentIndex ?? 0
cell.addHeader(view) cell.addHeader(view)
case .placeholder(height: let height): case .placeholder(height: let height):
_ = cell.addConstraint(height: height) _ = cell.addConstraint(height: height)

View File

@ -60,9 +60,9 @@ extension MenuActionProvider {
draft.visibility = .direct draft.visibility = .direct
self.navigationDelegate?.compose(editing: draft) self.navigationDelegate?.compose(editing: draft)
}), }),
UIDeferredMenuElement.uncached({ @MainActor [unowned self] elementHandler in UIDeferredMenuElement.uncached({ @MainActor elementHandler in
let relationship = Task { let relationship = Task {
await fetchRelationship(accountID: accountID, mastodonController: mastodonController) await self.fetchRelationship(accountID: accountID, mastodonController: mastodonController)
} }
// workaround for #198, may result in showing outdated relationship, so only do so where necessary // workaround for #198, may result in showing outdated relationship, so only do so where necessary
if ProcessInfo.processInfo.isiOSAppOnMac, if ProcessInfo.processInfo.isiOSAppOnMac,
@ -392,6 +392,19 @@ extension MenuActionProvider {
}) })
} }
private func fetchRelationship(accountID: String, mastodonController: MastodonController) async -> RelationshipMO? {
let req = Client.getRelationships(accounts: [accountID])
guard let (relationships, _) = try? await mastodonController.run(req),
let r = relationships.first else {
return nil
}
return await withCheckedContinuation { continuation in
mastodonController.persistentContainer.addOrUpdate(relationship: r, in: mastodonController.persistentContainer.viewContext) { mo in
continuation.resume(returning: mo)
}
}
}
@MainActor @MainActor
private func followAction(for relationship: RelationshipMO, mastodonController: MastodonController) -> UIMenuElement? { private func followAction(for relationship: RelationshipMO, mastodonController: MastodonController) -> UIMenuElement? {
guard let ownAccount = mastodonController.account, guard let ownAccount = mastodonController.account,
@ -420,19 +433,6 @@ extension MenuActionProvider {
} }
private func fetchRelationship(accountID: String, mastodonController: MastodonController) async -> RelationshipMO? {
let req = Client.getRelationships(accounts: [accountID])
guard let (relationships, _) = try? await mastodonController.run(req),
let r = relationships.first else {
return nil
}
return await withCheckedContinuation { continuation in
mastodonController.persistentContainer.addOrUpdate(relationship: r, in: mastodonController.persistentContainer.viewContext) { mo in
continuation.resume(returning: mo)
}
}
}
struct MenuPreviewHelper { struct MenuPreviewHelper {
static func willPerformPreviewAction(animator: UIContextMenuInteractionCommitAnimating, presenter: UIViewController) { static func willPerformPreviewAction(animator: UIContextMenuInteractionCommitAnimating, presenter: UIViewController) {
if let viewController = animator.previewViewController { if let viewController = animator.previewViewController {

View File

@ -65,8 +65,6 @@ actor TimelineLikeController<Item> {
await loadingIndicator.end() await loadingIndicator.end()
await emit(event: .replaceAllItems(items, token)) await emit(event: .replaceAllItems(items, token))
state = .idle state = .idle
} catch is CancellationError {
return
} catch { } catch {
await loadingIndicator.end() await loadingIndicator.end()
await emit(event: .loadAllError(error, token)) await emit(event: .loadAllError(error, token))
@ -87,8 +85,6 @@ actor TimelineLikeController<Item> {
} }
await emit(event: .prependItems(items, token)) await emit(event: .prependItems(items, token))
state = .idle state = .idle
} catch is CancellationError {
return
} catch { } catch {
await emit(event: .loadNewerError(error, token)) await emit(event: .loadNewerError(error, token))
state = .idle state = .idle
@ -117,8 +113,6 @@ actor TimelineLikeController<Item> {
await loadingIndicator.end() await loadingIndicator.end()
await emit(event: .appendItems(items, token)) await emit(event: .appendItems(items, token))
state = .idle state = .idle
} catch is CancellationError {
return
} catch { } catch {
await loadingIndicator.end() await loadingIndicator.end()
await emit(event: .loadOlderError(error, token)) await emit(event: .loadOlderError(error, token))

View File

@ -119,12 +119,12 @@ class ProfileHeaderView: UIView {
let request = Client.getRelationships(accounts: [accountID]) let request = Client.getRelationships(accounts: [accountID])
mastodonController.run(request) { [weak self] (response) in mastodonController.run(request) { [weak self] (response) in
guard let mastodonController = self?.mastodonController, guard let self = self,
case let .success(results, _) = response, case let .success(results, _) = response,
let relationship = results.first else { let relationship = results.first else {
return return
} }
mastodonController.persistentContainer.addOrUpdate(relationship: relationship) self.mastodonController.persistentContainer.addOrUpdate(relationship: relationship)
} }
} }