diff --git a/Tusker/Screens/Utilities/Previewing.swift b/Tusker/Screens/Utilities/Previewing.swift index 57ff74cf..1860c57e 100644 --- a/Tusker/Screens/Utilities/Previewing.swift +++ b/Tusker/Screens/Utilities/Previewing.swift @@ -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 {