Fix retain cycle due to account follow action workaround
This commit is contained in:
parent
4644475bc7
commit
b47876dc3d
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue