Compare commits

..

4 Commits

6 changed files with 30 additions and 22 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?) {
return try await withCheckedThrowingContinuation({ continuation in let result: (Result, Pagination?) = 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,6 +78,8 @@ 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,7 +234,6 @@ 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 {
unowned var owner: ProfileViewController weak var owner: ProfileViewController?
var mastodonController: MastodonController { owner.mastodonController } let mastodonController: MastodonController
private(set) var accountID: String! private(set) var accountID: String!
let kind: Kind let kind: Kind
var initialHeaderMode: HeaderMode? var initialHeaderMode: HeaderMode?
@ -37,6 +37,7 @@ 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)
@ -130,7 +131,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 elementHandler in UIDeferredMenuElement.uncached({ @MainActor [unowned self] elementHandler in
let relationship = Task { let relationship = Task {
await self.fetchRelationship(accountID: accountID, mastodonController: mastodonController) await 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,19 +392,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)
}
}
}
@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,
@ -433,6 +420,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)
}
}
}
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,6 +65,8 @@ 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))
@ -85,6 +87,8 @@ 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
@ -113,6 +117,8 @@ 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 self = self, guard let mastodonController = self?.mastodonController,
case let .success(results, _) = response, case let .success(results, _) = response,
let relationship = results.first else { let relationship = results.first else {
return return
} }
self.mastodonController.persistentContainer.addOrUpdate(relationship: relationship) mastodonController.persistentContainer.addOrUpdate(relationship: relationship)
} }
} }