From 5efdb3c2092d55f445ffb81c5db2da074cb2d307 Mon Sep 17 00:00:00 2001 From: Marcus Kida Date: Tue, 9 May 2023 11:33:31 +0200 Subject: [PATCH] Revert FollowedBlockedUserIdProviding (IOS-140) --- Mastodon.xcodeproj/project.pbxproj | 4 -- .../Search/SearchHistorySection.swift | 2 +- .../Diffable/Search/SearchResultSection.swift | 6 +-- Mastodon/Diffable/User/UserSection.swift | 6 +-- .../Provider/DataSourceFacade+UserView.swift | 37 +++++++++++++------ .../FamiliarFollowersViewController.swift | 3 +- .../FamiliarFollowersViewModel+Diffable.swift | 4 +- .../FamiliarFollowersViewModel.swift | 7 +--- .../FollowedBlockedUserIdProviding.swift | 31 ---------------- .../Follower/FollowerListViewController.swift | 3 +- .../FollowerListViewModel+Diffable.swift | 4 +- .../FollowerListViewModel+State.swift | 2 - .../Follower/FollowerListViewModel.swift | 5 +-- .../FollowingListViewController.swift | 3 +- .../FollowingListViewModel+Diffable.swift | 4 +- .../FollowingListViewModel+State.swift | 2 - .../Following/FollowingListViewModel.swift | 7 +--- .../FavoritedByViewController.swift | 7 +--- .../RebloggedByViewController.swift | 7 +--- .../UserLIst/UserListViewModel+Diffable.swift | 8 +--- .../UserLIst/UserListViewModel+State.swift | 4 +- .../Profile/UserLIst/UserListViewModel.swift | 7 +--- .../SearchHistoryViewController.swift | 9 +---- .../SearchHistoryViewModel.swift | 6 +-- .../SearchResultViewController.swift | 3 +- .../SearchResultViewModel+Diffable.swift | 4 +- .../SearchResult/SearchResultViewModel.swift | 5 +-- 27 files changed, 56 insertions(+), 134 deletions(-) delete mode 100644 Mastodon/Scene/Profile/FollowedBlockedUserIdProviding.swift diff --git a/Mastodon.xcodeproj/project.pbxproj b/Mastodon.xcodeproj/project.pbxproj index a0acb123c..fc7be157a 100644 --- a/Mastodon.xcodeproj/project.pbxproj +++ b/Mastodon.xcodeproj/project.pbxproj @@ -22,7 +22,6 @@ 164F0EBC267D4FE400249499 /* BoopSound.caf in Resources */ = {isa = PBXBuildFile; fileRef = 164F0EBB267D4FE400249499 /* BoopSound.caf */; }; 18BC7629F65E6DB12CB8416D /* Pods_Mastodon_MastodonUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3C030226D3C73DCC23D67452 /* Pods_Mastodon_MastodonUITests.framework */; }; 27D701F5292FC2D60031BCBB /* DataSourceFacade+URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27D701F4292FC2D60031BCBB /* DataSourceFacade+URL.swift */; }; - 2A15964E2A09012300C603BE /* FollowedBlockedUserIdProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A15964D2A09012300C603BE /* FollowedBlockedUserIdProviding.swift */; }; 2A1BF99529F7E68400FA1BA5 /* DataSourceFacade+UserView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A1BF99429F7E68400FA1BA5 /* DataSourceFacade+UserView.swift */; }; 2A1FE47C2938BB2600784BF1 /* FollowedTagsViewModel+DiffableDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A1FE47B2938BB2600784BF1 /* FollowedTagsViewModel+DiffableDataSource.swift */; }; 2A1FE47E2938C11200784BF1 /* Collection+IsNotEmpty.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A1FE47D2938C11200784BF1 /* Collection+IsNotEmpty.swift */; }; @@ -618,7 +617,6 @@ 164F0EBB267D4FE400249499 /* BoopSound.caf */ = {isa = PBXFileReference; lastKnownFileType = file; path = BoopSound.caf; sourceTree = ""; }; 1D6D967E77A5357E2C6110D9 /* Pods-Mastodon.asdk - debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Mastodon.asdk - debug.xcconfig"; path = "Target Support Files/Pods-Mastodon/Pods-Mastodon.asdk - debug.xcconfig"; sourceTree = ""; }; 27D701F4292FC2D60031BCBB /* DataSourceFacade+URL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DataSourceFacade+URL.swift"; sourceTree = ""; }; - 2A15964D2A09012300C603BE /* FollowedBlockedUserIdProviding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FollowedBlockedUserIdProviding.swift; sourceTree = ""; }; 2A1BF99429F7E68400FA1BA5 /* DataSourceFacade+UserView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DataSourceFacade+UserView.swift"; sourceTree = ""; }; 2A1FE47B2938BB2600784BF1 /* FollowedTagsViewModel+DiffableDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FollowedTagsViewModel+DiffableDataSource.swift"; sourceTree = ""; }; 2A1FE47D2938C11200784BF1 /* Collection+IsNotEmpty.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Collection+IsNotEmpty.swift"; sourceTree = ""; }; @@ -2705,7 +2703,6 @@ DBCC3B8E26148F7B0045B23D /* CachedProfileViewModel.swift */, DBAE3FAE26172FC0004B8251 /* RemoteProfileViewModel.swift */, DBB525632612C988002F1F29 /* MeProfileViewModel.swift */, - 2A15964D2A09012300C603BE /* FollowedBlockedUserIdProviding.swift */, ); path = Profile; sourceTree = ""; @@ -3882,7 +3879,6 @@ DB1D84382657B275000346B3 /* SegmentedControlNavigateable.swift in Sources */, 0F20220726134DA4000C64BF /* HashtagTimelineViewModel+Diffable.swift in Sources */, DB7A9F932818F33C0016AF98 /* MastodonServerRulesViewController+Debug.swift in Sources */, - 2A15964E2A09012300C603BE /* FollowedBlockedUserIdProviding.swift in Sources */, 2D5A3D2825CF8BC9002347D6 /* HomeTimelineViewModel+Diffable.swift in Sources */, DB6B74FC272FF55800C70B6E /* UserSection.swift in Sources */, DB0FCB862796BDA1006C02E2 /* SearchSection.swift in Sources */, diff --git a/Mastodon/Diffable/Search/SearchHistorySection.swift b/Mastodon/Diffable/Search/SearchHistorySection.swift index e55ccbbbb..5d1db9c55 100644 --- a/Mastodon/Diffable/Search/SearchHistorySection.swift +++ b/Mastodon/Diffable/Search/SearchHistorySection.swift @@ -32,7 +32,7 @@ extension SearchHistorySection { guard let user = item.object(in: context.managedObjectContext) else { return } cell.configure( me: authContext.mastodonAuthenticationBox.authenticationRecord.object(in: context.managedObjectContext)?.user, - viewModel: .init(value: user, followedUsers: viewModel.followedUserIds.eraseToAnyPublisher(), blockedUsers: viewModel.blockedUserIds.eraseToAnyPublisher()), + viewModel: .init(value: user, followedUsers: authContext.mastodonAuthenticationBox.inMemoryCache.$followingUserIds.eraseToAnyPublisher(), blockedUsers: authContext.mastodonAuthenticationBox.inMemoryCache.$blockedUserIds.eraseToAnyPublisher()), delegate: configuration.searchHistorySectionHeaderCollectionReusableViewDelegate ) } diff --git a/Mastodon/Diffable/Search/SearchResultSection.swift b/Mastodon/Diffable/Search/SearchResultSection.swift index 4719f45a8..2a6e92097 100644 --- a/Mastodon/Diffable/Search/SearchResultSection.swift +++ b/Mastodon/Diffable/Search/SearchResultSection.swift @@ -35,9 +35,7 @@ extension SearchResultSection { tableView: UITableView, context: AppContext, authContext: AuthContext, - configuration: Configuration, - followedUsers: AnyPublisher<[String], Never>, - blockedUsers: AnyPublisher<[String], Never> + configuration: Configuration ) -> UITableViewDiffableDataSource { tableView.register(UserTableViewCell.self, forCellReuseIdentifier: String(describing: UserTableViewCell.self)) tableView.register(StatusTableViewCell.self, forCellReuseIdentifier: String(describing: StatusTableViewCell.self)) @@ -55,7 +53,7 @@ extension SearchResultSection { authContext: authContext, tableView: tableView, cell: cell, - viewModel: .init(value: .user(user), followedUsers: followedUsers, blockedUsers: blockedUsers), + viewModel: .init(value: .user(user), followedUsers: authContext.mastodonAuthenticationBox.inMemoryCache.$followingUserIds.eraseToAnyPublisher(), blockedUsers: authContext.mastodonAuthenticationBox.inMemoryCache.$blockedUserIds.eraseToAnyPublisher()), configuration: configuration ) } diff --git a/Mastodon/Diffable/User/UserSection.swift b/Mastodon/Diffable/User/UserSection.swift index 73065e9cd..7defe5495 100644 --- a/Mastodon/Diffable/User/UserSection.swift +++ b/Mastodon/Diffable/User/UserSection.swift @@ -31,9 +31,7 @@ extension UserSection { tableView: UITableView, context: AppContext, authContext: AuthContext, - configuration: Configuration, - followedUsers: AnyPublisher<[String], Never>, - blockedUsers: AnyPublisher<[String], Never> + configuration: Configuration ) -> UITableViewDiffableDataSource { tableView.register(UserTableViewCell.self, forCellReuseIdentifier: String(describing: UserTableViewCell.self)) tableView.register(TimelineBottomLoaderTableViewCell.self, forCellReuseIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self)) @@ -50,7 +48,7 @@ extension UserSection { authContext: authContext, tableView: tableView, cell: cell, - viewModel: .init(value: .user(user), followedUsers: followedUsers, blockedUsers: blockedUsers), + viewModel: .init(value: .user(user), followedUsers: authContext.mastodonAuthenticationBox.inMemoryCache.$followingUserIds.eraseToAnyPublisher(), blockedUsers: authContext.mastodonAuthenticationBox.inMemoryCache.$blockedUserIds.eraseToAnyPublisher()), configuration: configuration ) } diff --git a/Mastodon/Protocol/Provider/DataSourceFacade+UserView.swift b/Mastodon/Protocol/Provider/DataSourceFacade+UserView.swift index 784ab6501..399267093 100644 --- a/Mastodon/Protocol/Provider/DataSourceFacade+UserView.swift +++ b/Mastodon/Protocol/Provider/DataSourceFacade+UserView.swift @@ -10,32 +10,45 @@ extension DataSourceFacade { static func responseToUserViewButtonAction( dependency: NeedsDependency & AuthContextProvider, user: ManagedObjectRecord, - buttonState: UserView.ButtonState, - viewModel: FollowedBlockedUserIdProviding + buttonState: UserView.ButtonState ) async throws { switch buttonState { - case .follow, .unfollow: + case .follow: try await DataSourceFacade.responseToUserFollowAction( dependency: dependency, user: user ) - fetchFollowedBlockedUserIds(in: viewModel) +// fetchFollowedBlockedUserIds(in: viewModel) + if let userObject = user.object(in: dependency.context.managedObjectContext) { + dependency.authContext.mastodonAuthenticationBox.inMemoryCache.followingUserIds.append(userObject.id) + } + case .unfollow: + try await DataSourceFacade.responseToUserFollowAction( + dependency: dependency, + user: user + ) + if let userObject = user.object(in: dependency.context.managedObjectContext) { + dependency.authContext.mastodonAuthenticationBox.inMemoryCache.followingUserIds.removeAll(where: { $0 == userObject.id }) + } case .blocked: try await DataSourceFacade.responseToUserBlockAction( dependency: dependency, user: user ) - fetchFollowedBlockedUserIds(in: viewModel) +// fetchFollowedBlockedUserIds(in: viewModel) + if let userObject = user.object(in: dependency.context.managedObjectContext) { + dependency.authContext.mastodonAuthenticationBox.inMemoryCache.blockedUserIds.append(userObject.id) + } case .none, .loading: break //no-op } } - private static func fetchFollowedBlockedUserIds(in viewModel: FollowedBlockedUserIdProviding) { - DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { // hack: otherwise fetching the blocked users will not return the user followed - Task { @MainActor in - try await viewModel.fetchFollowedBlockedUserIds() - } - } - } +// private static func fetchFollowedBlockedUserIds(in viewModel: FollowedBlockedUserIdProviding) { +// DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { // hack: otherwise fetching the blocked users will not return the user followed +// Task { @MainActor in +// try await viewModel.fetchFollowedBlockedUserIds() +// } +// } +// } } diff --git a/Mastodon/Scene/Profile/FamiliarFollowers/FamiliarFollowersViewController.swift b/Mastodon/Scene/Profile/FamiliarFollowers/FamiliarFollowersViewController.swift index c494de9cd..9640bc90c 100644 --- a/Mastodon/Scene/Profile/FamiliarFollowers/FamiliarFollowersViewController.swift +++ b/Mastodon/Scene/Profile/FamiliarFollowers/FamiliarFollowersViewController.swift @@ -99,8 +99,7 @@ extension FamiliarFollowersViewController: UserTableViewCellDelegate { try await DataSourceFacade.responseToUserViewButtonAction( dependency: self, user: user.asRecord, - buttonState: state, - viewModel: viewModel + buttonState: state ) } } diff --git a/Mastodon/Scene/Profile/FamiliarFollowers/FamiliarFollowersViewModel+Diffable.swift b/Mastodon/Scene/Profile/FamiliarFollowers/FamiliarFollowersViewModel+Diffable.swift index 553d8a047..0b0428c67 100644 --- a/Mastodon/Scene/Profile/FamiliarFollowers/FamiliarFollowersViewModel+Diffable.swift +++ b/Mastodon/Scene/Profile/FamiliarFollowers/FamiliarFollowersViewModel+Diffable.swift @@ -19,9 +19,7 @@ extension FamiliarFollowersViewModel { authContext: authContext, configuration: UserSection.Configuration( userTableViewCellDelegate: userTableViewCellDelegate - ), - followedUsers: followedUserIds.eraseToAnyPublisher(), - blockedUsers: blockedUserIds.eraseToAnyPublisher() + ) ) userFetchedResultsController.$records diff --git a/Mastodon/Scene/Profile/FamiliarFollowers/FamiliarFollowersViewModel.swift b/Mastodon/Scene/Profile/FamiliarFollowers/FamiliarFollowersViewModel.swift index 1f2f45a86..3e4a17e5e 100644 --- a/Mastodon/Scene/Profile/FamiliarFollowers/FamiliarFollowersViewModel.swift +++ b/Mastodon/Scene/Profile/FamiliarFollowers/FamiliarFollowersViewModel.swift @@ -11,7 +11,7 @@ import MastodonCore import MastodonSDK import CoreDataStack -final class FamiliarFollowersViewModel: FollowedBlockedUserIdProviding { +final class FamiliarFollowersViewModel { var disposeBag = Set() // input @@ -23,10 +23,7 @@ final class FamiliarFollowersViewModel: FollowedBlockedUserIdProviding { // output var diffableDataSource: UITableViewDiffableDataSource? - - var followedUserIds = CurrentValueSubject<[String], Never>([]) - var blockedUserIds = CurrentValueSubject<[String], Never>([]) - + init(context: AppContext, authContext: AuthContext) { self.context = context self.authContext = authContext diff --git a/Mastodon/Scene/Profile/FollowedBlockedUserIdProviding.swift b/Mastodon/Scene/Profile/FollowedBlockedUserIdProviding.swift deleted file mode 100644 index 59dce6db3..000000000 --- a/Mastodon/Scene/Profile/FollowedBlockedUserIdProviding.swift +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright © 2023 Mastodon gGmbH. All rights reserved. - -import Combine -import MastodonCore - -protocol FollowedBlockedUserIdProviding { - var context: AppContext { get } - var authContext: AuthContext { get } - - var followedUserIds: CurrentValueSubject<[String], Never> { get } - var blockedUserIds: CurrentValueSubject<[String], Never> { get } -} - -extension FollowedBlockedUserIdProviding { - func fetchFollowedBlockedUserIds() async throws { - let followingIds = try await context.apiService.following( - userID: authContext.mastodonAuthenticationBox.userID, - maxID: nil, - authenticationBox: authContext.mastodonAuthenticationBox - ).value.map { $0.id } - - let blockedIds = try await context.apiService.getBlocked( - authenticationBox: authContext.mastodonAuthenticationBox - ).value.map { $0.id } - - Task { @MainActor in - followedUserIds.send(followingIds) - blockedUserIds.send(blockedIds) - } - } -} diff --git a/Mastodon/Scene/Profile/Follower/FollowerListViewController.swift b/Mastodon/Scene/Profile/Follower/FollowerListViewController.swift index 4ddb0d5ed..687c11e45 100644 --- a/Mastodon/Scene/Profile/Follower/FollowerListViewController.swift +++ b/Mastodon/Scene/Profile/Follower/FollowerListViewController.swift @@ -125,8 +125,7 @@ extension FollowerListViewController: UserTableViewCellDelegate { try await DataSourceFacade.responseToUserViewButtonAction( dependency: self, user: user.asRecord, - buttonState: state, - viewModel: viewModel + buttonState: state ) } } diff --git a/Mastodon/Scene/Profile/Follower/FollowerListViewModel+Diffable.swift b/Mastodon/Scene/Profile/Follower/FollowerListViewModel+Diffable.swift index 7e3b407aa..11276c04f 100644 --- a/Mastodon/Scene/Profile/Follower/FollowerListViewModel+Diffable.swift +++ b/Mastodon/Scene/Profile/Follower/FollowerListViewModel+Diffable.swift @@ -20,9 +20,7 @@ extension FollowerListViewModel { authContext: authContext, configuration: UserSection.Configuration( userTableViewCellDelegate: userTableViewCellDelegate - ), - followedUsers: followedUserIds.eraseToAnyPublisher(), - blockedUsers: blockedUserIds.eraseToAnyPublisher() + ) ) // workaround to append loader wrong animation issue diff --git a/Mastodon/Scene/Profile/Follower/FollowerListViewModel+State.swift b/Mastodon/Scene/Profile/Follower/FollowerListViewModel+State.swift index 8b96a3712..531c2c380 100644 --- a/Mastodon/Scene/Profile/Follower/FollowerListViewModel+State.swift +++ b/Mastodon/Scene/Profile/Follower/FollowerListViewModel+State.swift @@ -155,8 +155,6 @@ extension FollowerListViewModel.State { authenticationBox: viewModel.authContext.mastodonAuthenticationBox ) logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): fetch \(response.value.count) followers") - - try await viewModel.fetchFollowedBlockedUserIds() var hasNewAppend = false var userIDs = viewModel.userFetchedResultsController.userIDs diff --git a/Mastodon/Scene/Profile/Follower/FollowerListViewModel.swift b/Mastodon/Scene/Profile/Follower/FollowerListViewModel.swift index 01c639341..ab1144e54 100644 --- a/Mastodon/Scene/Profile/Follower/FollowerListViewModel.swift +++ b/Mastodon/Scene/Profile/Follower/FollowerListViewModel.swift @@ -13,7 +13,7 @@ import GameplayKit import MastodonSDK import MastodonCore -final class FollowerListViewModel: FollowedBlockedUserIdProviding { +final class FollowerListViewModel { var disposeBag = Set() // input @@ -24,9 +24,6 @@ final class FollowerListViewModel: FollowedBlockedUserIdProviding { @Published var domain: String? @Published var userID: String? - - var followedUserIds = CurrentValueSubject<[String], Never>([]) - var blockedUserIds = CurrentValueSubject<[String], Never>([]) // output var diffableDataSource: UITableViewDiffableDataSource? diff --git a/Mastodon/Scene/Profile/Following/FollowingListViewController.swift b/Mastodon/Scene/Profile/Following/FollowingListViewController.swift index 1ece43c32..dc9d43590 100644 --- a/Mastodon/Scene/Profile/Following/FollowingListViewController.swift +++ b/Mastodon/Scene/Profile/Following/FollowingListViewController.swift @@ -123,8 +123,7 @@ extension FollowingListViewController: UserTableViewCellDelegate { try await DataSourceFacade.responseToUserViewButtonAction( dependency: self, user: user.asRecord, - buttonState: state, - viewModel: viewModel + buttonState: state ) } } diff --git a/Mastodon/Scene/Profile/Following/FollowingListViewModel+Diffable.swift b/Mastodon/Scene/Profile/Following/FollowingListViewModel+Diffable.swift index 0aba23ccf..785937335 100644 --- a/Mastodon/Scene/Profile/Following/FollowingListViewModel+Diffable.swift +++ b/Mastodon/Scene/Profile/Following/FollowingListViewModel+Diffable.swift @@ -21,9 +21,7 @@ extension FollowingListViewModel { authContext: authContext, configuration: UserSection.Configuration( userTableViewCellDelegate: userTableViewCellDelegate - ), - followedUsers: authContext.mastodonAuthenticationBox.inMemoryCache.$followingUserIds.eraseToAnyPublisher(), - blockedUsers: authContext.mastodonAuthenticationBox.inMemoryCache.$blockedUserIds.eraseToAnyPublisher() + ) ) // workaround to append loader wrong animation issue diff --git a/Mastodon/Scene/Profile/Following/FollowingListViewModel+State.swift b/Mastodon/Scene/Profile/Following/FollowingListViewModel+State.swift index 60907f99d..723e66c8e 100644 --- a/Mastodon/Scene/Profile/Following/FollowingListViewModel+State.swift +++ b/Mastodon/Scene/Profile/Following/FollowingListViewModel+State.swift @@ -158,8 +158,6 @@ extension FollowingListViewModel.State { userIDs.append(user.id) hasNewAppend = true } - - try await viewModel.fetchFollowedBlockedUserIds() let maxID = response.link?.maxID diff --git a/Mastodon/Scene/Profile/Following/FollowingListViewModel.swift b/Mastodon/Scene/Profile/Following/FollowingListViewModel.swift index fe7a3c456..e8758e645 100644 --- a/Mastodon/Scene/Profile/Following/FollowingListViewModel.swift +++ b/Mastodon/Scene/Profile/Following/FollowingListViewModel.swift @@ -13,7 +13,7 @@ import GameplayKit import MastodonCore import MastodonSDK -final class FollowingListViewModel: FollowedBlockedUserIdProviding { +final class FollowingListViewModel { var disposeBag = Set() @@ -40,10 +40,7 @@ final class FollowingListViewModel: FollowedBlockedUserIdProviding { stateMachine.enter(State.Initial.self) return stateMachine }() - - var followedUserIds = CurrentValueSubject<[String], Never>([]) - var blockedUserIds = CurrentValueSubject<[String], Never>([]) - + init( context: AppContext, authContext: AuthContext, diff --git a/Mastodon/Scene/Profile/UserLIst/FavoritedBy/FavoritedByViewController.swift b/Mastodon/Scene/Profile/UserLIst/FavoritedBy/FavoritedByViewController.swift index 9ec591112..e4ccdba67 100644 --- a/Mastodon/Scene/Profile/UserLIst/FavoritedBy/FavoritedByViewController.swift +++ b/Mastodon/Scene/Profile/UserLIst/FavoritedBy/FavoritedByViewController.swift @@ -68,9 +68,7 @@ extension FavoritedByViewController { tableView.delegate = self viewModel.setupDiffableDataSource( tableView: tableView, - userTableViewCellDelegate: self, - followedUsers: viewModel.followedUserIds.eraseToAnyPublisher(), - blockedUsers: viewModel.blockedUserIds.eraseToAnyPublisher() + userTableViewCellDelegate: self ) // setup batch fetch @@ -117,8 +115,7 @@ extension FavoritedByViewController: UserTableViewCellDelegate { try await DataSourceFacade.responseToUserViewButtonAction( dependency: self, user: user.asRecord, - buttonState: state, - viewModel: viewModel + buttonState: state ) } } diff --git a/Mastodon/Scene/Profile/UserLIst/RebloggedBy/RebloggedByViewController.swift b/Mastodon/Scene/Profile/UserLIst/RebloggedBy/RebloggedByViewController.swift index d9803d7ab..2f838fac7 100644 --- a/Mastodon/Scene/Profile/UserLIst/RebloggedBy/RebloggedByViewController.swift +++ b/Mastodon/Scene/Profile/UserLIst/RebloggedBy/RebloggedByViewController.swift @@ -68,9 +68,7 @@ extension RebloggedByViewController { tableView.delegate = self viewModel.setupDiffableDataSource( tableView: tableView, - userTableViewCellDelegate: self, - followedUsers: viewModel.followedUserIds.eraseToAnyPublisher(), - blockedUsers: viewModel.blockedUserIds.eraseToAnyPublisher() + userTableViewCellDelegate: self ) // setup batch fetch @@ -117,8 +115,7 @@ extension RebloggedByViewController: UserTableViewCellDelegate { try await DataSourceFacade.responseToUserViewButtonAction( dependency: self, user: user.asRecord, - buttonState: state, - viewModel: viewModel + buttonState: state ) } } diff --git a/Mastodon/Scene/Profile/UserLIst/UserListViewModel+Diffable.swift b/Mastodon/Scene/Profile/UserLIst/UserListViewModel+Diffable.swift index 808dc4159..bbc46063a 100644 --- a/Mastodon/Scene/Profile/UserLIst/UserListViewModel+Diffable.swift +++ b/Mastodon/Scene/Profile/UserLIst/UserListViewModel+Diffable.swift @@ -14,9 +14,7 @@ extension UserListViewModel { @MainActor func setupDiffableDataSource( tableView: UITableView, - userTableViewCellDelegate: UserTableViewCellDelegate?, - followedUsers: AnyPublisher<[String], Never>, - blockedUsers: AnyPublisher<[String], Never> + userTableViewCellDelegate: UserTableViewCellDelegate? ) { diffableDataSource = UserSection.diffableDataSource( tableView: tableView, @@ -24,9 +22,7 @@ extension UserListViewModel { authContext: authContext, configuration: UserSection.Configuration( userTableViewCellDelegate: userTableViewCellDelegate - ), - followedUsers: followedUsers, - blockedUsers: blockedUsers + ) ) // workaround to append loader wrong animation issue diff --git a/Mastodon/Scene/Profile/UserLIst/UserListViewModel+State.swift b/Mastodon/Scene/Profile/UserLIst/UserListViewModel+State.swift index 592d3cf80..c6666c6f5 100644 --- a/Mastodon/Scene/Profile/UserLIst/UserListViewModel+State.swift +++ b/Mastodon/Scene/Profile/UserLIst/UserListViewModel+State.swift @@ -165,9 +165,7 @@ extension UserListViewModel.State { userIDs.append(user.id) hasNewAppend = true } - - try await viewModel.fetchFollowedBlockedUserIds() - + let maxID = response.link?.maxID if hasNewAppend, maxID != nil { diff --git a/Mastodon/Scene/Profile/UserLIst/UserListViewModel.swift b/Mastodon/Scene/Profile/UserLIst/UserListViewModel.swift index 96e00fec3..481ac8ea0 100644 --- a/Mastodon/Scene/Profile/UserLIst/UserListViewModel.swift +++ b/Mastodon/Scene/Profile/UserLIst/UserListViewModel.swift @@ -12,7 +12,7 @@ import CoreDataStack import GameplayKit import MastodonCore -final class UserListViewModel: FollowedBlockedUserIdProviding { +final class UserListViewModel { let logger = Logger(subsystem: "UserListViewModel", category: "ViewModel") var disposeBag = Set() @@ -36,10 +36,7 @@ final class UserListViewModel: FollowedBlockedUserIdProviding { stateMachine.enter(State.Initial.self) return stateMachine }() - - var followedUserIds = CurrentValueSubject<[String], Never>([]) - var blockedUserIds = CurrentValueSubject<[String], Never>([]) - + public init( context: AppContext, authContext: AuthContext, diff --git a/Mastodon/Scene/Search/SearchDetail/SearchHistory/SearchHistoryViewController.swift b/Mastodon/Scene/Search/SearchDetail/SearchHistory/SearchHistoryViewController.swift index 74f41f42b..9f6d60e17 100644 --- a/Mastodon/Scene/Search/SearchDetail/SearchHistory/SearchHistoryViewController.swift +++ b/Mastodon/Scene/Search/SearchDetail/SearchHistory/SearchHistoryViewController.swift @@ -55,12 +55,6 @@ extension SearchHistoryViewController { collectionView: collectionView, searchHistorySectionHeaderCollectionReusableViewDelegate: self ) - - Task { - do { - try await viewModel.fetchFollowedBlockedUserIds() - } catch {} - } } } @@ -136,8 +130,7 @@ extension SearchHistoryViewController: SearchHistorySectionHeaderCollectionReusa try await DataSourceFacade.responseToUserViewButtonAction( dependency: self, user: user.asRecord, - buttonState: state, - viewModel: viewModel + buttonState: state ) } } diff --git a/Mastodon/Scene/Search/SearchDetail/SearchHistory/SearchHistoryViewModel.swift b/Mastodon/Scene/Search/SearchDetail/SearchHistory/SearchHistoryViewModel.swift index 28dc5409f..d20f2d495 100644 --- a/Mastodon/Scene/Search/SearchDetail/SearchHistory/SearchHistoryViewModel.swift +++ b/Mastodon/Scene/Search/SearchDetail/SearchHistory/SearchHistoryViewModel.swift @@ -11,7 +11,7 @@ import CoreDataStack import CommonOSLog import MastodonCore -final class SearchHistoryViewModel: FollowedBlockedUserIdProviding { +final class SearchHistoryViewModel { var disposeBag = Set() // input @@ -21,9 +21,7 @@ final class SearchHistoryViewModel: FollowedBlockedUserIdProviding { // output var diffableDataSource: UICollectionViewDiffableDataSource? - var followedUserIds = CurrentValueSubject<[String], Never>([]) - var blockedUserIds = CurrentValueSubject<[String], Never>([]) - + init(context: AppContext, authContext: AuthContext) { self.context = context self.authContext = authContext diff --git a/Mastodon/Scene/Search/SearchDetail/SearchResult/SearchResultViewController.swift b/Mastodon/Scene/Search/SearchDetail/SearchResult/SearchResultViewController.swift index 6d52292e0..fc4886bb0 100644 --- a/Mastodon/Scene/Search/SearchDetail/SearchResult/SearchResultViewController.swift +++ b/Mastodon/Scene/Search/SearchDetail/SearchResult/SearchResultViewController.swift @@ -265,8 +265,7 @@ extension SearchResultViewController: UserTableViewCellDelegate { try await DataSourceFacade.responseToUserViewButtonAction( dependency: self, user: user.asRecord, - buttonState: state, - viewModel: viewModel + buttonState: state ) } } diff --git a/Mastodon/Scene/Search/SearchDetail/SearchResult/SearchResultViewModel+Diffable.swift b/Mastodon/Scene/Search/SearchDetail/SearchResult/SearchResultViewModel+Diffable.swift index 962e9e0bc..225f79b02 100644 --- a/Mastodon/Scene/Search/SearchDetail/SearchResult/SearchResultViewModel+Diffable.swift +++ b/Mastodon/Scene/Search/SearchDetail/SearchResult/SearchResultViewModel+Diffable.swift @@ -23,9 +23,7 @@ extension SearchResultViewModel { authContext: authContext, statusViewTableViewCellDelegate: statusTableViewCellDelegate, userTableViewCellDelegate: userTableViewCellDelegate - ), - followedUsers: followedUserIds.eraseToAnyPublisher(), - blockedUsers: blockedUserIds.eraseToAnyPublisher() + ) ) var snapshot = NSDiffableDataSourceSnapshot() diff --git a/Mastodon/Scene/Search/SearchDetail/SearchResult/SearchResultViewModel.swift b/Mastodon/Scene/Search/SearchDetail/SearchResult/SearchResultViewModel.swift index 315e725b6..c4cfa0f54 100644 --- a/Mastodon/Scene/Search/SearchDetail/SearchResult/SearchResultViewModel.swift +++ b/Mastodon/Scene/Search/SearchDetail/SearchResult/SearchResultViewModel.swift @@ -14,7 +14,7 @@ import CommonOSLog import MastodonSDK import MastodonCore -final class SearchResultViewModel: FollowedBlockedUserIdProviding { +final class SearchResultViewModel { var disposeBag = Set() // input @@ -48,9 +48,6 @@ final class SearchResultViewModel: FollowedBlockedUserIdProviding { }() let didDataSourceUpdate = PassthroughSubject() - var followedUserIds = CurrentValueSubject<[String], Never>([]) - var blockedUserIds = CurrentValueSubject<[String], Never>([]) - init(context: AppContext, authContext: AuthContext, searchScope: SearchDetailViewModel.SearchScope) { self.context = context self.authContext = authContext