mastodon-ios/Mastodon/Diffiable/Status/ReportSection.swift

68 lines
2.5 KiB
Swift
Raw Normal View History

2021-04-19 14:34:08 +02:00
//
// ReportSection.swift
// Mastodon
//
// Created by ihugo on 2021/4/20.
//
import Combine
import CoreData
import CoreDataStack
import Foundation
import MastodonSDK
import UIKit
import AVKit
import os.log
enum ReportSection: Equatable, Hashable {
case main
}
extension ReportSection {
static func tableViewDiffableDataSource(
for tableView: UITableView,
dependency: ReportViewController,
2021-04-19 14:34:08 +02:00
managedObjectContext: NSManagedObjectContext,
timestampUpdatePublisher: AnyPublisher<Date, Never>
2021-04-19 14:34:08 +02:00
) -> UITableViewDiffableDataSource<ReportSection, Item> {
UITableViewDiffableDataSource(tableView: tableView) {[
weak dependency
] tableView, indexPath, item -> UITableViewCell? in
guard let dependency = dependency else { return UITableViewCell() }
switch item {
case .reportStatus(let objectID, let attribute):
2021-04-19 14:34:08 +02:00
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ReportedStatusTableViewCell.self), for: indexPath) as! ReportedStatusTableViewCell
cell.dependency = dependency
2021-04-19 14:34:08 +02:00
let activeMastodonAuthenticationBox = dependency.context.authenticationService.activeMastodonAuthenticationBox.value
let requestUserID = activeMastodonAuthenticationBox?.userID ?? ""
2021-04-26 11:41:24 +02:00
managedObjectContext.performAndWait { [weak dependency] in
guard let dependency = dependency else { return }
2021-04-19 14:34:08 +02:00
let status = managedObjectContext.object(with: objectID) as! Status
StatusSection.configure(
cell: cell,
tableView: tableView,
2021-07-09 13:07:12 +02:00
timelineContext: .report,
2021-04-19 14:34:08 +02:00
dependency: dependency,
readableLayoutFrame: tableView.readableContentGuide.layoutFrame,
status: status,
requestUserID: requestUserID,
statusItemAttribute: attribute
)
}
// defalut to select the report status
if attribute.isSelected {
tableView.selectRow(at: indexPath, animated: false, scrollPosition: .none)
} else {
tableView.deselectRow(at: indexPath, animated: false)
}
2021-04-19 14:34:08 +02:00
return cell
default:
return nil
}
}
}
}