Revert FollowedBlockedUserIdProviding (IOS-140)

This commit is contained in:
Marcus Kida 2023-05-09 11:33:31 +02:00
parent c7c635d32a
commit 5efdb3c209
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
27 changed files with 56 additions and 134 deletions

View File

@ -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 = "<group>"; };
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 = "<group>"; };
27D701F4292FC2D60031BCBB /* DataSourceFacade+URL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DataSourceFacade+URL.swift"; sourceTree = "<group>"; };
2A15964D2A09012300C603BE /* FollowedBlockedUserIdProviding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FollowedBlockedUserIdProviding.swift; sourceTree = "<group>"; };
2A1BF99429F7E68400FA1BA5 /* DataSourceFacade+UserView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DataSourceFacade+UserView.swift"; sourceTree = "<group>"; };
2A1FE47B2938BB2600784BF1 /* FollowedTagsViewModel+DiffableDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FollowedTagsViewModel+DiffableDataSource.swift"; sourceTree = "<group>"; };
2A1FE47D2938C11200784BF1 /* Collection+IsNotEmpty.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Collection+IsNotEmpty.swift"; sourceTree = "<group>"; };
@ -2705,7 +2703,6 @@
DBCC3B8E26148F7B0045B23D /* CachedProfileViewModel.swift */,
DBAE3FAE26172FC0004B8251 /* RemoteProfileViewModel.swift */,
DBB525632612C988002F1F29 /* MeProfileViewModel.swift */,
2A15964D2A09012300C603BE /* FollowedBlockedUserIdProviding.swift */,
);
path = Profile;
sourceTree = "<group>";
@ -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 */,

View File

@ -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
)
}

View File

@ -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<SearchResultSection, SearchResultItem> {
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
)
}

View File

@ -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<UserSection, UserItem> {
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
)
}

View File

@ -10,32 +10,45 @@ extension DataSourceFacade {
static func responseToUserViewButtonAction(
dependency: NeedsDependency & AuthContextProvider,
user: ManagedObjectRecord<MastodonUser>,
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()
// }
// }
// }
}

View File

@ -99,8 +99,7 @@ extension FamiliarFollowersViewController: UserTableViewCellDelegate {
try await DataSourceFacade.responseToUserViewButtonAction(
dependency: self,
user: user.asRecord,
buttonState: state,
viewModel: viewModel
buttonState: state
)
}
}

View File

@ -19,9 +19,7 @@ extension FamiliarFollowersViewModel {
authContext: authContext,
configuration: UserSection.Configuration(
userTableViewCellDelegate: userTableViewCellDelegate
),
followedUsers: followedUserIds.eraseToAnyPublisher(),
blockedUsers: blockedUserIds.eraseToAnyPublisher()
)
)
userFetchedResultsController.$records

View File

@ -11,7 +11,7 @@ import MastodonCore
import MastodonSDK
import CoreDataStack
final class FamiliarFollowersViewModel: FollowedBlockedUserIdProviding {
final class FamiliarFollowersViewModel {
var disposeBag = Set<AnyCancellable>()
// input
@ -24,9 +24,6 @@ final class FamiliarFollowersViewModel: FollowedBlockedUserIdProviding {
// output
var diffableDataSource: UITableViewDiffableDataSource<UserSection, UserItem>?
var followedUserIds = CurrentValueSubject<[String], Never>([])
var blockedUserIds = CurrentValueSubject<[String], Never>([])
init(context: AppContext, authContext: AuthContext) {
self.context = context
self.authContext = authContext

View File

@ -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)
}
}
}

View File

@ -125,8 +125,7 @@ extension FollowerListViewController: UserTableViewCellDelegate {
try await DataSourceFacade.responseToUserViewButtonAction(
dependency: self,
user: user.asRecord,
buttonState: state,
viewModel: viewModel
buttonState: state
)
}
}

View File

@ -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

View File

@ -156,8 +156,6 @@ extension FollowerListViewModel.State {
)
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
for user in response.value {

View File

@ -13,7 +13,7 @@ import GameplayKit
import MastodonSDK
import MastodonCore
final class FollowerListViewModel: FollowedBlockedUserIdProviding {
final class FollowerListViewModel {
var disposeBag = Set<AnyCancellable>()
// input
@ -25,9 +25,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<UserSection, UserItem>?
private(set) lazy var stateMachine: GKStateMachine = {

View File

@ -123,8 +123,7 @@ extension FollowingListViewController: UserTableViewCellDelegate {
try await DataSourceFacade.responseToUserViewButtonAction(
dependency: self,
user: user.asRecord,
buttonState: state,
viewModel: viewModel
buttonState: state
)
}
}

View File

@ -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

View File

@ -159,8 +159,6 @@ extension FollowingListViewModel.State {
hasNewAppend = true
}
try await viewModel.fetchFollowedBlockedUserIds()
let maxID = response.link?.maxID
if hasNewAppend, maxID != nil {

View File

@ -13,7 +13,7 @@ import GameplayKit
import MastodonCore
import MastodonSDK
final class FollowingListViewModel: FollowedBlockedUserIdProviding {
final class FollowingListViewModel {
var disposeBag = Set<AnyCancellable>()
@ -41,9 +41,6 @@ final class FollowingListViewModel: FollowedBlockedUserIdProviding {
return stateMachine
}()
var followedUserIds = CurrentValueSubject<[String], Never>([])
var blockedUserIds = CurrentValueSubject<[String], Never>([])
init(
context: AppContext,
authContext: AuthContext,

View File

@ -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
)
}
}

View File

@ -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
)
}
}

View File

@ -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

View File

@ -166,8 +166,6 @@ extension UserListViewModel.State {
hasNewAppend = true
}
try await viewModel.fetchFollowedBlockedUserIds()
let maxID = response.link?.maxID
if hasNewAppend, maxID != nil {

View File

@ -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<AnyCancellable>()
@ -37,9 +37,6 @@ final class UserListViewModel: FollowedBlockedUserIdProviding {
return stateMachine
}()
var followedUserIds = CurrentValueSubject<[String], Never>([])
var blockedUserIds = CurrentValueSubject<[String], Never>([])
public init(
context: AppContext,
authContext: AuthContext,

View File

@ -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
)
}
}

View File

@ -11,7 +11,7 @@ import CoreDataStack
import CommonOSLog
import MastodonCore
final class SearchHistoryViewModel: FollowedBlockedUserIdProviding {
final class SearchHistoryViewModel {
var disposeBag = Set<AnyCancellable>()
// input
@ -21,8 +21,6 @@ final class SearchHistoryViewModel: FollowedBlockedUserIdProviding {
// output
var diffableDataSource: UICollectionViewDiffableDataSource<SearchHistorySection, SearchHistoryItem>?
var followedUserIds = CurrentValueSubject<[String], Never>([])
var blockedUserIds = CurrentValueSubject<[String], Never>([])
init(context: AppContext, authContext: AuthContext) {
self.context = context

View File

@ -265,8 +265,7 @@ extension SearchResultViewController: UserTableViewCellDelegate {
try await DataSourceFacade.responseToUserViewButtonAction(
dependency: self,
user: user.asRecord,
buttonState: state,
viewModel: viewModel
buttonState: state
)
}
}

View File

@ -23,9 +23,7 @@ extension SearchResultViewModel {
authContext: authContext,
statusViewTableViewCellDelegate: statusTableViewCellDelegate,
userTableViewCellDelegate: userTableViewCellDelegate
),
followedUsers: followedUserIds.eraseToAnyPublisher(),
blockedUsers: blockedUserIds.eraseToAnyPublisher()
)
)
var snapshot = NSDiffableDataSourceSnapshot<SearchResultSection, SearchResultItem>()

View File

@ -14,7 +14,7 @@ import CommonOSLog
import MastodonSDK
import MastodonCore
final class SearchResultViewModel: FollowedBlockedUserIdProviding {
final class SearchResultViewModel {
var disposeBag = Set<AnyCancellable>()
// input
@ -48,9 +48,6 @@ final class SearchResultViewModel: FollowedBlockedUserIdProviding {
}()
let didDataSourceUpdate = PassthroughSubject<Void, Never>()
var followedUserIds = CurrentValueSubject<[String], Never>([])
var blockedUserIds = CurrentValueSubject<[String], Never>([])
init(context: AppContext, authContext: AuthContext, searchScope: SearchDetailViewModel.SearchScope) {
self.context = context
self.authContext = authContext