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)
StatusSection.configure(
cell: cell,
indexPath: indexPath,
dependency: dependency,
readableLayoutFrame: frame,
timestampUpdatePublisher: timestampUpdatePublisher,

View File

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

View File

@ -49,7 +49,6 @@ extension StatusSection {
let timelineIndex = managedObjectContext.object(with: objectID) as! HomeTimelineIndex
StatusSection.configure(
cell: cell,
indexPath: indexPath,
dependency: dependency,
readableLayoutFrame: tableView.readableContentGuide.layoutFrame,
timestampUpdatePublisher: timestampUpdatePublisher,
@ -72,7 +71,6 @@ extension StatusSection {
let status = managedObjectContext.object(with: objectID) as! Status
StatusSection.configure(
cell: cell,
indexPath: indexPath,
dependency: dependency,
readableLayoutFrame: tableView.readableContentGuide.layoutFrame,
timestampUpdatePublisher: timestampUpdatePublisher,
@ -138,7 +136,6 @@ extension StatusSection {
static func configure(
cell: StatusCell,
indexPath: IndexPath,
dependency: NeedsDependency,
readableLayoutFrame: CGRect?,
timestampUpdatePublisher: AnyPublisher<Date, Never>,
@ -407,7 +404,6 @@ extension StatusSection {
// toolbar
StatusSection.configureActionToolBar(
cell: statusTableViewCell,
indexPath: indexPath,
dependency: dependency,
status: status,
requestUserID: requestUserID
@ -438,7 +434,6 @@ extension StatusSection {
guard let statusTableViewCell = cell as? StatusTableViewCell else { return }
StatusSection.configureActionToolBar(
cell: statusTableViewCell,
indexPath: indexPath,
dependency: dependency,
status: status,
requestUserID: requestUserID
@ -597,7 +592,6 @@ extension StatusSection {
static func configureActionToolBar(
cell: StatusTableViewCell,
indexPath: IndexPath,
dependency: NeedsDependency,
status: Status,
requestUserID: String
@ -644,10 +638,10 @@ extension StatusSection {
case .none:
break
}
StatusSection.setupStatusMoreButtonMenu(cell: cell, indexPath: indexPath, dependency: dependency, status: status)
StatusSection.setupStatusMoreButtonMenu(cell: cell, dependency: dependency, status: status)
}
.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(
@ -777,7 +771,6 @@ extension StatusSection {
private static func setupStatusMoreButtonMenu(
cell: StatusTableViewCell,
indexPath: IndexPath,
dependency: NeedsDependency,
status: Status) {
@ -802,7 +795,6 @@ extension StatusSection {
isDomainBlocking: isDomainBlocking,
provider: userProvider,
cell: cell,
indexPath: indexPath,
sourceView: cell.statusView.actionToolbarContainer.moreButton,
barButtonItem: 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 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)
}
@ -260,7 +260,7 @@ extension StatusTableViewCellDelegate where Self: StatusProvider {
guard index < imageViews.count else { return }
let imageView = imageViews[index]
let status = status(for: nil, indexPath: indexPath)
let status = self.status(for: nil, indexPath: indexPath)
let initialFrame: CGRect? = {
guard let previewViewController = animator.previewViewController else { return nil }
return UIView.findContextMenuPreviewFrameInWindow(previewController: previewViewController)

View File

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

View File

@ -54,19 +54,18 @@ extension UserProviderFacade {
extension UserProviderFacade {
static func toggleUserBlockRelationship(
provider: UserProvider,
cell: UITableViewCell?,
indexPath: IndexPath?
cell: UITableViewCell?
) -> AnyPublisher<Mastodon.Response.Content<Mastodon.Entity.Relationship>, Error> {
// prepare authentication
guard let activeMastodonAuthenticationBox = provider.context.authenticationService.activeMastodonAuthenticationBox.value else {
assertionFailure()
return Fail(error: APIService.APIError.implicit(.authenticationMissing)).eraseToAnyPublisher()
}
if let cell = cell, let indexPath = indexPath {
if let cell = cell {
return _toggleUserBlockRelationship(
context: provider.context,
activeMastodonAuthenticationBox: activeMastodonAuthenticationBox,
mastodonUser: provider.mastodonUser(for: cell, indexPath: indexPath).eraseToAnyPublisher()
mastodonUser: provider.mastodonUser(for: cell).eraseToAnyPublisher()
)
} else {
return _toggleUserBlockRelationship(
@ -101,19 +100,18 @@ extension UserProviderFacade {
extension UserProviderFacade {
static func toggleUserMuteRelationship(
provider: UserProvider,
cell: UITableViewCell?,
indexPath: IndexPath?
cell: UITableViewCell?
) -> AnyPublisher<Mastodon.Response.Content<Mastodon.Entity.Relationship>, Error> {
// prepare authentication
guard let activeMastodonAuthenticationBox = provider.context.authenticationService.activeMastodonAuthenticationBox.value else {
assertionFailure()
return Fail(error: APIService.APIError.implicit(.authenticationMissing)).eraseToAnyPublisher()
}
if let cell = cell, let indexPath = indexPath {
if let cell = cell {
return _toggleUserMuteRelationship(
context: provider.context,
activeMastodonAuthenticationBox: activeMastodonAuthenticationBox,
mastodonUser: provider.mastodonUser(for: cell, indexPath: indexPath).eraseToAnyPublisher()
mastodonUser: provider.mastodonUser(for: cell).eraseToAnyPublisher()
)
} else {
return _toggleUserMuteRelationship(
@ -155,7 +153,6 @@ extension UserProviderFacade {
isDomainBlocking: Bool,
provider: UserProvider,
cell: UITableViewCell?,
indexPath: IndexPath?,
sourceView: UIView?,
barButtonItem: UIBarButtonItem?,
shareUser: MastodonUser?,
@ -176,8 +173,7 @@ extension UserProviderFacade {
UserProviderFacade.toggleUserMuteRelationship(
provider: provider,
cell: cell,
indexPath: indexPath
cell: cell
)
.sink { _ in
// do nothing
@ -205,8 +201,7 @@ extension UserProviderFacade {
UserProviderFacade.toggleUserBlockRelationship(
provider: provider,
cell: cell,
indexPath: indexPath
cell: cell
)
.sink { _ in
// do nothing
@ -246,7 +241,7 @@ extension UserProviderFacade {
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
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)
} else {
@ -257,7 +252,7 @@ extension UserProviderFacade {
}
alertController.addAction(cancelAction)
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)
provider.present(alertController, animated: true, completion: nil)

View File

@ -11,7 +11,7 @@ import CoreDataStack
import UIKit
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
promise(.success(nil))
}

View File

@ -399,7 +399,6 @@ extension ProfileViewController {
isDomainBlocking: isDomainBlocking,
provider: self,
cell: nil,
indexPath: nil,
sourceView: nil,
barButtonItem: self.moreMenuBarButtonItem,
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
guard let self = self else { return }
UserProviderFacade.toggleUserMuteRelationship(provider: self, cell: nil, indexPath: nil)
UserProviderFacade.toggleUserMuteRelationship(provider: self, cell: nil)
.sink { _ in
// do nothing
} receiveValue: { _ in
@ -809,7 +808,7 @@ extension ProfileViewController: ProfileHeaderViewDelegate {
)
let unblockAction = UIAlertAction(title: L10n.Common.Controls.Firendship.unblock, style: .default) { [weak self] _ in
guard let self = self else { return }
UserProviderFacade.toggleUserBlockRelationship(provider: self, cell: nil, indexPath: nil)
UserProviderFacade.toggleUserBlockRelationship(provider: self, cell: nil)
.sink { _ in
// do nothing
} receiveValue: { _ in

View File

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

View File

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