From b47876dc3d96e2361d8befda7b15b2c1fd3f204b Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 2 Nov 2022 22:59:44 -0400 Subject: [PATCH] Fix retain cycle due to account follow action workaround --- Tusker/Screens/Utilities/Previewing.swift | 30 +++++++++++------------ 1 file changed, 15 insertions(+), 15 deletions(-) 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 {