mirror of
https://github.com/mastodon/mastodon-ios.git
synced 2025-02-03 18:57:46 +01:00
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 {
|
||||
|
||||
static func responseToDeleteStatus(
|
||||
dependency: NeedsDependency & AuthContextProvider,
|
||||
dependency: NeedsDependency & AuthContextProvider & DataSourceProvider,
|
||||
status: MastodonStatus
|
||||
) async throws {
|
||||
_ = try await dependency.context.apiService.deleteStatus(
|
||||
let deletedStatus = try await dependency.context.apiService.deleteStatus(
|
||||
status: status,
|
||||
authenticationBox: dependency.authContext.mastodonAuthenticationBox
|
||||
)
|
||||
).value.asMastodonStatus
|
||||
|
||||
dependency.delete(status: deletedStatus)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -40,4 +40,5 @@ extension DataSourceItem {
|
||||
protocol DataSourceProvider: ViewControllerWithDependencies {
|
||||
func item(from source: DataSourceItem.Source) async -> DataSourceItem?
|
||||
func update(status: MastodonStatus)
|
||||
func delete(status: MastodonStatus)
|
||||
}
|
||||
|
@ -27,11 +27,17 @@ extension DiscoveryCommunityViewController: DataSourceProvider {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func update(status: MastodonStatus) {
|
||||
viewModel.statusFetchedResultsController.update(status: status)
|
||||
}
|
||||
|
||||
func delete(status: MastodonStatus) {
|
||||
viewModel.statusFetchedResultsController.setRecords(
|
||||
viewModel.statusFetchedResultsController.records.filter { $0.id != status.id }
|
||||
)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
||||
return tableView.indexPath(for: cell)
|
||||
|
@ -27,11 +27,17 @@ extension DiscoveryPostsViewController: DataSourceProvider {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func update(status: MastodonStatus) {
|
||||
viewModel.statusFetchedResultsController.update(status: status)
|
||||
}
|
||||
|
||||
func delete(status: MastodonStatus) {
|
||||
viewModel.statusFetchedResultsController.setRecords(
|
||||
viewModel.statusFetchedResultsController.records.filter { $0.id != status.id }
|
||||
)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
||||
return tableView.indexPath(for: cell)
|
||||
|
@ -32,6 +32,10 @@ extension HashtagTimelineViewController: DataSourceProvider {
|
||||
viewModel.fetchedResultsController.update(status: status)
|
||||
}
|
||||
|
||||
func delete(status: MastodonStatus) {
|
||||
viewModel.fetchedResultsController.deleteRecord(status)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
||||
return tableView.indexPath(for: cell)
|
||||
|
@ -35,11 +35,15 @@ extension HomeTimelineViewController: DataSourceProvider {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func update(status: MastodonStatus) {
|
||||
viewModel.fetchedResultsController.update(status: status)
|
||||
}
|
||||
|
||||
func delete(status: MastodonStatus) {
|
||||
viewModel.fetchedResultsController.records = viewModel.fetchedResultsController.records.filter { $0.id != status.id }
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
||||
return tableView.indexPath(for: cell)
|
||||
|
@ -36,11 +36,15 @@ extension NotificationTimelineViewController: DataSourceProvider {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func update(status: MastodonStatus) {
|
||||
viewModel.feedFetchedResultsController.update(status: status)
|
||||
}
|
||||
|
||||
func delete(status: MastodonStatus) {
|
||||
viewModel.feedFetchedResultsController
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
||||
return tableView.indexPath(for: cell)
|
||||
|
@ -27,11 +27,17 @@ extension BookmarkViewController: DataSourceProvider {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func update(status: MastodonStatus) {
|
||||
viewModel.statusFetchedResultsController.update(status: status)
|
||||
}
|
||||
|
||||
func delete(status: MastodonStatus) {
|
||||
viewModel.statusFetchedResultsController.setRecords(
|
||||
viewModel.statusFetchedResultsController.records.filter { $0.id != status.id }
|
||||
)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
||||
return tableView.indexPath(for: cell)
|
||||
|
@ -104,7 +104,11 @@ extension FamiliarFollowersViewController: DataSourceProvider {
|
||||
}
|
||||
|
||||
func update(status: MastodonStatus) {
|
||||
assertionFailure("Implement not required in this class")
|
||||
assertionFailure("Not required")
|
||||
}
|
||||
|
||||
func delete(status: MastodonStatus) {
|
||||
assertionFailure("Not required")
|
||||
}
|
||||
|
||||
@MainActor
|
||||
|
@ -27,11 +27,17 @@ extension FavoriteViewController: DataSourceProvider {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func update(status: MastodonStatus) {
|
||||
viewModel.statusFetchedResultsController.update(status: status)
|
||||
}
|
||||
|
||||
func delete(status: MastodonStatus) {
|
||||
viewModel.statusFetchedResultsController.setRecords(
|
||||
viewModel.statusFetchedResultsController.records.filter { $0.id != status.id }
|
||||
)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
||||
return tableView.indexPath(for: cell)
|
||||
|
@ -153,9 +153,13 @@ extension FollowerListViewController: DataSourceProvider {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func update(status: MastodonStatus) {
|
||||
assertionFailure("Implement not required in this class")
|
||||
assertionFailure("Not required")
|
||||
}
|
||||
|
||||
func delete(status: MastodonStatus) {
|
||||
assertionFailure("Not required")
|
||||
}
|
||||
|
||||
@MainActor
|
||||
|
@ -151,7 +151,11 @@ extension FollowingListViewController: DataSourceProvider {
|
||||
}
|
||||
|
||||
func update(status: MastodonStatus) {
|
||||
assertionFailure("Implement not required in this class")
|
||||
assertionFailure("Not required")
|
||||
}
|
||||
|
||||
func delete(status: MastodonStatus) {
|
||||
assertionFailure("Not required")
|
||||
}
|
||||
|
||||
@MainActor
|
||||
|
@ -944,11 +944,15 @@ private extension ProfileViewController {
|
||||
|
||||
extension ProfileViewController: DataSourceProvider {
|
||||
func item(from source: DataSourceItem.Source) async -> DataSourceItem? {
|
||||
assertionFailure("Implement not required in this class")
|
||||
assertionFailure("Not required")
|
||||
return nil
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
func delete(status: MastodonStatus) {
|
||||
viewModel.statusFetchedResultsController.deleteRecord(status)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
||||
return tableView.indexPath(for: cell)
|
||||
|
@ -29,7 +29,11 @@ extension FavoritedByViewController: DataSourceProvider {
|
||||
}
|
||||
|
||||
func update(status: MastodonStatus) {
|
||||
assertionFailure("Implement not required in this class")
|
||||
assertionFailure("Not required")
|
||||
}
|
||||
|
||||
func delete(status: MastodonStatus) {
|
||||
assertionFailure("Not required")
|
||||
}
|
||||
|
||||
@MainActor
|
||||
|
@ -30,7 +30,11 @@ extension RebloggedByViewController: DataSourceProvider {
|
||||
}
|
||||
|
||||
func update(status: MastodonStatus) {
|
||||
assertionFailure("Implement not required in this class")
|
||||
assertionFailure("Not required")
|
||||
}
|
||||
|
||||
func delete(status: MastodonStatus) {
|
||||
assertionFailure("Not required")
|
||||
}
|
||||
|
||||
@MainActor
|
||||
|
@ -30,7 +30,11 @@ extension SearchHistoryViewController: DataSourceProvider {
|
||||
}
|
||||
|
||||
func update(status: MastodonStatus) {
|
||||
assertionFailure("Implement not required in this class")
|
||||
assertionFailure("Not required")
|
||||
}
|
||||
|
||||
func delete(status: MastodonStatus) {
|
||||
assertionFailure("Not required")
|
||||
}
|
||||
|
||||
@MainActor
|
||||
|
@ -37,6 +37,10 @@ extension SearchResultViewController: DataSourceProvider {
|
||||
viewModel.statusFetchedResultsController.update(status: status)
|
||||
}
|
||||
|
||||
func delete(status: MastodonStatus) {
|
||||
viewModel.statusFetchedResultsController.deleteRecord(status)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
||||
return tableView.indexPath(for: cell)
|
||||
|
@ -33,6 +33,10 @@ extension ThreadViewController: DataSourceProvider {
|
||||
viewModel.root = .root(context: .init(status: status))
|
||||
}
|
||||
|
||||
func delete(status: MastodonStatus) {
|
||||
assertionFailure("Needs implementation")
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func indexPath(for cell: UITableViewCell) async -> IndexPath? {
|
||||
return tableView.indexPath(for: cell)
|
||||
|
@ -71,6 +71,10 @@ final public class FeedFetchedResultsController {
|
||||
}
|
||||
records = newRecords
|
||||
}
|
||||
|
||||
public func delete(status: MastodonStatus) {
|
||||
self.records.removeAll { $0.id == status.id }
|
||||
}
|
||||
}
|
||||
|
||||
private extension FeedFetchedResultsController {
|
||||
|
@ -36,6 +36,11 @@ public final class StatusFetchedResultsController {
|
||||
self.records += records
|
||||
}
|
||||
|
||||
@MainActor
|
||||
public func deleteRecord(_ record: MastodonStatus) {
|
||||
self.records = self.records.filter { $0.id != record.id }
|
||||
}
|
||||
|
||||
@MainActor
|
||||
public func update(status: MastodonStatus) {
|
||||
var newRecords = Array(records)
|
||||
|
@ -49,9 +49,12 @@ extension MastodonStatus: Hashable {
|
||||
}
|
||||
|
||||
public extension Mastodon.Entity.Status {
|
||||
var asMastodonStatus: MastodonStatus {
|
||||
.fromEntity(self)
|
||||
}
|
||||
|
||||
var mastodonVisibility: MastodonVisibility? {
|
||||
guard let visibility = visibility?.rawValue else { return nil }
|
||||
return MastodonVisibility(rawValue: visibility)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user