2021-03-11 08:41:27 +01:00
|
|
|
//
|
|
|
|
// ComposeViewModel+Diffable.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-3-11.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
extension ComposeViewModel {
|
|
|
|
|
2021-03-12 07:18:07 +01:00
|
|
|
func setupDiffableDataSource(
|
|
|
|
for tableView: UITableView,
|
|
|
|
dependency: NeedsDependency
|
|
|
|
) {
|
|
|
|
diffableDataSource = ComposeStatusSection.tableViewDiffableDataSource(
|
|
|
|
for: tableView,
|
|
|
|
dependency: dependency,
|
|
|
|
managedObjectContext: context.managedObjectContext,
|
|
|
|
composeKind: composeKind
|
|
|
|
)
|
2021-03-11 08:41:27 +01:00
|
|
|
|
|
|
|
var snapshot = NSDiffableDataSourceSnapshot<ComposeStatusSection, ComposeStatusItem>()
|
|
|
|
snapshot.appendSections([.repliedTo, .status])
|
|
|
|
switch composeKind {
|
|
|
|
case .replyToot(let tootObjectID):
|
|
|
|
snapshot.appendItems([.replyTo(tootObjectID: tootObjectID)], toSection: .repliedTo)
|
2021-03-12 07:18:07 +01:00
|
|
|
snapshot.appendItems([.toot(replyToTootObjectID: tootObjectID, attribute: composeTootAttribute)], toSection: .status)
|
2021-03-11 08:41:27 +01:00
|
|
|
case .toot:
|
2021-03-12 07:18:07 +01:00
|
|
|
snapshot.appendItems([.toot(replyToTootObjectID: nil, attribute: composeTootAttribute)], toSection: .status)
|
2021-03-11 08:41:27 +01:00
|
|
|
}
|
|
|
|
diffableDataSource.apply(snapshot, animatingDifferences: false)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|