2021-03-11 08:41:27 +01:00
|
|
|
//
|
|
|
|
// ComposeViewModel+Diffable.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-3-11.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
2021-03-12 12:25:28 +01:00
|
|
|
import TwitterTextEditor
|
2021-03-11 08:41:27 +01:00
|
|
|
|
|
|
|
extension ComposeViewModel {
|
|
|
|
|
2021-03-12 07:18:07 +01:00
|
|
|
func setupDiffableDataSource(
|
|
|
|
for tableView: UITableView,
|
2021-03-12 12:25:28 +01:00
|
|
|
dependency: NeedsDependency,
|
|
|
|
textEditorViewTextAttributesDelegate: TextEditorViewTextAttributesDelegate
|
2021-03-12 07:18:07 +01:00
|
|
|
) {
|
|
|
|
diffableDataSource = ComposeStatusSection.tableViewDiffableDataSource(
|
|
|
|
for: tableView,
|
|
|
|
dependency: dependency,
|
|
|
|
managedObjectContext: context.managedObjectContext,
|
2021-03-12 12:25:28 +01:00
|
|
|
composeKind: composeKind,
|
|
|
|
textEditorViewTextAttributesDelegate: textEditorViewTextAttributesDelegate
|
2021-03-12 07:18:07 +01:00
|
|
|
)
|
2021-03-11 08:41:27 +01:00
|
|
|
|
|
|
|
var snapshot = NSDiffableDataSourceSnapshot<ComposeStatusSection, ComposeStatusItem>()
|
|
|
|
snapshot.appendSections([.repliedTo, .status])
|
|
|
|
switch composeKind {
|
2021-03-15 06:42:46 +01:00
|
|
|
case .reply(let tootObjectID):
|
2021-03-11 08:41:27 +01:00
|
|
|
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-15 06:42:46 +01:00
|
|
|
case .post:
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|