From d80b8d718a0f55ce27274dbcbd4fcbd6d9502198 Mon Sep 17 00:00:00 2001 From: CMK Date: Tue, 15 Feb 2022 18:17:55 +0800 Subject: [PATCH] fix: wrong reply header redirect logic issue --- ...Provider+StatusTableViewCellDelegate.swift | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/Mastodon/Protocol/Provider/DataSourceProvider+StatusTableViewCellDelegate.swift b/Mastodon/Protocol/Provider/DataSourceProvider+StatusTableViewCellDelegate.swift index a7afca8c..d14b5c34 100644 --- a/Mastodon/Protocol/Provider/DataSourceProvider+StatusTableViewCellDelegate.swift +++ b/Mastodon/Protocol/Provider/DataSourceProvider+StatusTableViewCellDelegate.swift @@ -28,11 +28,36 @@ extension StatusTableViewCellDelegate where Self: DataSourceProvider { assertionFailure("only works for status data provider") return } - await DataSourceFacade.coordinateToProfileScene( - provider: self, - target: .reblog, // keep the wrapper for header author - status: status - ) + + switch await statusView.viewModel.header { + case .none: + break + case .reply: + let _replyToAuthor: ManagedObjectRecord? = try? await context.managedObjectContext.perform { + guard let status = status.object(in: self.context.managedObjectContext) else { return nil } + guard let inReplyToAccountID = status.inReplyToAccountID else { return nil } + let request = MastodonUser.sortedFetchRequest + request.predicate = MastodonUser.predicate(domain: status.author.domain, id: inReplyToAccountID) + request.fetchLimit = 1 + guard let author = self.context.managedObjectContext.safeFetch(request).first else { return nil } + return .init(objectID: author.objectID) + } + guard let replyToAuthor = _replyToAuthor else { + return + } + + await DataSourceFacade.coordinateToProfileScene( + provider: self, + user: replyToAuthor + ) + + case .repost: + await DataSourceFacade.coordinateToProfileScene( + provider: self, + target: .reblog, // keep the wrapper for header author + status: status + ) + } } }