Kurdtvs-Live-Kurdish-TV-Kur.../Mastodon/Scene/Notification/NotificationViewController+...

71 lines
2.2 KiB
Swift
Raw Normal View History

//
// NotificationViewController+StatusProvider.swift
// Mastodon
//
// Created by MainasuK Cirno on 2021-7-1.
//
import UIKit
import Combine
import CoreData
import CoreDataStack
extension NotificationViewController: StatusProvider {
func status() -> Future<Status?, Never> {
return Future<Status?, Never> { promise in
promise(.success(nil))
}
}
func status(for cell: UITableViewCell?, indexPath: IndexPath?) -> Future<Status?, Never> {
return Future<Status?, Never> { promise in
guard let cell = cell,
let diffableDataSource = self.viewModel.diffableDataSource,
let indexPath = self.tableView.indexPath(for: cell),
let item = diffableDataSource.itemIdentifier(for: indexPath) else {
promise(.success(nil))
return
}
switch item {
case .notification(let objectID, _):
self.viewModel.fetchedResultsController.managedObjectContext.perform {
let notification = self.viewModel.fetchedResultsController.managedObjectContext.object(with: objectID) as! MastodonNotification
promise(.success(notification.status))
}
default:
promise(.success(nil))
}
}
}
func status(for cell: UICollectionViewCell) -> Future<Status?, Never> {
return Future<Status?, Never> { promise in
promise(.success(nil))
}
}
var managedObjectContext: NSManagedObjectContext {
viewModel.fetchedResultsController.managedObjectContext
}
var tableViewDiffableDataSource: UITableViewDiffableDataSource<StatusSection, Item>? {
return nil
}
func item(for cell: UITableViewCell?, indexPath: IndexPath?) -> Item? {
return nil
}
func items(indexPaths: [IndexPath]) -> [Item] {
return []
}
func statusObjectItems(indexPaths: [IndexPath]) -> [StatusObjectItem] {
guard let diffableDataSource = self.viewModel.diffableDataSource else { return [] }
let items = indexPaths.compactMap { diffableDataSource.itemIdentifier(for: $0)?.statusObjectItem }
return items
}
}