Kurdtvs-Live-Kurdish-TV-Kur.../Mastodon/Diffiable/Section/ReportSection.swift

59 lines
2.1 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: NeedsDependency,
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
let activeMastodonAuthenticationBox = dependency.context.authenticationService.activeMastodonAuthenticationBox.value
let requestUserID = activeMastodonAuthenticationBox?.userID ?? ""
managedObjectContext.performAndWait {
let status = managedObjectContext.object(with: objectID) as! Status
StatusSection.configure(
cell: cell,
dependency: dependency,
readableLayoutFrame: tableView.readableContentGuide.layoutFrame,
timestampUpdatePublisher: timestampUpdatePublisher,
status: status,
requestUserID: requestUserID,
statusItemAttribute: attribute
)
}
cell.setupSelected(attribute.isSelected)
2021-04-19 14:34:08 +02:00
return cell
default:
return nil
}
}
}
}