Compare commits
4 Commits
c7f3bac330
...
7bdbd9f71a
Author | SHA1 | Date |
---|---|---|
Shadowfacts | 7bdbd9f71a | |
Shadowfacts | b47876dc3d | |
Shadowfacts | 4644475bc7 | |
Shadowfacts | 16ba292afa |
|
@ -68,7 +68,7 @@ class MastodonController: ObservableObject {
|
|||
}
|
||||
|
||||
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
|
||||
switch response {
|
||||
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.
|
||||
|
|
|
@ -234,7 +234,6 @@ struct SheetOrPopover<V: View>: ViewModifier {
|
|||
@Environment(\.horizontalSizeClass) var sizeClass
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
let _ = print("isPresented: \(isPresented)")
|
||||
if sizeClass == .compact {
|
||||
content.sheet(isPresented: $isPresented, content: view)
|
||||
} else {
|
||||
|
|
|
@ -12,8 +12,8 @@ import Combine
|
|||
|
||||
class ProfileStatusesViewController: UIViewController, TimelineLikeCollectionViewController {
|
||||
|
||||
unowned var owner: ProfileViewController
|
||||
var mastodonController: MastodonController { owner.mastodonController }
|
||||
weak var owner: ProfileViewController?
|
||||
let mastodonController: MastodonController
|
||||
private(set) var accountID: String!
|
||||
let kind: Kind
|
||||
var initialHeaderMode: HeaderMode?
|
||||
|
@ -37,6 +37,7 @@ class ProfileStatusesViewController: UIViewController, TimelineLikeCollectionVie
|
|||
self.accountID = accountID
|
||||
self.kind = kind
|
||||
self.owner = owner
|
||||
self.mastodonController = owner.mastodonController
|
||||
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
|
||||
|
@ -130,7 +131,7 @@ class ProfileStatusesViewController: UIViewController, TimelineLikeCollectionVie
|
|||
let view = ProfileHeaderView.create()
|
||||
view.delegate = self.profileHeaderDelegate
|
||||
view.updateUI(for: id)
|
||||
view.pagesSegmentedControl.selectedSegmentIndex = self.owner.currentIndex ?? 0
|
||||
view.pagesSegmentedControl.selectedSegmentIndex = self.owner?.currentIndex ?? 0
|
||||
cell.addHeader(view)
|
||||
case .placeholder(height: let height):
|
||||
_ = cell.addConstraint(height: height)
|
||||
|
|
|
@ -60,9 +60,9 @@ extension MenuActionProvider {
|
|||
draft.visibility = .direct
|
||||
self.navigationDelegate?.compose(editing: draft)
|
||||
}),
|
||||
UIDeferredMenuElement.uncached({ @MainActor elementHandler in
|
||||
UIDeferredMenuElement.uncached({ @MainActor [unowned self] elementHandler in
|
||||
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
|
||||
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
|
||||
private func followAction(for relationship: RelationshipMO, mastodonController: MastodonController) -> UIMenuElement? {
|
||||
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 {
|
||||
static func willPerformPreviewAction(animator: UIContextMenuInteractionCommitAnimating, presenter: UIViewController) {
|
||||
if let viewController = animator.previewViewController {
|
||||
|
|
|
@ -65,6 +65,8 @@ actor TimelineLikeController<Item> {
|
|||
await loadingIndicator.end()
|
||||
await emit(event: .replaceAllItems(items, token))
|
||||
state = .idle
|
||||
} catch is CancellationError {
|
||||
return
|
||||
} catch {
|
||||
await loadingIndicator.end()
|
||||
await emit(event: .loadAllError(error, token))
|
||||
|
@ -85,6 +87,8 @@ actor TimelineLikeController<Item> {
|
|||
}
|
||||
await emit(event: .prependItems(items, token))
|
||||
state = .idle
|
||||
} catch is CancellationError {
|
||||
return
|
||||
} catch {
|
||||
await emit(event: .loadNewerError(error, token))
|
||||
state = .idle
|
||||
|
@ -113,6 +117,8 @@ actor TimelineLikeController<Item> {
|
|||
await loadingIndicator.end()
|
||||
await emit(event: .appendItems(items, token))
|
||||
state = .idle
|
||||
} catch is CancellationError {
|
||||
return
|
||||
} catch {
|
||||
await loadingIndicator.end()
|
||||
await emit(event: .loadOlderError(error, token))
|
||||
|
|
|
@ -119,12 +119,12 @@ class ProfileHeaderView: UIView {
|
|||
|
||||
let request = Client.getRelationships(accounts: [accountID])
|
||||
mastodonController.run(request) { [weak self] (response) in
|
||||
guard let self = self,
|
||||
guard let mastodonController = self?.mastodonController,
|
||||
case let .success(results, _) = response,
|
||||
let relationship = results.first else {
|
||||
return
|
||||
}
|
||||
self.mastodonController.persistentContainer.addOrUpdate(relationship: relationship)
|
||||
mastodonController.persistentContainer.addOrUpdate(relationship: relationship)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue