diff --git a/Mastodon/Diffiable/Section/ReportSection.swift b/Mastodon/Diffiable/Section/ReportSection.swift index eccf09d2..e14a959f 100644 --- a/Mastodon/Diffiable/Section/ReportSection.swift +++ b/Mastodon/Diffiable/Section/ReportSection.swift @@ -21,7 +21,7 @@ enum ReportSection: Equatable, Hashable { extension ReportSection { static func tableViewDiffableDataSource( for tableView: UITableView, - dependency: NeedsDependency, + dependency: ReportViewController, managedObjectContext: NSManagedObjectContext, timestampUpdatePublisher: AnyPublisher ) -> UITableViewDiffableDataSource { @@ -33,6 +33,7 @@ extension ReportSection { switch item { case .reportStatus(let objectID, let attribute): let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ReportedStatusTableViewCell.self), for: indexPath) as! ReportedStatusTableViewCell + cell.dependency = dependency let activeMastodonAuthenticationBox = dependency.context.authenticationService.activeMastodonAuthenticationBox.value let requestUserID = activeMastodonAuthenticationBox?.userID ?? "" managedObjectContext.performAndWait { diff --git a/Mastodon/Protocol/StatusProvider/StatusProviderFacade.swift b/Mastodon/Protocol/StatusProvider/StatusProviderFacade.swift index 2e610222..03f84216 100644 --- a/Mastodon/Protocol/StatusProvider/StatusProviderFacade.swift +++ b/Mastodon/Protocol/StatusProvider/StatusProviderFacade.swift @@ -498,6 +498,34 @@ extension StatusProviderFacade { .store(in: &dependency.context.disposeBag) } + static func responseToStatusContentWarningRevealAction(dependency: ReportViewController, cell: UITableViewCell) { + let status = Future { promise in + guard let diffableDataSource = dependency.viewModel.diffableDataSource, + let indexPath = dependency.tableView.indexPath(for: cell), + let item = diffableDataSource.itemIdentifier(for: indexPath) else { + promise(.success(nil)) + return + } + let managedObjectContext = dependency.viewModel.statusFetchedResultsController + .fetchedResultsController + .managedObjectContext + + switch item { + case .reportStatus(let objectID, _): + managedObjectContext.perform { + let status = managedObjectContext.object(with: objectID) as! Status + promise(.success(status)) + } + default: + promise(.success(nil)) + } + } + + _responseToStatusContentWarningRevealAction( + dependency: dependency, + status: status + ) + } } extension StatusProviderFacade { diff --git a/Mastodon/Scene/Report/ReportViewModel+Diffable.swift b/Mastodon/Scene/Report/ReportViewModel+Diffable.swift index f737381b..73d6ffa0 100644 --- a/Mastodon/Scene/Report/ReportViewModel+Diffable.swift +++ b/Mastodon/Scene/Report/ReportViewModel+Diffable.swift @@ -13,7 +13,7 @@ import CoreDataStack extension ReportViewModel { func setupDiffableDataSource( for tableView: UITableView, - dependency: NeedsDependency + dependency: ReportViewController ) { let timestampUpdatePublisher = Timer.publish(every: 1.0, on: .main, in: .common) .autoconnect() diff --git a/Mastodon/Scene/Report/ReportedStatusTableviewCell.swift b/Mastodon/Scene/Report/ReportedStatusTableviewCell.swift index 0c63398d..3cbfface 100644 --- a/Mastodon/Scene/Report/ReportedStatusTableviewCell.swift +++ b/Mastodon/Scene/Report/ReportedStatusTableviewCell.swift @@ -17,6 +17,7 @@ final class ReportedStatusTableViewCell: UITableViewCell, StatusCell { static let bottomPaddingHeight: CGFloat = 10 + var dependency: ReportViewController? var disposeBag = Set() var pollCountdownSubscription: AnyCancellable? var observations = Set() @@ -63,6 +64,9 @@ final class ReportedStatusTableViewCell: UITableViewCell, StatusCell { override func layoutSubviews() { super.layoutSubviews() + + // precondition: app is active + guard UIApplication.shared.applicationState == .active else { return } DispatchQueue.main.async { self.statusView.drawContentWarningImageView() } @@ -127,8 +131,10 @@ extension ReportedStatusTableViewCell { resetSeparatorLineLayout() selectionStyle = .none + statusView.delegate = self + statusView.statusMosaicImageViewContainer.delegate = self statusView.actionToolbarContainer.isHidden = true - statusView.isUserInteractionEnabled = false + statusView.contentWarningOverlayView.blurContentImageView.backgroundColor = backgroundColor } override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { @@ -168,3 +174,44 @@ extension ReportedStatusTableViewCell { } } } + +extension ReportedStatusTableViewCell: MosaicImageViewContainerDelegate { + func mosaicImageViewContainer(_ mosaicImageViewContainer: MosaicImageViewContainer, didTapImageView imageView: UIImageView, atIndex index: Int) { + + } + + func mosaicImageViewContainer(_ mosaicImageViewContainer: MosaicImageViewContainer, contentWarningOverlayViewDidPressed contentWarningOverlayView: ContentWarningOverlayView) { + + guard let dependency = self.dependency else { return } + StatusProviderFacade.responseToStatusContentWarningRevealAction(dependency: dependency, cell: self) + } +} + +extension ReportedStatusTableViewCell: StatusViewDelegate { + func statusView(_ statusView: StatusView, headerInfoLabelDidPressed label: UILabel) { + } + + func statusView(_ statusView: StatusView, avatarButtonDidPressed button: UIButton) { + } + + func statusView(_ statusView: StatusView, revealContentWarningButtonDidPressed button: UIButton) { + guard let dependency = self.dependency else { return } + StatusProviderFacade.responseToStatusContentWarningRevealAction(dependency: dependency, cell: self) + } + + func statusView(_ statusView: StatusView, contentWarningOverlayViewDidPressed contentWarningOverlayView: ContentWarningOverlayView) { + guard let dependency = self.dependency else { return } + StatusProviderFacade.responseToStatusContentWarningRevealAction(dependency: dependency, cell: self) + } + + func statusView(_ statusView: StatusView, playerContainerView: PlayerContainerView, contentWarningOverlayViewDidPressed contentWarningOverlayView: ContentWarningOverlayView) { + guard let dependency = self.dependency else { return } + StatusProviderFacade.responseToStatusContentWarningRevealAction(dependency: dependency, cell: self) + } + + func statusView(_ statusView: StatusView, pollVoteButtonPressed button: UIButton) { + } + + func statusView(_ statusView: StatusView, activeLabel: ActiveLabel, didSelectActiveEntity entity: ActiveEntity) { + } +}