fix: ignore indexPath for userProvider

This commit is contained in:
sunxiaojian 2021-05-06 18:03:58 +08:00
parent 5f921c1537
commit 8011298571
10 changed files with 29 additions and 47 deletions

View File

@ -50,7 +50,6 @@ extension NotificationSection {
let frame = CGRect(x: 0, y: 0, width: tableView.readableContentGuide.layoutFrame.width - NotificationStatusTableViewCell.statusPadding.left - NotificationStatusTableViewCell.statusPadding.right, height: tableView.readableContentGuide.layoutFrame.height) let frame = CGRect(x: 0, y: 0, width: tableView.readableContentGuide.layoutFrame.width - NotificationStatusTableViewCell.statusPadding.left - NotificationStatusTableViewCell.statusPadding.right, height: tableView.readableContentGuide.layoutFrame.height)
StatusSection.configure( StatusSection.configure(
cell: cell, cell: cell,
indexPath: indexPath,
dependency: dependency, dependency: dependency,
readableLayoutFrame: frame, readableLayoutFrame: frame,
timestampUpdatePublisher: timestampUpdatePublisher, timestampUpdatePublisher: timestampUpdatePublisher,

View File

@ -41,7 +41,6 @@ extension ReportSection {
let status = managedObjectContext.object(with: objectID) as! Status let status = managedObjectContext.object(with: objectID) as! Status
StatusSection.configure( StatusSection.configure(
cell: cell, cell: cell,
indexPath: indexPath,
dependency: dependency, dependency: dependency,
readableLayoutFrame: tableView.readableContentGuide.layoutFrame, readableLayoutFrame: tableView.readableContentGuide.layoutFrame,
timestampUpdatePublisher: timestampUpdatePublisher, timestampUpdatePublisher: timestampUpdatePublisher,

View File

@ -49,7 +49,6 @@ extension StatusSection {
let timelineIndex = managedObjectContext.object(with: objectID) as! HomeTimelineIndex let timelineIndex = managedObjectContext.object(with: objectID) as! HomeTimelineIndex
StatusSection.configure( StatusSection.configure(
cell: cell, cell: cell,
indexPath: indexPath,
dependency: dependency, dependency: dependency,
readableLayoutFrame: tableView.readableContentGuide.layoutFrame, readableLayoutFrame: tableView.readableContentGuide.layoutFrame,
timestampUpdatePublisher: timestampUpdatePublisher, timestampUpdatePublisher: timestampUpdatePublisher,
@ -72,7 +71,6 @@ extension StatusSection {
let status = managedObjectContext.object(with: objectID) as! Status let status = managedObjectContext.object(with: objectID) as! Status
StatusSection.configure( StatusSection.configure(
cell: cell, cell: cell,
indexPath: indexPath,
dependency: dependency, dependency: dependency,
readableLayoutFrame: tableView.readableContentGuide.layoutFrame, readableLayoutFrame: tableView.readableContentGuide.layoutFrame,
timestampUpdatePublisher: timestampUpdatePublisher, timestampUpdatePublisher: timestampUpdatePublisher,
@ -138,7 +136,6 @@ extension StatusSection {
static func configure( static func configure(
cell: StatusCell, cell: StatusCell,
indexPath: IndexPath,
dependency: NeedsDependency, dependency: NeedsDependency,
readableLayoutFrame: CGRect?, readableLayoutFrame: CGRect?,
timestampUpdatePublisher: AnyPublisher<Date, Never>, timestampUpdatePublisher: AnyPublisher<Date, Never>,
@ -407,7 +404,6 @@ extension StatusSection {
// toolbar // toolbar
StatusSection.configureActionToolBar( StatusSection.configureActionToolBar(
cell: statusTableViewCell, cell: statusTableViewCell,
indexPath: indexPath,
dependency: dependency, dependency: dependency,
status: status, status: status,
requestUserID: requestUserID requestUserID: requestUserID
@ -438,7 +434,6 @@ extension StatusSection {
guard let statusTableViewCell = cell as? StatusTableViewCell else { return } guard let statusTableViewCell = cell as? StatusTableViewCell else { return }
StatusSection.configureActionToolBar( StatusSection.configureActionToolBar(
cell: statusTableViewCell, cell: statusTableViewCell,
indexPath: indexPath,
dependency: dependency, dependency: dependency,
status: status, status: status,
requestUserID: requestUserID requestUserID: requestUserID
@ -597,7 +592,6 @@ extension StatusSection {
static func configureActionToolBar( static func configureActionToolBar(
cell: StatusTableViewCell, cell: StatusTableViewCell,
indexPath: IndexPath,
dependency: NeedsDependency, dependency: NeedsDependency,
status: Status, status: Status,
requestUserID: String requestUserID: String
@ -644,10 +638,10 @@ extension StatusSection {
case .none: case .none:
break break
} }
StatusSection.setupStatusMoreButtonMenu(cell: cell, indexPath: indexPath, dependency: dependency, status: status) StatusSection.setupStatusMoreButtonMenu(cell: cell, dependency: dependency, status: status)
} }
.store(in: &cell.disposeBag) .store(in: &cell.disposeBag)
self.setupStatusMoreButtonMenu(cell: cell, indexPath: indexPath, dependency: dependency, status: status) self.setupStatusMoreButtonMenu(cell: cell, dependency: dependency, status: status)
} }
static func configurePoll( static func configurePoll(
@ -777,7 +771,6 @@ extension StatusSection {
private static func setupStatusMoreButtonMenu( private static func setupStatusMoreButtonMenu(
cell: StatusTableViewCell, cell: StatusTableViewCell,
indexPath: IndexPath,
dependency: NeedsDependency, dependency: NeedsDependency,
status: Status) { status: Status) {
@ -802,7 +795,6 @@ extension StatusSection {
isDomainBlocking: isDomainBlocking, isDomainBlocking: isDomainBlocking,
provider: userProvider, provider: userProvider,
cell: cell, cell: cell,
indexPath: indexPath,
sourceView: cell.statusView.actionToolbarContainer.moreButton, sourceView: cell.statusView.actionToolbarContainer.moreButton,
barButtonItem: nil, barButtonItem: nil,
shareUser: nil, shareUser: nil,

View File

@ -114,7 +114,7 @@ extension StatusTableViewCellDelegate where Self: StatusProvider {
guard let imagePreviewPresentableCell = tableView.cellForRow(at: indexPath) as? ImagePreviewPresentableCell else { return nil } guard let imagePreviewPresentableCell = tableView.cellForRow(at: indexPath) as? ImagePreviewPresentableCell else { return nil }
guard imagePreviewPresentableCell.isRevealing else { return nil } guard imagePreviewPresentableCell.isRevealing else { return nil }
let status = status(for: nil, indexPath: indexPath) let status = self.status(for: nil, indexPath: indexPath)
return contextMenuConfiguration(tableView, status: status, imagePreviewPresentableCell: imagePreviewPresentableCell, contextMenuConfigurationForRowAt: indexPath, point: point) return contextMenuConfiguration(tableView, status: status, imagePreviewPresentableCell: imagePreviewPresentableCell, contextMenuConfigurationForRowAt: indexPath, point: point)
} }
@ -260,7 +260,7 @@ extension StatusTableViewCellDelegate where Self: StatusProvider {
guard index < imageViews.count else { return } guard index < imageViews.count else { return }
let imageView = imageViews[index] let imageView = imageViews[index]
let status = status(for: nil, indexPath: indexPath) let status = self.status(for: nil, indexPath: indexPath)
let initialFrame: CGRect? = { let initialFrame: CGRect? = {
guard let previewViewController = animator.previewViewController else { return nil } guard let previewViewController = animator.previewViewController else { return nil }
return UIView.findContextMenuPreviewFrameInWindow(previewController: previewViewController) return UIView.findContextMenuPreviewFrameInWindow(previewController: previewViewController)

View File

@ -14,14 +14,14 @@ protocol UserProvider: NeedsDependency & DisposeBagCollectable & UIViewControlle
// async // async
func mastodonUser() -> Future<MastodonUser?, Never> func mastodonUser() -> Future<MastodonUser?, Never>
func mastodonUser(for cell: UITableViewCell?, indexPath: IndexPath?) -> Future<MastodonUser?, Never> func mastodonUser(for cell: UITableViewCell?) -> Future<MastodonUser?, Never>
} }
extension UserProvider where Self: StatusProvider { extension UserProvider where Self: StatusProvider {
func mastodonUser(for cell: UITableViewCell?, indexPath: IndexPath?) -> Future<MastodonUser?, Never> { func mastodonUser(for cell: UITableViewCell?) -> Future<MastodonUser?, Never> {
Future { [weak self] promise in Future { [weak self] promise in
guard let self = self else { return } guard let self = self else { return }
self.status(for: cell, indexPath: indexPath) self.status(for: cell, indexPath: nil)
.sink { status in .sink { status in
promise(.success(status?.authorForUserProvider)) promise(.success(status?.authorForUserProvider))
} }

View File

@ -54,19 +54,18 @@ extension UserProviderFacade {
extension UserProviderFacade { extension UserProviderFacade {
static func toggleUserBlockRelationship( static func toggleUserBlockRelationship(
provider: UserProvider, provider: UserProvider,
cell: UITableViewCell?, cell: UITableViewCell?
indexPath: IndexPath?
) -> AnyPublisher<Mastodon.Response.Content<Mastodon.Entity.Relationship>, Error> { ) -> AnyPublisher<Mastodon.Response.Content<Mastodon.Entity.Relationship>, Error> {
// prepare authentication // prepare authentication
guard let activeMastodonAuthenticationBox = provider.context.authenticationService.activeMastodonAuthenticationBox.value else { guard let activeMastodonAuthenticationBox = provider.context.authenticationService.activeMastodonAuthenticationBox.value else {
assertionFailure() assertionFailure()
return Fail(error: APIService.APIError.implicit(.authenticationMissing)).eraseToAnyPublisher() return Fail(error: APIService.APIError.implicit(.authenticationMissing)).eraseToAnyPublisher()
} }
if let cell = cell, let indexPath = indexPath { if let cell = cell {
return _toggleUserBlockRelationship( return _toggleUserBlockRelationship(
context: provider.context, context: provider.context,
activeMastodonAuthenticationBox: activeMastodonAuthenticationBox, activeMastodonAuthenticationBox: activeMastodonAuthenticationBox,
mastodonUser: provider.mastodonUser(for: cell, indexPath: indexPath).eraseToAnyPublisher() mastodonUser: provider.mastodonUser(for: cell).eraseToAnyPublisher()
) )
} else { } else {
return _toggleUserBlockRelationship( return _toggleUserBlockRelationship(
@ -101,19 +100,18 @@ extension UserProviderFacade {
extension UserProviderFacade { extension UserProviderFacade {
static func toggleUserMuteRelationship( static func toggleUserMuteRelationship(
provider: UserProvider, provider: UserProvider,
cell: UITableViewCell?, cell: UITableViewCell?
indexPath: IndexPath?
) -> AnyPublisher<Mastodon.Response.Content<Mastodon.Entity.Relationship>, Error> { ) -> AnyPublisher<Mastodon.Response.Content<Mastodon.Entity.Relationship>, Error> {
// prepare authentication // prepare authentication
guard let activeMastodonAuthenticationBox = provider.context.authenticationService.activeMastodonAuthenticationBox.value else { guard let activeMastodonAuthenticationBox = provider.context.authenticationService.activeMastodonAuthenticationBox.value else {
assertionFailure() assertionFailure()
return Fail(error: APIService.APIError.implicit(.authenticationMissing)).eraseToAnyPublisher() return Fail(error: APIService.APIError.implicit(.authenticationMissing)).eraseToAnyPublisher()
} }
if let cell = cell, let indexPath = indexPath { if let cell = cell {
return _toggleUserMuteRelationship( return _toggleUserMuteRelationship(
context: provider.context, context: provider.context,
activeMastodonAuthenticationBox: activeMastodonAuthenticationBox, activeMastodonAuthenticationBox: activeMastodonAuthenticationBox,
mastodonUser: provider.mastodonUser(for: cell, indexPath: indexPath).eraseToAnyPublisher() mastodonUser: provider.mastodonUser(for: cell).eraseToAnyPublisher()
) )
} else { } else {
return _toggleUserMuteRelationship( return _toggleUserMuteRelationship(
@ -155,7 +153,6 @@ extension UserProviderFacade {
isDomainBlocking: Bool, isDomainBlocking: Bool,
provider: UserProvider, provider: UserProvider,
cell: UITableViewCell?, cell: UITableViewCell?,
indexPath: IndexPath?,
sourceView: UIView?, sourceView: UIView?,
barButtonItem: UIBarButtonItem?, barButtonItem: UIBarButtonItem?,
shareUser: MastodonUser?, shareUser: MastodonUser?,
@ -176,8 +173,7 @@ extension UserProviderFacade {
UserProviderFacade.toggleUserMuteRelationship( UserProviderFacade.toggleUserMuteRelationship(
provider: provider, provider: provider,
cell: cell, cell: cell
indexPath: indexPath
) )
.sink { _ in .sink { _ in
// do nothing // do nothing
@ -205,8 +201,7 @@ extension UserProviderFacade {
UserProviderFacade.toggleUserBlockRelationship( UserProviderFacade.toggleUserBlockRelationship(
provider: provider, provider: provider,
cell: cell, cell: cell
indexPath: indexPath
) )
.sink { _ in .sink { _ in
// do nothing // do nothing
@ -246,7 +241,7 @@ extension UserProviderFacade {
if isDomainBlocking { if isDomainBlocking {
let unblockDomainAction = UIAction(title: L10n.Common.Controls.Actions.unblockDomain(mastodonUser.domainFromAcct), image: UIImage(systemName: "nosign"), identifier: nil, discoverabilityTitle: nil, attributes: [], state: .off) { [weak provider] _ in let unblockDomainAction = UIAction(title: L10n.Common.Controls.Actions.unblockDomain(mastodonUser.domainFromAcct), image: UIImage(systemName: "nosign"), identifier: nil, discoverabilityTitle: nil, attributes: [], state: .off) { [weak provider] _ in
guard let provider = provider else { return } guard let provider = provider else { return }
provider.context.blockDomainService.unblockDomain(userProvider: provider, cell: cell, indexPath: indexPath) provider.context.blockDomainService.unblockDomain(userProvider: provider, cell: cell)
} }
children.append(unblockDomainAction) children.append(unblockDomainAction)
} else { } else {
@ -257,7 +252,7 @@ extension UserProviderFacade {
} }
alertController.addAction(cancelAction) alertController.addAction(cancelAction)
let blockDomainAction = UIAlertAction(title: L10n.Common.Alerts.BlockDomain.blockEntireDomain, style: .destructive) { _ in let blockDomainAction = UIAlertAction(title: L10n.Common.Alerts.BlockDomain.blockEntireDomain, style: .destructive) { _ in
provider.context.blockDomainService.blockDomain(userProvider: provider, cell: cell, indexPath: indexPath) provider.context.blockDomainService.blockDomain(userProvider: provider, cell: cell)
} }
alertController.addAction(blockDomainAction) alertController.addAction(blockDomainAction)
provider.present(alertController, animated: true, completion: nil) provider.present(alertController, animated: true, completion: nil)

View File

@ -11,7 +11,7 @@ import CoreDataStack
import UIKit import UIKit
extension ProfileViewController: UserProvider { extension ProfileViewController: UserProvider {
func mastodonUser(for cell: UITableViewCell?, indexPath: IndexPath?) -> Future<MastodonUser?, Never> { func mastodonUser(for cell: UITableViewCell?) -> Future<MastodonUser?, Never> {
return Future { promise in return Future { promise in
promise(.success(nil)) promise(.success(nil))
} }

View File

@ -399,7 +399,6 @@ extension ProfileViewController {
isDomainBlocking: isDomainBlocking, isDomainBlocking: isDomainBlocking,
provider: self, provider: self,
cell: nil, cell: nil,
indexPath: nil,
sourceView: nil, sourceView: nil,
barButtonItem: self.moreMenuBarButtonItem, barButtonItem: self.moreMenuBarButtonItem,
shareUser: needsShareAction ? mastodonUser : nil, shareUser: needsShareAction ? mastodonUser : nil,
@ -787,7 +786,7 @@ extension ProfileViewController: ProfileHeaderViewDelegate {
) )
let unmuteAction = UIAlertAction(title: L10n.Common.Controls.Firendship.unmute, style: .default) { [weak self] _ in let unmuteAction = UIAlertAction(title: L10n.Common.Controls.Firendship.unmute, style: .default) { [weak self] _ in
guard let self = self else { return } guard let self = self else { return }
UserProviderFacade.toggleUserMuteRelationship(provider: self, cell: nil, indexPath: nil) UserProviderFacade.toggleUserMuteRelationship(provider: self, cell: nil)
.sink { _ in .sink { _ in
// do nothing // do nothing
} receiveValue: { _ in } receiveValue: { _ in
@ -809,7 +808,7 @@ extension ProfileViewController: ProfileHeaderViewDelegate {
) )
let unblockAction = UIAlertAction(title: L10n.Common.Controls.Firendship.unblock, style: .default) { [weak self] _ in let unblockAction = UIAlertAction(title: L10n.Common.Controls.Firendship.unblock, style: .default) { [weak self] _ in
guard let self = self else { return } guard let self = self else { return }
UserProviderFacade.toggleUserBlockRelationship(provider: self, cell: nil, indexPath: nil) UserProviderFacade.toggleUserBlockRelationship(provider: self, cell: nil)
.sink { _ in .sink { _ in
// do nothing // do nothing
} receiveValue: { _ in } receiveValue: { _ in

View File

@ -12,7 +12,7 @@ import UIKit
extension SearchViewController: UserProvider { extension SearchViewController: UserProvider {
func mastodonUser(for cell: UITableViewCell?, indexPath: IndexPath?) -> Future<MastodonUser?, Never> { func mastodonUser(for cell: UITableViewCell?) -> Future<MastodonUser?, Never> {
return Future { promise in return Future { promise in
promise(.success(nil)) promise(.success(nil))
} }
@ -54,7 +54,7 @@ extension SearchViewController: SearchRecommendAccountsCollectionViewCellDelegat
) )
let unmuteAction = UIAlertAction(title: L10n.Common.Controls.Firendship.unmute, style: .default) { [weak self] _ in let unmuteAction = UIAlertAction(title: L10n.Common.Controls.Firendship.unmute, style: .default) { [weak self] _ in
guard let self = self else { return } guard let self = self else { return }
UserProviderFacade.toggleUserMuteRelationship(provider: self, cell: nil, indexPath: nil) UserProviderFacade.toggleUserMuteRelationship(provider: self, cell: nil)
.sink { _ in .sink { _ in
// do nothing // do nothing
} receiveValue: { _ in } receiveValue: { _ in
@ -76,7 +76,7 @@ extension SearchViewController: SearchRecommendAccountsCollectionViewCellDelegat
) )
let unblockAction = UIAlertAction(title: L10n.Common.Controls.Firendship.unblock, style: .default) { [weak self] _ in let unblockAction = UIAlertAction(title: L10n.Common.Controls.Firendship.unblock, style: .default) { [weak self] _ in
guard let self = self else { return } guard let self = self else { return }
UserProviderFacade.toggleUserBlockRelationship(provider: self, cell: nil, indexPath: nil) UserProviderFacade.toggleUserBlockRelationship(provider: self, cell: nil)
.sink { _ in .sink { _ in
// do nothing // do nothing
} receiveValue: { _ in } receiveValue: { _ in

View File

@ -46,16 +46,15 @@ final class BlockDomainService {
func blockDomain( func blockDomain(
userProvider: UserProvider, userProvider: UserProvider,
cell: UITableViewCell?, cell: UITableViewCell?
indexPath: IndexPath?
) { ) {
guard let activeMastodonAuthenticationBox = userProvider.context.authenticationService.activeMastodonAuthenticationBox.value else { return } guard let activeMastodonAuthenticationBox = userProvider.context.authenticationService.activeMastodonAuthenticationBox.value else { return }
guard let context = userProvider.context else { guard let context = userProvider.context else {
return return
} }
var mastodonUser: AnyPublisher<MastodonUser?, Never> var mastodonUser: AnyPublisher<MastodonUser?, Never>
if let cell = cell, let indexPath = indexPath { if let cell = cell {
mastodonUser = userProvider.mastodonUser(for: cell, indexPath: indexPath).eraseToAnyPublisher() mastodonUser = userProvider.mastodonUser(for: cell).eraseToAnyPublisher()
} else { } else {
mastodonUser = userProvider.mastodonUser().eraseToAnyPublisher() mastodonUser = userProvider.mastodonUser().eraseToAnyPublisher()
} }
@ -85,16 +84,15 @@ final class BlockDomainService {
func unblockDomain( func unblockDomain(
userProvider: UserProvider, userProvider: UserProvider,
cell: UITableViewCell?, cell: UITableViewCell?
indexPath: IndexPath?
) { ) {
guard let activeMastodonAuthenticationBox = userProvider.context.authenticationService.activeMastodonAuthenticationBox.value else { return } guard let activeMastodonAuthenticationBox = userProvider.context.authenticationService.activeMastodonAuthenticationBox.value else { return }
guard let context = userProvider.context else { guard let context = userProvider.context else {
return return
} }
var mastodonUser: AnyPublisher<MastodonUser?, Never> var mastodonUser: AnyPublisher<MastodonUser?, Never>
if let cell = cell, let indexPath = indexPath { if let cell = cell {
mastodonUser = userProvider.mastodonUser(for: cell, indexPath: indexPath).eraseToAnyPublisher() mastodonUser = userProvider.mastodonUser(for: cell).eraseToAnyPublisher()
} else { } else {
mastodonUser = userProvider.mastodonUser().eraseToAnyPublisher() mastodonUser = userProvider.mastodonUser().eraseToAnyPublisher()
} }