mirror of
https://github.com/mastodon/mastodon-ios.git
synced 2025-01-06 14:27:14 +01:00
Remove delegate again (IOS-195)
This commit is contained in:
parent
5a3a10071b
commit
1fbc2a8d1c
@ -147,6 +147,8 @@ extension DiscoveryForYouViewController: ProfileCardTableViewCellDelegate {
|
||||
let familiarFollowers = viewModel.familiarFollowers.first(where: { $0.id == userID })?.accounts ?? []
|
||||
let relationships = try await context.apiService.relationship(forAccounts: familiarFollowers, authenticationBox: authContext.mastodonAuthenticationBox).value
|
||||
|
||||
coordinator.hideLoading()
|
||||
|
||||
let familiarFollowersViewModel = FamiliarFollowersViewModel(
|
||||
context: context,
|
||||
authContext: authContext,
|
||||
@ -154,17 +156,11 @@ extension DiscoveryForYouViewController: ProfileCardTableViewCellDelegate {
|
||||
relationships: relationships
|
||||
)
|
||||
|
||||
coordinator.hideLoading()
|
||||
|
||||
let viewController = coordinator.present(
|
||||
scene: .familiarFollowers(viewModel: familiarFollowersViewModel),
|
||||
from: self,
|
||||
transition: .show
|
||||
)
|
||||
|
||||
if let familiarFollowersViewController = viewController as? FamiliarFollowersViewController {
|
||||
familiarFollowersViewController.delegate = self
|
||||
}
|
||||
} catch {
|
||||
|
||||
}
|
||||
@ -176,11 +172,3 @@ extension DiscoveryForYouViewController: ProfileCardTableViewCellDelegate {
|
||||
extension DiscoveryForYouViewController: ScrollViewContainer {
|
||||
var scrollView: UIScrollView { tableView }
|
||||
}
|
||||
|
||||
extension DiscoveryForYouViewController: FamiliarFollowersViewControllerDelegate {
|
||||
func relationshipChanged(_ viewController: UIViewController, account: Mastodon.Entity.Account) {
|
||||
Task {
|
||||
try? await viewModel.fetch()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,16 +13,11 @@ import MastodonUI
|
||||
import MastodonSDK
|
||||
import CoreDataStack
|
||||
|
||||
protocol FamiliarFollowersViewControllerDelegate: AnyObject {
|
||||
func relationshipChanged(_ viewController: UIViewController, account: Mastodon.Entity.Account)
|
||||
}
|
||||
|
||||
final class FamiliarFollowersViewController: UIViewController, NeedsDependency {
|
||||
|
||||
weak var context: AppContext!
|
||||
weak var coordinator: SceneCoordinator!
|
||||
let viewModel: FamiliarFollowersViewModel
|
||||
weak var delegate: FamiliarFollowersViewControllerDelegate?
|
||||
|
||||
let tableView: UITableView
|
||||
|
||||
@ -85,43 +80,7 @@ extension FamiliarFollowersViewController: UITableViewDelegate, AutoGenerateTabl
|
||||
}
|
||||
|
||||
// MARK: - UserTableViewCellDelegate
|
||||
extension FamiliarFollowersViewController: UserTableViewCellDelegate {
|
||||
func userView(_ view: UserView, didTapButtonWith state: UserView.ButtonState, for user: MastodonUser) { }
|
||||
func userView(_ view: UserView, didTapButtonWith state: UserView.ButtonState, for account: Mastodon.Entity.Account, me: MastodonUser?) {
|
||||
|
||||
// Can we call the default implementation somehow? Maybe add a FollowAction-class with a completion-block?
|
||||
Task {
|
||||
await MainActor.run { view.setButtonState(.loading) }
|
||||
|
||||
try await DataSourceFacade.responseToUserViewButtonAction(
|
||||
dependency: self,
|
||||
user: account,
|
||||
buttonState: state
|
||||
)
|
||||
|
||||
// this is a dirty hack to give the backend enough time to process the relationship-change
|
||||
// Otherwise the relationship might still be `pending`
|
||||
try await Task.sleep(for: .seconds(1))
|
||||
|
||||
let relationship = try await self.context.apiService.relationship(forAccounts: [account], authenticationBox: authContext.mastodonAuthenticationBox).value.first
|
||||
|
||||
let isMe: Bool
|
||||
if let me {
|
||||
isMe = account.id == me.id
|
||||
} else {
|
||||
isMe = false
|
||||
}
|
||||
|
||||
await MainActor.run {
|
||||
view.viewModel.relationship = relationship
|
||||
view.updateButtonState(with: relationship, isMe: isMe)
|
||||
|
||||
delegate?.relationshipChanged(self, account: account)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
extension FamiliarFollowersViewController: UserTableViewCellDelegate {}
|
||||
|
||||
//MARK: - DataSourceProvider
|
||||
extension FamiliarFollowersViewController: DataSourceProvider {
|
||||
|
Loading…
Reference in New Issue
Block a user