2021-04-12 10:31:53 +02:00
|
|
|
//
|
|
|
|
// NotificationSection.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by sxiaojian on 2021/4/13.
|
|
|
|
//
|
|
|
|
|
2021-04-15 04:16:30 +02:00
|
|
|
import Combine
|
2021-04-12 10:31:53 +02:00
|
|
|
import CoreData
|
|
|
|
import CoreDataStack
|
|
|
|
import Foundation
|
|
|
|
import MastodonSDK
|
|
|
|
import UIKit
|
2021-07-23 13:10:27 +02:00
|
|
|
import MetaTextKit
|
|
|
|
import MastodonMeta
|
2022-01-27 14:23:39 +01:00
|
|
|
import MastodonAsset
|
|
|
|
import MastodonLocalization
|
2021-04-12 10:31:53 +02:00
|
|
|
|
|
|
|
enum NotificationSection: Equatable, Hashable {
|
|
|
|
case main
|
|
|
|
}
|
|
|
|
|
|
|
|
extension NotificationSection {
|
2022-01-27 14:23:39 +01:00
|
|
|
|
|
|
|
struct Configuration {
|
|
|
|
weak var notificationTableViewCellDelegate: NotificationTableViewCellDelegate?
|
2022-02-15 12:44:45 +01:00
|
|
|
let filterContext: Mastodon.Entity.Filter.Context?
|
|
|
|
let activeFilters: Published<[Mastodon.Entity.Filter]>.Publisher?
|
2022-01-27 14:23:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static func diffableDataSource(
|
|
|
|
tableView: UITableView,
|
|
|
|
context: AppContext,
|
|
|
|
configuration: Configuration
|
2021-04-12 10:31:53 +02:00
|
|
|
) -> UITableViewDiffableDataSource<NotificationSection, NotificationItem> {
|
2022-01-27 14:23:39 +01:00
|
|
|
tableView.register(NotificationTableViewCell.self, forCellReuseIdentifier: String(describing: NotificationTableViewCell.self))
|
|
|
|
tableView.register(TimelineBottomLoaderTableViewCell.self, forCellReuseIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self))
|
|
|
|
|
|
|
|
return UITableViewDiffableDataSource(tableView: tableView) { tableView, indexPath, item -> UITableViewCell? in
|
|
|
|
switch item {
|
|
|
|
case .feed(let record):
|
|
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: NotificationTableViewCell.self), for: indexPath) as! NotificationTableViewCell
|
|
|
|
context.managedObjectContext.performAndWait {
|
|
|
|
guard let feed = record.object(in: context.managedObjectContext) else { return }
|
|
|
|
configure(
|
|
|
|
context: context,
|
|
|
|
tableView: tableView,
|
|
|
|
cell: cell,
|
|
|
|
viewModel: NotificationTableViewCell.ViewModel(value: .feed(feed)),
|
|
|
|
configuration: configuration
|
|
|
|
)
|
|
|
|
}
|
2021-07-02 21:22:17 +02:00
|
|
|
return cell
|
2022-02-08 13:07:50 +01:00
|
|
|
case .feedLoader:
|
|
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as! TimelineBottomLoaderTableViewCell
|
|
|
|
cell.activityIndicatorView.startAnimating()
|
|
|
|
return cell
|
2021-04-12 10:31:53 +02:00
|
|
|
case .bottomLoader:
|
2022-01-27 14:23:39 +01:00
|
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as! TimelineBottomLoaderTableViewCell
|
|
|
|
cell.activityIndicatorView.startAnimating()
|
2021-04-12 10:31:53 +02:00
|
|
|
return cell
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-14 09:00:48 +02:00
|
|
|
|
2021-11-02 07:28:21 +01:00
|
|
|
extension NotificationSection {
|
2022-01-27 14:23:39 +01:00
|
|
|
|
2021-11-02 07:28:21 +01:00
|
|
|
static func configure(
|
2022-01-27 14:23:39 +01:00
|
|
|
context: AppContext,
|
2021-11-02 07:28:21 +01:00
|
|
|
tableView: UITableView,
|
2022-01-27 14:23:39 +01:00
|
|
|
cell: NotificationTableViewCell,
|
|
|
|
viewModel: NotificationTableViewCell.ViewModel,
|
|
|
|
configuration: Configuration
|
2021-11-02 07:28:21 +01:00
|
|
|
) {
|
2022-01-27 14:23:39 +01:00
|
|
|
StatusSection.setupStatusPollDataSource(
|
|
|
|
context: context,
|
|
|
|
statusView: cell.notificationView.statusView
|
2021-11-02 07:28:21 +01:00
|
|
|
)
|
|
|
|
|
2022-01-27 14:23:39 +01:00
|
|
|
StatusSection.setupStatusPollDataSource(
|
|
|
|
context: context,
|
|
|
|
statusView: cell.notificationView.quoteStatusView
|
|
|
|
)
|
2021-11-02 07:28:21 +01:00
|
|
|
|
2022-01-27 14:23:39 +01:00
|
|
|
context.authenticationService.activeMastodonAuthenticationBox
|
|
|
|
.map { $0 as UserIdentifier? }
|
|
|
|
.assign(to: \.userIdentifier, on: cell.notificationView.viewModel)
|
2021-11-02 07:28:21 +01:00
|
|
|
.store(in: &cell.disposeBag)
|
|
|
|
|
2022-01-27 14:23:39 +01:00
|
|
|
cell.configure(
|
|
|
|
tableView: tableView,
|
|
|
|
viewModel: viewModel,
|
|
|
|
delegate: configuration.notificationTableViewCellDelegate
|
|
|
|
)
|
2022-02-15 12:44:45 +01:00
|
|
|
|
|
|
|
cell.notificationView.statusView.viewModel.filterContext = configuration.filterContext
|
|
|
|
cell.notificationView.quoteStatusView.viewModel.filterContext = configuration.filterContext
|
|
|
|
|
|
|
|
configuration.activeFilters?
|
|
|
|
.assign(to: \.activeFilters, on: cell.notificationView.statusView.viewModel)
|
|
|
|
.store(in: &cell.disposeBag)
|
|
|
|
configuration.activeFilters?
|
|
|
|
.assign(to: \.activeFilters, on: cell.notificationView.quoteStatusView.viewModel)
|
|
|
|
.store(in: &cell.disposeBag)
|
2021-11-02 07:28:21 +01:00
|
|
|
}
|
2021-12-03 13:23:40 +01:00
|
|
|
|
2021-11-02 07:28:21 +01:00
|
|
|
}
|
2021-12-03 13:23:40 +01:00
|
|
|
|