Fix status deletion not updating data model (IOS-205)
This commit is contained in:
parent
a4db8a2b90
commit
c30fb73922
|
@ -20,13 +20,15 @@ import MastodonSDK
|
||||||
extension DataSourceFacade {
|
extension DataSourceFacade {
|
||||||
|
|
||||||
static func responseToDeleteStatus(
|
static func responseToDeleteStatus(
|
||||||
dependency: NeedsDependency & AuthContextProvider,
|
dependency: NeedsDependency & AuthContextProvider & DataSourceProvider,
|
||||||
status: MastodonStatus
|
status: MastodonStatus
|
||||||
) async throws {
|
) async throws {
|
||||||
_ = try await dependency.context.apiService.deleteStatus(
|
let deletedStatus = try await dependency.context.apiService.deleteStatus(
|
||||||
status: status,
|
status: status,
|
||||||
authenticationBox: dependency.authContext.mastodonAuthenticationBox
|
authenticationBox: dependency.authContext.mastodonAuthenticationBox
|
||||||
)
|
).value.asMastodonStatus
|
||||||
|
|
||||||
|
dependency.delete(status: deletedStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,4 +40,5 @@ extension DataSourceItem {
|
||||||
protocol DataSourceProvider: ViewControllerWithDependencies {
|
protocol DataSourceProvider: ViewControllerWithDependencies {
|
||||||
func item(from source: DataSourceItem.Source) async -> DataSourceItem?
|
func item(from source: DataSourceItem.Source) async -> DataSourceItem?
|
||||||
func update(status: MastodonStatus)
|
func update(status: MastodonStatus)
|
||||||
|
func delete(status: MastodonStatus)
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,12 @@ extension DiscoveryCommunityViewController: DataSourceProvider {
|
||||||
viewModel.statusFetchedResultsController.update(status: status)
|
viewModel.statusFetchedResultsController.update(status: status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func delete(status: MastodonStatus) {
|
||||||
|
viewModel.statusFetchedResultsController.setRecords(
|
||||||
|
viewModel.statusFetchedResultsController.records.filter { $0.id != status.id }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
||||||
return tableView.indexPath(for: cell)
|
return tableView.indexPath(for: cell)
|
||||||
|
|
|
@ -32,6 +32,12 @@ extension DiscoveryPostsViewController: DataSourceProvider {
|
||||||
viewModel.statusFetchedResultsController.update(status: status)
|
viewModel.statusFetchedResultsController.update(status: status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func delete(status: MastodonStatus) {
|
||||||
|
viewModel.statusFetchedResultsController.setRecords(
|
||||||
|
viewModel.statusFetchedResultsController.records.filter { $0.id != status.id }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
||||||
return tableView.indexPath(for: cell)
|
return tableView.indexPath(for: cell)
|
||||||
|
|
|
@ -32,6 +32,10 @@ extension HashtagTimelineViewController: DataSourceProvider {
|
||||||
viewModel.fetchedResultsController.update(status: status)
|
viewModel.fetchedResultsController.update(status: status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func delete(status: MastodonStatus) {
|
||||||
|
viewModel.fetchedResultsController.deleteRecord(status)
|
||||||
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
||||||
return tableView.indexPath(for: cell)
|
return tableView.indexPath(for: cell)
|
||||||
|
|
|
@ -40,6 +40,10 @@ extension HomeTimelineViewController: DataSourceProvider {
|
||||||
viewModel.fetchedResultsController.update(status: status)
|
viewModel.fetchedResultsController.update(status: status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func delete(status: MastodonStatus) {
|
||||||
|
viewModel.fetchedResultsController.records = viewModel.fetchedResultsController.records.filter { $0.id != status.id }
|
||||||
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
||||||
return tableView.indexPath(for: cell)
|
return tableView.indexPath(for: cell)
|
||||||
|
|
|
@ -41,6 +41,10 @@ extension NotificationTimelineViewController: DataSourceProvider {
|
||||||
viewModel.feedFetchedResultsController.update(status: status)
|
viewModel.feedFetchedResultsController.update(status: status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func delete(status: MastodonStatus) {
|
||||||
|
viewModel.feedFetchedResultsController
|
||||||
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
||||||
return tableView.indexPath(for: cell)
|
return tableView.indexPath(for: cell)
|
||||||
|
|
|
@ -32,6 +32,12 @@ extension BookmarkViewController: DataSourceProvider {
|
||||||
viewModel.statusFetchedResultsController.update(status: status)
|
viewModel.statusFetchedResultsController.update(status: status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func delete(status: MastodonStatus) {
|
||||||
|
viewModel.statusFetchedResultsController.setRecords(
|
||||||
|
viewModel.statusFetchedResultsController.records.filter { $0.id != status.id }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
||||||
return tableView.indexPath(for: cell)
|
return tableView.indexPath(for: cell)
|
||||||
|
|
|
@ -104,7 +104,11 @@ extension FamiliarFollowersViewController: DataSourceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
func update(status: MastodonStatus) {
|
func update(status: MastodonStatus) {
|
||||||
assertionFailure("Implement not required in this class")
|
assertionFailure("Not required")
|
||||||
|
}
|
||||||
|
|
||||||
|
func delete(status: MastodonStatus) {
|
||||||
|
assertionFailure("Not required")
|
||||||
}
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
|
|
|
@ -32,6 +32,12 @@ extension FavoriteViewController: DataSourceProvider {
|
||||||
viewModel.statusFetchedResultsController.update(status: status)
|
viewModel.statusFetchedResultsController.update(status: status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func delete(status: MastodonStatus) {
|
||||||
|
viewModel.statusFetchedResultsController.setRecords(
|
||||||
|
viewModel.statusFetchedResultsController.records.filter { $0.id != status.id }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
||||||
return tableView.indexPath(for: cell)
|
return tableView.indexPath(for: cell)
|
||||||
|
|
|
@ -155,7 +155,11 @@ extension FollowerListViewController: DataSourceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
func update(status: MastodonStatus) {
|
func update(status: MastodonStatus) {
|
||||||
assertionFailure("Implement not required in this class")
|
assertionFailure("Not required")
|
||||||
|
}
|
||||||
|
|
||||||
|
func delete(status: MastodonStatus) {
|
||||||
|
assertionFailure("Not required")
|
||||||
}
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
|
|
|
@ -151,7 +151,11 @@ extension FollowingListViewController: DataSourceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
func update(status: MastodonStatus) {
|
func update(status: MastodonStatus) {
|
||||||
assertionFailure("Implement not required in this class")
|
assertionFailure("Not required")
|
||||||
|
}
|
||||||
|
|
||||||
|
func delete(status: MastodonStatus) {
|
||||||
|
assertionFailure("Not required")
|
||||||
}
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
|
|
|
@ -944,11 +944,15 @@ private extension ProfileViewController {
|
||||||
|
|
||||||
extension ProfileViewController: DataSourceProvider {
|
extension ProfileViewController: DataSourceProvider {
|
||||||
func item(from source: DataSourceItem.Source) async -> DataSourceItem? {
|
func item(from source: DataSourceItem.Source) async -> DataSourceItem? {
|
||||||
assertionFailure("Implement not required in this class")
|
assertionFailure("Not required")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func update(status: MastodonStatus) {
|
func update(status: MastodonStatus) {
|
||||||
assertionFailure("Implement not required in this class")
|
assertionFailure("Not required")
|
||||||
|
}
|
||||||
|
|
||||||
|
func delete(status: MastodonStatus) {
|
||||||
|
assertionFailure("Not required")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,10 @@ extension UserTimelineViewController: DataSourceProvider {
|
||||||
viewModel.statusFetchedResultsController.update(status: status)
|
viewModel.statusFetchedResultsController.update(status: status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func delete(status: MastodonStatus) {
|
||||||
|
viewModel.statusFetchedResultsController.deleteRecord(status)
|
||||||
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
||||||
return tableView.indexPath(for: cell)
|
return tableView.indexPath(for: cell)
|
||||||
|
|
|
@ -29,7 +29,11 @@ extension FavoritedByViewController: DataSourceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
func update(status: MastodonStatus) {
|
func update(status: MastodonStatus) {
|
||||||
assertionFailure("Implement not required in this class")
|
assertionFailure("Not required")
|
||||||
|
}
|
||||||
|
|
||||||
|
func delete(status: MastodonStatus) {
|
||||||
|
assertionFailure("Not required")
|
||||||
}
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
|
|
|
@ -30,7 +30,11 @@ extension RebloggedByViewController: DataSourceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
func update(status: MastodonStatus) {
|
func update(status: MastodonStatus) {
|
||||||
assertionFailure("Implement not required in this class")
|
assertionFailure("Not required")
|
||||||
|
}
|
||||||
|
|
||||||
|
func delete(status: MastodonStatus) {
|
||||||
|
assertionFailure("Not required")
|
||||||
}
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
|
|
|
@ -30,7 +30,11 @@ extension SearchHistoryViewController: DataSourceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
func update(status: MastodonStatus) {
|
func update(status: MastodonStatus) {
|
||||||
assertionFailure("Implement not required in this class")
|
assertionFailure("Not required")
|
||||||
|
}
|
||||||
|
|
||||||
|
func delete(status: MastodonStatus) {
|
||||||
|
assertionFailure("Not required")
|
||||||
}
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
|
|
|
@ -37,6 +37,10 @@ extension SearchResultViewController: DataSourceProvider {
|
||||||
viewModel.statusFetchedResultsController.update(status: status)
|
viewModel.statusFetchedResultsController.update(status: status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func delete(status: MastodonStatus) {
|
||||||
|
viewModel.statusFetchedResultsController.deleteRecord(status)
|
||||||
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
||||||
return tableView.indexPath(for: cell)
|
return tableView.indexPath(for: cell)
|
||||||
|
|
|
@ -33,6 +33,10 @@ extension ThreadViewController: DataSourceProvider {
|
||||||
viewModel.root = .root(context: .init(status: status))
|
viewModel.root = .root(context: .init(status: status))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func delete(status: MastodonStatus) {
|
||||||
|
assertionFailure("Needs implementation")
|
||||||
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
||||||
return tableView.indexPath(for: cell)
|
return tableView.indexPath(for: cell)
|
||||||
|
|
|
@ -71,6 +71,10 @@ final public class FeedFetchedResultsController {
|
||||||
}
|
}
|
||||||
records = newRecords
|
records = newRecords
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func delete(status: MastodonStatus) {
|
||||||
|
self.records.removeAll { $0.id == status.id }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private extension FeedFetchedResultsController {
|
private extension FeedFetchedResultsController {
|
||||||
|
|
|
@ -36,6 +36,11 @@ public final class StatusFetchedResultsController {
|
||||||
self.records += records
|
self.records += records
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
public func deleteRecord(_ record: MastodonStatus) {
|
||||||
|
self.records = self.records.filter { $0.id != record.id }
|
||||||
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
public func update(status: MastodonStatus) {
|
public func update(status: MastodonStatus) {
|
||||||
var newRecords = Array(records)
|
var newRecords = Array(records)
|
||||||
|
|
|
@ -49,9 +49,12 @@ extension MastodonStatus: Hashable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public extension Mastodon.Entity.Status {
|
public extension Mastodon.Entity.Status {
|
||||||
|
var asMastodonStatus: MastodonStatus {
|
||||||
|
.fromEntity(self)
|
||||||
|
}
|
||||||
|
|
||||||
var mastodonVisibility: MastodonVisibility? {
|
var mastodonVisibility: MastodonVisibility? {
|
||||||
guard let visibility = visibility?.rawValue else { return nil }
|
guard let visibility = visibility?.rawValue else { return nil }
|
||||||
return MastodonVisibility(rawValue: visibility)
|
return MastodonVisibility(rawValue: visibility)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue