diff --git a/Mastodon.xcodeproj/project.pbxproj b/Mastodon.xcodeproj/project.pbxproj index 892c6cd57..45d7d3da8 100644 --- a/Mastodon.xcodeproj/project.pbxproj +++ b/Mastodon.xcodeproj/project.pbxproj @@ -137,6 +137,11 @@ D81A22752AB4643200905D71 /* SearchResultsOverviewTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D81A22742AB4643200905D71 /* SearchResultsOverviewTableViewController.swift */; }; D81A22782AB4782400905D71 /* SearchResultOverviewSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = D81A22772AB4782400905D71 /* SearchResultOverviewSection.swift */; }; D81A227B2AB47B9A00905D71 /* SearchResultDefaultSectionTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D81A227A2AB47B9A00905D71 /* SearchResultDefaultSectionTableViewCell.swift */; }; + D81A94122B07A1BE0067A19D /* ProfileCardTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D81A94112B07A1BE0067A19D /* ProfileCardTableViewCell.swift */; }; + D81A94132B07A1BE0067A19D /* ProfileCardTableViewCell+Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D81A94102B07A1BE0067A19D /* ProfileCardTableViewCell+Configuration.swift */; }; + D81A94172B07A1D30067A19D /* ProfileCardView+Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D81A94162B07A1D30067A19D /* ProfileCardView+Configuration.swift */; }; + D81A94182B07A1D30067A19D /* ProfileCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D81A94142B07A1D30067A19D /* ProfileCardView.swift */; }; + D81A94192B07A1D30067A19D /* ProfileCardView+ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D81A94152B07A1D30067A19D /* ProfileCardView+ViewModel.swift */; }; D81D12462A4E1861005009D4 /* PolicySelectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D81D12452A4E1861005009D4 /* PolicySelectionViewController.swift */; }; D81D124B2A4E1914005009D4 /* ToggleTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D81D124A2A4E1914005009D4 /* ToggleTableViewCell.swift */; }; D82BD7532ABC44C2009A374A /* Coordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8F9170E2A4B47EF008A5370 /* Coordinator.swift */; }; @@ -451,7 +456,6 @@ DBCBCBF4267CB070000F5B51 /* Decode85.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBCBCBF3267CB070000F5B51 /* Decode85.swift */; }; DBCBED1726132DB500B49291 /* UserTimelineViewModel+Diffable.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBCBED1626132DB500B49291 /* UserTimelineViewModel+Diffable.swift */; }; DBCC3B30261440A50045B23D /* UITabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBCC3B2F261440A50045B23D /* UITabBarController.swift */; }; - DBCC3B8F26148F7B0045B23D /* CachedProfileViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBCC3B8E26148F7B0045B23D /* CachedProfileViewModel.swift */; }; DBD376B2269302A4007FEC24 /* UITableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBD376B1269302A4007FEC24 /* UITableViewCell.swift */; }; DBD5B1F827BCFD9D00BD6B38 /* DataSourceProvider+TableViewControllerNavigateable.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBD5B1F727BCFD9D00BD6B38 /* DataSourceProvider+TableViewControllerNavigateable.swift */; }; DBD5B1FA27BD013700BD6B38 /* DataSourceProvider+StatusTableViewControllerNavigateable.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBD5B1F927BD013700BD6B38 /* DataSourceProvider+StatusTableViewControllerNavigateable.swift */; }; @@ -794,6 +798,11 @@ D81A940D2B04E7AC0067A19D /* hy */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hy; path = hy.lproj/LaunchScreen.strings; sourceTree = ""; }; D81A940E2B04E7AD0067A19D /* hy */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hy; path = hy.lproj/MainInterface.strings; sourceTree = ""; }; D81A940F2B04E7AD0067A19D /* hy */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hy; path = hy.lproj/InfoPlist.strings; sourceTree = ""; }; + D81A94102B07A1BE0067A19D /* ProfileCardTableViewCell+Configuration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ProfileCardTableViewCell+Configuration.swift"; sourceTree = ""; }; + D81A94112B07A1BE0067A19D /* ProfileCardTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileCardTableViewCell.swift; sourceTree = ""; }; + D81A94142B07A1D30067A19D /* ProfileCardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileCardView.swift; sourceTree = ""; }; + D81A94152B07A1D30067A19D /* ProfileCardView+ViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ProfileCardView+ViewModel.swift"; sourceTree = ""; }; + D81A94162B07A1D30067A19D /* ProfileCardView+Configuration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ProfileCardView+Configuration.swift"; sourceTree = ""; }; D81D12452A4E1861005009D4 /* PolicySelectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PolicySelectionViewController.swift; sourceTree = ""; }; D81D124A2A4E1914005009D4 /* ToggleTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToggleTableViewCell.swift; sourceTree = ""; }; D82463522A52B47B00A3DBDD /* be */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = be; path = be.lproj/Intents.strings; sourceTree = ""; }; @@ -1194,7 +1203,6 @@ DBCBCBF3267CB070000F5B51 /* Decode85.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Decode85.swift; sourceTree = ""; }; DBCBED1626132DB500B49291 /* UserTimelineViewModel+Diffable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserTimelineViewModel+Diffable.swift"; sourceTree = ""; }; DBCC3B2F261440A50045B23D /* UITabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITabBarController.swift; sourceTree = ""; }; - DBCC3B8E26148F7B0045B23D /* CachedProfileViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CachedProfileViewModel.swift; sourceTree = ""; }; DBD376B1269302A4007FEC24 /* UITableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITableViewCell.swift; sourceTree = ""; }; DBD5B1F727BCFD9D00BD6B38 /* DataSourceProvider+TableViewControllerNavigateable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DataSourceProvider+TableViewControllerNavigateable.swift"; sourceTree = ""; }; DBD5B1F927BD013700BD6B38 /* DataSourceProvider+StatusTableViewControllerNavigateable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DataSourceProvider+StatusTableViewControllerNavigateable.swift"; sourceTree = ""; }; @@ -2094,8 +2102,6 @@ DB3E6FE52806A5BA00B035AE /* Discovery */ = { isa = PBXGroup; children = ( - DB3E6FE32806A5B800B035AE /* DiscoverySection.swift */, - DB3E6FE62806A7A200B035AE /* DiscoveryItem.swift */, ); path = Discovery; sourceTree = ""; @@ -2114,6 +2120,11 @@ DB3E6FF62807C40500B035AE /* ForYou */ = { isa = PBXGroup; children = ( + D81A94142B07A1D30067A19D /* ProfileCardView.swift */, + D81A94162B07A1D30067A19D /* ProfileCardView+Configuration.swift */, + D81A94152B07A1D30067A19D /* ProfileCardView+ViewModel.swift */, + D81A94112B07A1BE0067A19D /* ProfileCardTableViewCell.swift */, + D81A94102B07A1BE0067A19D /* ProfileCardTableViewCell+Configuration.swift */, DB3E6FF42807C40300B035AE /* DiscoveryForYouViewController.swift */, DB3E6FF72807C45300B035AE /* DiscoveryForYouViewModel.swift */, DB3E6FF92807C47900B035AE /* DiscoveryForYouViewModel+Diffable.swift */, @@ -2763,7 +2774,6 @@ DBFEEC97279BDC6A004F81DD /* About */, DB9D6BFE25E4F5940051B173 /* ProfileViewController.swift */, DBB5255D2611F07A002F1F29 /* ProfileViewModel.swift */, - DBCC3B8E26148F7B0045B23D /* CachedProfileViewModel.swift */, DBAE3FAE26172FC0004B8251 /* RemoteProfileViewModel.swift */, DBB525632612C988002F1F29 /* MeProfileViewModel.swift */, ); @@ -2926,6 +2936,8 @@ DB3E6FED2806D7FC00B035AE /* News */, DB3EA8E7281B79E500598866 /* Community */, DB3E6FF62807C40500B035AE /* ForYou */, + DB3E6FE32806A5B800B035AE /* DiscoverySection.swift */, + DB3E6FE62806A7A200B035AE /* DiscoveryItem.swift */, DBDFF19928055A1400557A48 /* DiscoveryViewController.swift */, DBDFF19B28055BD600557A48 /* DiscoveryViewModel.swift */, ); @@ -3727,6 +3739,7 @@ 2D38F1EB25CD477000561493 /* HomeTimelineViewModel+LoadLatestState.swift in Sources */, DB5B7295273112B100081888 /* FollowingListViewController.swift in Sources */, 0F202201261326E6000C64BF /* HashtagTimelineViewModel.swift in Sources */, + D81A94172B07A1D30067A19D /* ProfileCardView+Configuration.swift in Sources */, DB63F7452799056400455B82 /* HashtagTableViewCell.swift in Sources */, DBAE3FAF26172FC0004B8251 /* RemoteProfileViewModel.swift in Sources */, D82BD7552ABC73AF009A374A /* NotificationPolicyTableViewCell.swift in Sources */, @@ -3772,6 +3785,7 @@ 2A506CF4292CD85800059C37 /* FollowedTagsViewController.swift in Sources */, DB1D843026566512000346B3 /* KeyboardPreference.swift in Sources */, DB852D1926FAEB6B00FC9D81 /* SidebarViewController.swift in Sources */, + D81A94132B07A1BE0067A19D /* ProfileCardTableViewCell+Configuration.swift in Sources */, 2D206B9225F60EA700143C56 /* UIControl.swift in Sources */, 85904C02293BC0EB0011C817 /* ImageProvider.swift in Sources */, DBDFF1932805554900557A48 /* DiscoveryPostsViewModel.swift in Sources */, @@ -3799,6 +3813,7 @@ DB63F769279A5EBB00455B82 /* NotificationTimelineViewModel+Diffable.swift in Sources */, DBFEEC9B279BDDD9004F81DD /* ProfileAboutViewModel+Diffable.swift in Sources */, DBB525562611EDCA002F1F29 /* UserTimelineViewModel.swift in Sources */, + D81A94192B07A1D30067A19D /* ProfileCardView+ViewModel.swift in Sources */, D8916DC029211BE500124085 /* ContentSizedTableView.swift in Sources */, DB0618012785732C0030EE79 /* ServerRulesTableViewCell.swift in Sources */, DB98EB5C27B10A730082E365 /* ReportSupplementaryViewModel.swift in Sources */, @@ -3875,7 +3890,6 @@ 2D38F20825CD491300561493 /* DisposeBagCollectable.swift in Sources */, D8F9170D2A4B3C6F008A5370 /* AboutMastodonTableViewCell.swift in Sources */, DB697DE1278F5296004EF2F7 /* DataSourceFacade+Model.swift in Sources */, - DBCC3B8F26148F7B0045B23D /* CachedProfileViewModel.swift in Sources */, DB4F097526A037F500D62E92 /* SearchHistoryViewModel.swift in Sources */, DB3EA8E9281B7A3700598866 /* DiscoveryCommunityViewModel.swift in Sources */, D87BFC8B291D5C6B00FEE264 /* MastodonLoginView.swift in Sources */, @@ -3974,6 +3988,7 @@ DBEFCD7D282A2A3B00C0ABEA /* ReportServerRulesViewController.swift in Sources */, DBB525362611ECEB002F1F29 /* UserTimelineViewController.swift in Sources */, D8F917122A4C6B67008A5370 /* GeneralSettingsViewController.swift in Sources */, + D81A94122B07A1BE0067A19D /* ProfileCardTableViewCell.swift in Sources */, DB98EB4927B0F0CD0082E365 /* ReportStatusTableViewCell.swift in Sources */, 855149CA29606D6400943D96 /* PortraitAlertController.swift in Sources */, DBF3B7412733EB9400E21627 /* MastodonLocalCode.swift in Sources */, @@ -3981,6 +3996,7 @@ DB4F096A269EDAD200D62E92 /* SearchResultViewModel+State.swift in Sources */, D8ECC8102AC31EA400AE0818 /* NotificationSettingsDisabledTableViewCell.swift in Sources */, 5BB04FF5262F0E6D0043BFF6 /* ReportSection.swift in Sources */, + D81A94182B07A1D30067A19D /* ProfileCardView.swift in Sources */, DBEFCD82282A2AB100C0ABEA /* ReportServerRulesView.swift in Sources */, DBA94436265CBB7400C537E1 /* ProfileFieldItem.swift in Sources */, 2A3F6FE5292F6E44002E6DA7 /* FollowedTagsTableViewCell.swift in Sources */, diff --git a/Mastodon/Protocol/Provider/DataSourceFacade+Profile.swift b/Mastodon/Protocol/Provider/DataSourceFacade+Profile.swift index 30c024f54..c34b62704 100644 --- a/Mastodon/Protocol/Provider/DataSourceFacade+Profile.swift +++ b/Mastodon/Protocol/Provider/DataSourceFacade+Profile.swift @@ -42,10 +42,10 @@ extension DataSourceFacade { return } - let profileViewModel = CachedProfileViewModel( + let profileViewModel = ProfileViewModel( context: provider.context, authContext: provider.authContext, - mastodonUser: user + optionalMastodonUser: user ) _ = provider.coordinator.present( @@ -125,7 +125,7 @@ extension DataSourceFacade { let _user = provider.context.managedObjectContext.safeFetch(request).first if let user = _user { - return CachedProfileViewModel(context: provider.context, authContext: provider.authContext, mastodonUser: user) + return ProfileViewModel(context: provider.context, authContext: provider.authContext, optionalMastodonUser: user) } else { return RemoteProfileViewModel(context: provider.context, authContext: provider.authContext, userID: userID) } diff --git a/Mastodon/Diffable/Discovery/DiscoveryItem.swift b/Mastodon/Scene/Discovery/DiscoveryItem.swift similarity index 78% rename from Mastodon/Diffable/Discovery/DiscoveryItem.swift rename to Mastodon/Scene/Discovery/DiscoveryItem.swift index 024c4a2da..0d9a69a4e 100644 --- a/Mastodon/Diffable/Discovery/DiscoveryItem.swift +++ b/Mastodon/Scene/Discovery/DiscoveryItem.swift @@ -7,11 +7,10 @@ import Foundation import MastodonSDK -import CoreDataStack enum DiscoveryItem: Hashable { case hashtag(Mastodon.Entity.Tag) case link(Mastodon.Entity.Link) - case user(ManagedObjectRecord) + case account(Mastodon.Entity.Account) case bottomLoader } diff --git a/Mastodon/Diffable/Discovery/DiscoverySection.swift b/Mastodon/Scene/Discovery/DiscoverySection.swift similarity index 88% rename from Mastodon/Diffable/Discovery/DiscoverySection.swift rename to Mastodon/Scene/Discovery/DiscoverySection.swift index bb93ffc28..fd028fbd1 100644 --- a/Mastodon/Diffable/Discovery/DiscoverySection.swift +++ b/Mastodon/Scene/Discovery/DiscoverySection.swift @@ -55,19 +55,15 @@ extension DiscoverySection { let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: NewsTableViewCell.self), for: indexPath) as! NewsTableViewCell cell.newsView.configure(link: link) return cell - case .user(let record): + case .account(let account): let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ProfileCardTableViewCell.self), for: indexPath) as! ProfileCardTableViewCell - context.managedObjectContext.performAndWait { - guard let user = record.object(in: context.managedObjectContext) else { return } - cell.configure( - tableView: tableView, - user: user, - profileCardTableViewCellDelegate: configuration.profileCardTableViewCellDelegate - ) + + cell.configure(tableView: tableView, account: account, profileCardTableViewCellDelegate: configuration.profileCardTableViewCellDelegate) + // bind familiarFollowers if let familiarFollowers = configuration.familiarFollowers { familiarFollowers - .map { array in array.first(where: { $0.id == user.id }) } + .map { array in array.first(where: { $0.id == account.id }) } .assign(to: \.familiarFollowers, on: cell.profileCardView.viewModel) .store(in: &cell.disposeBag) } else { @@ -75,7 +71,7 @@ extension DiscoverySection { } // bind me cell.profileCardView.viewModel.relationshipViewModel.me = configuration.authContext.mastodonAuthenticationBox.authentication.user(in: context.managedObjectContext) - } +// } return cell case .bottomLoader: let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as! TimelineBottomLoaderTableViewCell diff --git a/Mastodon/Scene/Discovery/ForYou/DiscoveryForYouViewController.swift b/Mastodon/Scene/Discovery/ForYou/DiscoveryForYouViewController.swift index 952ba4937..6e5cbcb15 100644 --- a/Mastodon/Scene/Discovery/ForYou/DiscoveryForYouViewController.swift +++ b/Mastodon/Scene/Discovery/ForYou/DiscoveryForYouViewController.swift @@ -96,18 +96,11 @@ extension DiscoveryForYouViewController: AuthContextProvider { extension DiscoveryForYouViewController: UITableViewDelegate { func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - guard case let .user(record) = viewModel.diffableDataSource?.itemIdentifier(for: indexPath) else { return } - guard let user = record.object(in: context.managedObjectContext) else { return } - let profileViewModel = CachedProfileViewModel( - context: context, - authContext: viewModel.authContext, - mastodonUser: user - ) - _ = coordinator.present( - scene: .profile(viewModel: profileViewModel), - from: self, - transition: .show - ) + guard case let .account(account) = viewModel.diffableDataSource?.itemIdentifier(for: indexPath) else { return } + + Task { + await DataSourceFacade.coordinateToProfileScene(provider: self, account: account) + } } } @@ -120,14 +113,11 @@ extension DiscoveryForYouViewController: ProfileCardTableViewCellDelegate { relationshipButtonDidPressed button: ProfileRelationshipActionButton ) { guard let indexPath = tableView.indexPath(for: cell) else { return } - guard case let .user(record) = viewModel.diffableDataSource?.itemIdentifier(for: indexPath) else { return } - + guard case let .account(account) = viewModel.diffableDataSource?.itemIdentifier(for: indexPath) else { return } + Task { - try await DataSourceFacade.responseToUserFollowAction( - dependency: self, - user: record - ) - } // end Task + try await DataSourceFacade.responseToUserFollowAction(dependency: self, user: account) + } } func profileCardTableViewCell( @@ -136,10 +126,9 @@ extension DiscoveryForYouViewController: ProfileCardTableViewCellDelegate { familiarFollowersDashboardViewDidPressed view: FamiliarFollowersDashboardView ) { guard let indexPath = tableView.indexPath(for: cell) else { return } - guard case let .user(record) = viewModel.diffableDataSource?.itemIdentifier(for: indexPath) else { return } - guard let user = record.object(in: context.managedObjectContext) else { return } - - let userID = user.id + guard case let .account(account) = viewModel.diffableDataSource?.itemIdentifier(for: indexPath) else { return } + + let userID = account.id let _familiarFollowers = viewModel.familiarFollowers.first(where: { $0.id == userID }) guard let familiarFollowers = _familiarFollowers else { assertionFailure() diff --git a/Mastodon/Scene/Discovery/ForYou/DiscoveryForYouViewModel+Diffable.swift b/Mastodon/Scene/Discovery/ForYou/DiscoveryForYouViewModel+Diffable.swift index 31b14c55d..c4ca3abae 100644 --- a/Mastodon/Scene/Discovery/ForYou/DiscoveryForYouViewModel+Diffable.swift +++ b/Mastodon/Scene/Discovery/ForYou/DiscoveryForYouViewModel+Diffable.swift @@ -29,16 +29,16 @@ extension DiscoveryForYouViewModel { try await fetch() } - userFetchedResultsController.$records + $accounts .receive(on: DispatchQueue.main) - .sink { [weak self] records in + .sink { [weak self] accounts in guard let self = self else { return } guard let diffableDataSource = self.diffableDataSource else { return } var snapshot = NSDiffableDataSourceSnapshot() snapshot.appendSections([.forYou]) - let items = records.map { DiscoveryItem.user($0) } + let items = accounts.map { DiscoveryItem.account($0) } snapshot.appendItems(items, toSection: .forYou) diffableDataSource.apply(snapshot, animatingDifferences: false) diff --git a/Mastodon/Scene/Discovery/ForYou/DiscoveryForYouViewModel.swift b/Mastodon/Scene/Discovery/ForYou/DiscoveryForYouViewModel.swift index fcd521a36..53549209d 100644 --- a/Mastodon/Scene/Discovery/ForYou/DiscoveryForYouViewModel.swift +++ b/Mastodon/Scene/Discovery/ForYou/DiscoveryForYouViewModel.swift @@ -8,8 +8,6 @@ import UIKit import Combine import GameplayKit -import CoreData -import CoreDataStack import MastodonSDK import MastodonCore @@ -20,11 +18,11 @@ final class DiscoveryForYouViewModel { // input let context: AppContext let authContext: AuthContext - let userFetchedResultsController: UserFetchedResultsController - + @MainActor @Published var familiarFollowers: [Mastodon.Entity.FamiliarFollowers] = [] @Published var isFetching = false + @Published var accounts: [Mastodon.Entity.Account] // output var diffableDataSource: UITableViewDiffableDataSource? @@ -33,12 +31,7 @@ final class DiscoveryForYouViewModel { init(context: AppContext, authContext: AuthContext) { self.context = context self.authContext = authContext - self.userFetchedResultsController = UserFetchedResultsController( - managedObjectContext: context.managedObjectContext, - domain: authContext.mastodonAuthenticationBox.domain, - additionalPredicate: nil - ) - // end init + self.accounts = [] } } @@ -46,40 +39,39 @@ extension DiscoveryForYouViewModel { @MainActor func fetch() async throws { - guard !isFetching else { return } + guard isFetching == false else { return } isFetching = true defer { isFetching = false } do { - let userIDs = try await fetchSuggestionAccounts() - - let _familiarFollowersResponse = try? await context.apiService.familiarFollowers( - query: .init(ids: userIDs), + let suggestedAccounts = try await fetchSuggestionAccounts() + + let familiarFollowersResponse = try? await context.apiService.familiarFollowers( + query: .init(ids: suggestedAccounts.compactMap { $0.id }), authenticationBox: authContext.mastodonAuthenticationBox - ) - familiarFollowers = _familiarFollowersResponse?.value ?? [] - userFetchedResultsController.userIDs = userIDs + ).value + familiarFollowers = familiarFollowersResponse ?? [] + accounts = suggestedAccounts } catch { // do nothing } } - private func fetchSuggestionAccounts() async throws -> [Mastodon.Entity.Account.ID] { + private func fetchSuggestionAccounts() async throws -> [Mastodon.Entity.Account] { do { let response = try await context.apiService.suggestionAccountV2( query: nil, authenticationBox: authContext.mastodonAuthenticationBox - ) - let userIDs = response.value.map { $0.account.id } - return userIDs + ).value + return response.compactMap { $0.account } } catch { // fallback V1 let response = try await context.apiService.suggestionAccount( query: nil, authenticationBox: authContext.mastodonAuthenticationBox - ) - let userIDs = response.value.map { $0.id } - return userIDs + ).value + + return response } } } diff --git a/MastodonSDK/Sources/MastodonUI/View/TableViewCell/ProfileCardTableViewCell+Configuration.swift b/Mastodon/Scene/Discovery/ForYou/ProfileCardTableViewCell+Configuration.swift similarity index 86% rename from MastodonSDK/Sources/MastodonUI/View/TableViewCell/ProfileCardTableViewCell+Configuration.swift rename to Mastodon/Scene/Discovery/ForYou/ProfileCardTableViewCell+Configuration.swift index d4767048a..4a50e611c 100644 --- a/MastodonSDK/Sources/MastodonUI/View/TableViewCell/ProfileCardTableViewCell+Configuration.swift +++ b/Mastodon/Scene/Discovery/ForYou/ProfileCardTableViewCell+Configuration.swift @@ -6,14 +6,13 @@ // import UIKit -import CoreDataStack import MastodonSDK extension ProfileCardTableViewCell { public func configure( tableView: UITableView, - user: MastodonUser, + account: Mastodon.Entity.Account, profileCardTableViewCellDelegate: ProfileCardTableViewCellDelegate? ) { if profileCardView.frame == .zero { @@ -22,9 +21,9 @@ extension ProfileCardTableViewCell { shadowBackgroundContainer.frame.size.width = layoutMarginsGuide.layoutFrame.width profileCardView.setupLayoutFrame(layoutMarginsGuide.layoutFrame) } - - profileCardView.configure(user: user) + + profileCardView.configure(account: account) delegate = profileCardTableViewCellDelegate } - + } diff --git a/MastodonSDK/Sources/MastodonUI/View/TableViewCell/ProfileCardTableViewCell.swift b/Mastodon/Scene/Discovery/ForYou/ProfileCardTableViewCell.swift similarity index 99% rename from MastodonSDK/Sources/MastodonUI/View/TableViewCell/ProfileCardTableViewCell.swift rename to Mastodon/Scene/Discovery/ForYou/ProfileCardTableViewCell.swift index 3b3227e23..f12369437 100644 --- a/MastodonSDK/Sources/MastodonUI/View/TableViewCell/ProfileCardTableViewCell.swift +++ b/Mastodon/Scene/Discovery/ForYou/ProfileCardTableViewCell.swift @@ -7,6 +7,7 @@ import UIKit import Combine +import MastodonUI public protocol ProfileCardTableViewCellDelegate: AnyObject { func profileCardTableViewCell(_ cell: ProfileCardTableViewCell, profileCardView: ProfileCardView, relationshipButtonDidPressed button: ProfileRelationshipActionButton) diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/ProfileCardView+Configuration.swift b/Mastodon/Scene/Discovery/ForYou/ProfileCardView+Configuration.swift similarity index 80% rename from MastodonSDK/Sources/MastodonUI/View/Content/ProfileCardView+Configuration.swift rename to Mastodon/Scene/Discovery/ForYou/ProfileCardView+Configuration.swift index fcf83e75b..3db4698f7 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/ProfileCardView+Configuration.swift +++ b/Mastodon/Scene/Discovery/ForYou/ProfileCardView+Configuration.swift @@ -15,12 +15,23 @@ import MastodonSDK extension ProfileCardView { + public func configure(account: Mastodon.Entity.Account) { + //TODO: Implement + viewModel.authorBannerImageURL = URL(string: account.header) + + do { + let content = MastodonContent(content: account.displayNameWithFallback, emojis: account.emojis?.asDictionary ?? [:]) + let metaContent = try MastodonMetaContent.convert(document: content) + viewModel.authorName = metaContent + } catch { + assertionFailure(error.localizedDescription) + let metaContent = PlaintextMetaContent(string: account.displayNameWithFallback) + viewModel.authorName = metaContent + } + + } + public func configure(user: MastodonUser) { - // banner - user.publisher(for: \.header) - .map { URL(string: $0) } - .assign(to: \.authorBannerImageURL, on: viewModel) - .store(in: &disposeBag) // author avatar Publishers.CombineLatest3( user.publisher(for: \.avatar), diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/ProfileCardView+ViewModel.swift b/Mastodon/Scene/Discovery/ForYou/ProfileCardView+ViewModel.swift similarity index 77% rename from MastodonSDK/Sources/MastodonUI/View/Content/ProfileCardView+ViewModel.swift rename to Mastodon/Scene/Discovery/ForYou/ProfileCardView+ViewModel.swift index 25b8fc653..f375ee478 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/ProfileCardView+ViewModel.swift +++ b/Mastodon/Scene/Discovery/ForYou/ProfileCardView+ViewModel.swift @@ -14,6 +14,7 @@ import MastodonLocalization import MastodonAsset import MastodonSDK import MastodonCore +import MastodonUI extension ProfileCardView { public class ViewModel: ObservableObject { @@ -77,7 +78,7 @@ extension ProfileCardView.ViewModel { bindRelationship(view: view) bindDashboard(view: view) bindFamiliarFollowers(view: view) - bindAccessibility(view: view) +// bindAccessibility(view: view) } private func bindAppearacne(view: ProfileCardView) { @@ -212,73 +213,73 @@ extension ProfileCardView.ViewModel { view.familiarFollowersDashboardView.configure(familiarFollowers: familiarFollowers) } .store(in: &disposeBag) - $backgroundColor - .assign(to: \.backgroundColor, on: view.familiarFollowersDashboardView.viewModel) - .store(in: &disposeBag) +// $backgroundColor +// .assign(to: \.backgroundColor, on: view.familiarFollowersDashboardView.viewModel) +// .store(in: &disposeBag) } - private func bindAccessibility(view: ProfileCardView) { - let authorAccessibilityLabel = Publishers.CombineLatest( - $authorName, - $bioContent - ) - .map { authorName, bioContent -> String? in - var strings: [String?] = [] - strings.append(authorName?.string) - strings.append(bioContent?.string) - return strings.compactMap { $0 }.joined(separator: ", ") - } - - authorAccessibilityLabel - .map { $0 ?? "" } - .assign(to: &$groupedAccessibilityLabel) - - $groupedAccessibilityLabel - .sink { accessibilityLabel in - view.accessibilityLabel = accessibilityLabel - } - .store(in: &disposeBag) - - let statusesContent = $statusesCount - .removeDuplicates() - .map { - AXCustomContent( - label: L10n.Scene.Profile.Dashboard.otherPosts, - value: $0 - ) - } - let followingContent = $followingCount - .removeDuplicates() - .map { - AXCustomContent( - label: L10n.Scene.Profile.Dashboard.otherFollowing, - value: $0 - ) - } - let followersContent = $followersCount - .removeDuplicates() - .map { - AXCustomContent( - label: L10n.Scene.Profile.Dashboard.otherFollowers, - value: $0 - ) - } - let familiarContent = view.familiarFollowersDashboardView.viewModel.$label - .map { $0?.accessibilityLabel } - .removeDuplicates() - .map { - AXCustomContent( - label: L10n.Scene.Profile.Dashboard.familiarFollowers, - value: $0 - ) - } - Publishers.CombineLatest4( - statusesContent, - followingContent, - followersContent, - familiarContent - ).sink { statuses, following, followers, familiar in - view.accessibilityCustomContent = [statuses, following, followers, familiar].compactMap { $0 } - }.store(in: &disposeBag) - } +// private func bindAccessibility(view: ProfileCardView) { +// let authorAccessibilityLabel = Publishers.CombineLatest( +// $authorName, +// $bioContent +// ) +// .map { authorName, bioContent -> String? in +// var strings: [String?] = [] +// strings.append(authorName?.string) +// strings.append(bioContent?.string) +// return strings.compactMap { $0 }.joined(separator: ", ") +// } +// +// authorAccessibilityLabel +// .map { $0 ?? "" } +// .assign(to: &$groupedAccessibilityLabel) +// +// $groupedAccessibilityLabel +// .sink { accessibilityLabel in +// view.accessibilityLabel = accessibilityLabel +// } +// .store(in: &disposeBag) +// +// let statusesContent = $statusesCount +// .removeDuplicates() +// .map { +// AXCustomContent( +// label: L10n.Scene.Profile.Dashboard.otherPosts, +// value: "\($0.)" +// ) +// } +// let followingContent = $followingCount +// .removeDuplicates() +// .map { +// AXCustomContent( +// label: L10n.Scene.Profile.Dashboard.otherFollowing, +// value: $0 +// ) +// } +// let followersContent = $followersCount +// .removeDuplicates() +// .map { +// AXCustomContent( +// label: L10n.Scene.Profile.Dashboard.otherFollowers, +// value: $0 +// ) +// } +// let familiarContent = view.familiarFollowersDashboardView.viewModel.$label +// .map { $0?.accessibilityLabel } +// .removeDuplicates() +// .map { +// AXCustomContent( +// label: L10n.Scene.Profile.Dashboard.familiarFollowers, +// value: $0 +// ) +// } +// Publishers.CombineLatest4( +// statusesContent, +// followingContent, +// followersContent, +// familiarContent +// ).sink { statuses, following, followers, familiar in +// view.accessibilityCustomContent = [statuses, following, followers, familiar].compactMap { $0 } +// }.store(in: &disposeBag) +// } } diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/ProfileCardView.swift b/Mastodon/Scene/Discovery/ForYou/ProfileCardView.swift similarity index 99% rename from MastodonSDK/Sources/MastodonUI/View/Content/ProfileCardView.swift rename to Mastodon/Scene/Discovery/ForYou/ProfileCardView.swift index ad8762c71..1407c745c 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/ProfileCardView.swift +++ b/Mastodon/Scene/Discovery/ForYou/ProfileCardView.swift @@ -9,6 +9,7 @@ import UIKit import Combine import MetaTextKit import MastodonAsset +import MastodonUI public protocol ProfileCardViewDelegate: AnyObject { func profileCardView(_ profileCardView: ProfileCardView, relationshipButtonDidPressed button: ProfileRelationshipActionButton) diff --git a/Mastodon/Scene/Profile/CachedProfileViewModel.swift b/Mastodon/Scene/Profile/CachedProfileViewModel.swift deleted file mode 100644 index a769f2a9f..000000000 --- a/Mastodon/Scene/Profile/CachedProfileViewModel.swift +++ /dev/null @@ -1,17 +0,0 @@ -// -// CachedProfileViewModel.swift -// Mastodon -// -// Created by MainasuK Cirno on 2021-3-31. -// - -import Foundation -import CoreDataStack -import MastodonCore - -final class CachedProfileViewModel: ProfileViewModel { - - init(context: AppContext, authContext: AuthContext, mastodonUser: MastodonUser) { - super.init(context: context, authContext: authContext, optionalMastodonUser: mastodonUser) - } -} diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/FamiliarFollowersDashboardView.swift b/MastodonSDK/Sources/MastodonUI/View/Content/FamiliarFollowersDashboardView.swift index 32d9bce96..caf85483f 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/FamiliarFollowersDashboardView.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/FamiliarFollowersDashboardView.swift @@ -63,15 +63,3 @@ extension FamiliarFollowersDashboardView { } } - - -#if DEBUG -import SwiftUI -struct FamiliarFollowersDashboardView_Preview: PreviewProvider { - static var previews: some View { - UIViewPreview { - FamiliarFollowersDashboardView() - } - } -} -#endif