fix: remove ActionToolbarContainer.moreButtonDidPressed

This commit is contained in:
sunxiaojian 2021-05-06 18:19:24 +08:00
parent 8011298571
commit b8f3f4c886
9 changed files with 69 additions and 68 deletions

View File

@ -29,7 +29,7 @@
"confirm": "Sign Out" "confirm": "Sign Out"
}, },
"block_domain": { "block_domain": {
"message": "Are you really, really sure you want to block the entire %s ? In most cases a few targeted blocks or mutes are sufficient and preferable. You will not see content from that domain in any public timelines or your notifications. Your followers from that domain will be removed.", "message": "Are you really, really sure you want to block the entire %s? In most cases a few targeted blocks or mutes are sufficient and preferable. You will not see content from that domain in any public timelines or your notifications. Your followers from that domain will be removed.",
"block_entire_domain": "Block entire domain" "block_entire_domain": "Block entire domain"
}, },
"save_photo_failure": { "save_photo_failure": {

View File

@ -780,7 +780,8 @@ extension StatusSection {
return return
} }
let author = status.authorForUserProvider let author = status.authorForUserProvider
let canReport = authenticationBox.userID != author.id let isMyself = authenticationBox.userID == author.id
let canReport = !isMyself
let isInSameDomain = authenticationBox.domain == author.domainFromAcct let isInSameDomain = authenticationBox.domain == author.domainFromAcct
let isMuting = (author.mutingBy ?? Set()).map(\.id).contains(authenticationBox.userID) let isMuting = (author.mutingBy ?? Set()).map(\.id).contains(authenticationBox.userID)
let isBlocking = (author.blockingBy ?? Set()).map(\.id).contains(authenticationBox.userID) let isBlocking = (author.blockingBy ?? Set()).map(\.id).contains(authenticationBox.userID)
@ -788,9 +789,9 @@ extension StatusSection {
cell.statusView.actionToolbarContainer.moreButton.showsMenuAsPrimaryAction = true cell.statusView.actionToolbarContainer.moreButton.showsMenuAsPrimaryAction = true
cell.statusView.actionToolbarContainer.moreButton.menu = UserProviderFacade.createProfileActionMenu( cell.statusView.actionToolbarContainer.moreButton.menu = UserProviderFacade.createProfileActionMenu(
for: author, for: author,
isMyself: isMyself,
isMuting: isMuting, isMuting: isMuting,
isBlocking: isBlocking, isBlocking: isBlocking,
canReport: canReport,
isInSameDomain: isInSameDomain, isInSameDomain: isInSameDomain,
isDomainBlocking: isDomainBlocking, isDomainBlocking: isDomainBlocking,
provider: userProvider, provider: userProvider,

View File

@ -16,7 +16,7 @@ internal enum L10n {
internal enum BlockDomain { internal enum BlockDomain {
/// Block entire domain /// Block entire domain
internal static let blockEntireDomain = L10n.tr("Localizable", "Common.Alerts.BlockDomain.BlockEntireDomain") internal static let blockEntireDomain = L10n.tr("Localizable", "Common.Alerts.BlockDomain.BlockEntireDomain")
/// Are you really, really sure you want to block the entire %@ ? In most cases a few targeted blocks or mutes are sufficient and preferable. You will not see content from that domain in any public timelines or your notifications. Your followers from that domain will be removed. /// Are you really, really sure you want to block the entire %@? In most cases a few targeted blocks or mutes are sufficient and preferable. You will not see content from that domain in any public timelines or your notifications. Your followers from that domain will be removed.
internal static func message(_ p1: Any) -> String { internal static func message(_ p1: Any) -> String {
return L10n.tr("Localizable", "Common.Alerts.BlockDomain.Message", String(describing: p1)) return L10n.tr("Localizable", "Common.Alerts.BlockDomain.Message", String(describing: p1))
} }

View File

@ -146,9 +146,9 @@ extension UserProviderFacade {
extension UserProviderFacade { extension UserProviderFacade {
static func createProfileActionMenu( static func createProfileActionMenu(
for mastodonUser: MastodonUser, for mastodonUser: MastodonUser,
isMyself: Bool,
isMuting: Bool, isMuting: Bool,
isBlocking: Bool, isBlocking: Bool,
canReport: Bool,
isInSameDomain: Bool, isInSameDomain: Bool,
isDomainBlocking: Bool, isDomainBlocking: Bool,
provider: UserProvider, provider: UserProvider,
@ -161,62 +161,67 @@ extension UserProviderFacade {
var children: [UIMenuElement] = [] var children: [UIMenuElement] = []
let name = mastodonUser.displayNameWithFallback let name = mastodonUser.displayNameWithFallback
// mute if !isMyself {
let muteAction = UIAction( // mute
title: isMuting ? L10n.Common.Controls.Firendship.unmuteUser(name) : L10n.Common.Controls.Firendship.mute, let muteAction = UIAction(
image: isMuting ? UIImage(systemName: "speaker") : UIImage(systemName: "speaker.slash"), title: isMuting ? L10n.Common.Controls.Firendship.unmuteUser(name) : L10n.Common.Controls.Firendship.mute,
discoverabilityTitle: isMuting ? nil : L10n.Common.Controls.Firendship.muteUser(name), image: isMuting ? UIImage(systemName: "speaker") : UIImage(systemName: "speaker.slash"),
attributes: isMuting ? [] : .destructive, discoverabilityTitle: isMuting ? nil : L10n.Common.Controls.Firendship.muteUser(name),
state: .off attributes: isMuting ? [] : .destructive,
) { [weak provider] _ in state: .off
guard let provider = provider else { return } ) { [weak provider] _ in
guard let provider = provider else { return }
UserProviderFacade.toggleUserMuteRelationship( UserProviderFacade.toggleUserMuteRelationship(
provider: provider, provider: provider,
cell: cell cell: cell
) )
.sink { _ in .sink { _ in
// do nothing // do nothing
} receiveValue: { _ in } receiveValue: { _ in
// do nothing // do nothing
}
.store(in: &provider.context.disposeBag)
}
if isMuting {
children.append(muteAction)
} else {
let muteMenu = UIMenu(title: L10n.Common.Controls.Firendship.muteUser(name), image: UIImage(systemName: "speaker.slash"), options: [], children: [muteAction])
children.append(muteMenu)
} }
.store(in: &provider.context.disposeBag)
}
if isMuting {
children.append(muteAction)
} else {
let muteMenu = UIMenu(title: L10n.Common.Controls.Firendship.muteUser(name), image: UIImage(systemName: "speaker.slash"), options: [], children: [muteAction])
children.append(muteMenu)
} }
// block if !isMyself {
let blockAction = UIAction( // block
title: isBlocking ? L10n.Common.Controls.Firendship.unblockUser(name) : L10n.Common.Controls.Firendship.block, let blockAction = UIAction(
image: isBlocking ? UIImage(systemName: "hand.raised.slash") : UIImage(systemName: "hand.raised"), title: isBlocking ? L10n.Common.Controls.Firendship.unblockUser(name) : L10n.Common.Controls.Firendship.block,
discoverabilityTitle: isBlocking ? nil : L10n.Common.Controls.Firendship.blockUser(name), image: isBlocking ? UIImage(systemName: "hand.raised.slash") : UIImage(systemName: "hand.raised"),
attributes: isBlocking ? [] : .destructive, discoverabilityTitle: isBlocking ? nil : L10n.Common.Controls.Firendship.blockUser(name),
state: .off attributes: isBlocking ? [] : .destructive,
) { [weak provider] _ in state: .off
guard let provider = provider else { return } ) { [weak provider] _ in
guard let provider = provider else { return }
UserProviderFacade.toggleUserBlockRelationship( UserProviderFacade.toggleUserBlockRelationship(
provider: provider, provider: provider,
cell: cell cell: cell
) )
.sink { _ in .sink { _ in
// do nothing // do nothing
} receiveValue: { _ in } receiveValue: { _ in
// do nothing // do nothing
}
.store(in: &provider.context.disposeBag)
}
if isBlocking {
children.append(blockAction)
} else {
let blockMenu = UIMenu(title: L10n.Common.Controls.Firendship.blockUser(name), image: UIImage(systemName: "hand.raised"), options: [], children: [blockAction])
children.append(blockMenu)
} }
.store(in: &provider.context.disposeBag)
} }
if isBlocking {
children.append(blockAction) if !isMyself {
} else {
let blockMenu = UIMenu(title: L10n.Common.Controls.Firendship.blockUser(name), image: UIImage(systemName: "hand.raised"), options: [], children: [blockAction])
children.append(blockMenu)
}
if canReport {
let reportAction = UIAction(title: L10n.Common.Controls.Actions.reportUser(name), image: UIImage(systemName: "flag"), identifier: nil, discoverabilityTitle: nil, attributes: [], state: .off) { [weak provider] _ in let reportAction = UIAction(title: L10n.Common.Controls.Actions.reportUser(name), image: UIImage(systemName: "flag"), identifier: nil, discoverabilityTitle: nil, attributes: [], state: .off) { [weak provider] _ in
guard let provider = provider else { return } guard let provider = provider else { return }
guard let authenticationBox = provider.context.authenticationService.activeMastodonAuthenticationBox.value else { guard let authenticationBox = provider.context.authenticationService.activeMastodonAuthenticationBox.value else {

View File

@ -1,5 +1,5 @@
"Common.Alerts.BlockDomain.BlockEntireDomain" = "Block entire domain"; "Common.Alerts.BlockDomain.BlockEntireDomain" = "Block entire domain";
"Common.Alerts.BlockDomain.Message" = "Are you really, really sure you want to block the entire %@ ? In most cases a few targeted blocks or mutes are sufficient and preferable. You will not see content from that domain in any public timelines or your notifications. Your followers from that domain will be removed."; "Common.Alerts.BlockDomain.Message" = "Are you really, really sure you want to block the entire %@? In most cases a few targeted blocks or mutes are sufficient and preferable. You will not see content from that domain in any public timelines or your notifications. Your followers from that domain will be removed.";
"Common.Alerts.Common.PleaseTryAgain" = "Please try again."; "Common.Alerts.Common.PleaseTryAgain" = "Please try again.";
"Common.Alerts.Common.PleaseTryAgainLater" = "Please try again later."; "Common.Alerts.Common.PleaseTryAgainLater" = "Please try again later.";
"Common.Alerts.DiscardPostContent.Message" = "Confirm discard composed post content."; "Common.Alerts.DiscardPostContent.Message" = "Confirm discard composed post content.";

View File

@ -384,17 +384,23 @@ extension ProfileViewController {
self.moreMenuBarButtonItem.menu = nil self.moreMenuBarButtonItem.menu = nil
return return
} }
guard let currentMastodonUser = self.viewModel.currentMastodonUser.value else {
self.moreMenuBarButtonItem.menu = nil
return
}
guard let currentDomain = self.viewModel.domain.value else { return } guard let currentDomain = self.viewModel.domain.value else { return }
let isMuting = relationshipActionOptionSet.contains(.muting) let isMuting = relationshipActionOptionSet.contains(.muting)
let isBlocking = relationshipActionOptionSet.contains(.blocking) let isBlocking = relationshipActionOptionSet.contains(.blocking)
let isDomainBlocking = domains.contains(mastodonUser.domainFromAcct) let isDomainBlocking = domains.contains(mastodonUser.domainFromAcct)
let needsShareAction = self.viewModel.isMeBarButtonItemsHidden.value let needsShareAction = self.viewModel.isMeBarButtonItemsHidden.value
let isInSameDomain = mastodonUser.domainFromAcct == currentDomain let isInSameDomain = mastodonUser.domainFromAcct == currentDomain
let isMyself = currentMastodonUser.id == mastodonUser.id
self.moreMenuBarButtonItem.menu = UserProviderFacade.createProfileActionMenu( self.moreMenuBarButtonItem.menu = UserProviderFacade.createProfileActionMenu(
for: mastodonUser, for: mastodonUser,
isMyself: isMyself,
isMuting: isMuting, isMuting: isMuting,
isBlocking: isBlocking, isBlocking: isBlocking,
canReport: true,
isInSameDomain: isInSameDomain, isInSameDomain: isInSameDomain,
isDomainBlocking: isDomainBlocking, isDomainBlocking: isDomainBlocking,
provider: self, provider: self,

View File

@ -356,8 +356,4 @@ extension StatusTableViewCell: ActionToolbarContainerDelegate {
delegate?.statusTableViewCell(self, actionToolbarContainer: actionToolbarContainer, likeButtonDidPressed: sender) delegate?.statusTableViewCell(self, actionToolbarContainer: actionToolbarContainer, likeButtonDidPressed: sender)
} }
func actionToolbarContainer(_ actionToolbarContainer: ActionToolbarContainer, moreButtonDidPressed sender: UIButton) {
}
} }

View File

@ -12,7 +12,6 @@ protocol ActionToolbarContainerDelegate: class {
func actionToolbarContainer(_ actionToolbarContainer: ActionToolbarContainer, replayButtonDidPressed sender: UIButton) func actionToolbarContainer(_ actionToolbarContainer: ActionToolbarContainer, replayButtonDidPressed sender: UIButton)
func actionToolbarContainer(_ actionToolbarContainer: ActionToolbarContainer, reblogButtonDidPressed sender: UIButton) func actionToolbarContainer(_ actionToolbarContainer: ActionToolbarContainer, reblogButtonDidPressed sender: UIButton)
func actionToolbarContainer(_ actionToolbarContainer: ActionToolbarContainer, starButtonDidPressed sender: UIButton) func actionToolbarContainer(_ actionToolbarContainer: ActionToolbarContainer, starButtonDidPressed sender: UIButton)
func actionToolbarContainer(_ actionToolbarContainer: ActionToolbarContainer, moreButtonDidPressed sender: UIButton)
} }
@ -63,7 +62,6 @@ extension ActionToolbarContainer {
replyButton.addTarget(self, action: #selector(ActionToolbarContainer.replyButtonDidPressed(_:)), for: .touchUpInside) replyButton.addTarget(self, action: #selector(ActionToolbarContainer.replyButtonDidPressed(_:)), for: .touchUpInside)
reblogButton.addTarget(self, action: #selector(ActionToolbarContainer.reblogButtonDidPressed(_:)), for: .touchUpInside) reblogButton.addTarget(self, action: #selector(ActionToolbarContainer.reblogButtonDidPressed(_:)), for: .touchUpInside)
favoriteButton.addTarget(self, action: #selector(ActionToolbarContainer.favoriteButtonDidPressed(_:)), for: .touchUpInside) favoriteButton.addTarget(self, action: #selector(ActionToolbarContainer.favoriteButtonDidPressed(_:)), for: .touchUpInside)
moreButton.addTarget(self, action: #selector(ActionToolbarContainer.moreButtonDidPressed(_:)), for: .touchUpInside)
} }
} }
@ -194,11 +192,6 @@ extension ActionToolbarContainer {
delegate?.actionToolbarContainer(self, starButtonDidPressed: sender) delegate?.actionToolbarContainer(self, starButtonDidPressed: sender)
} }
@objc private func moreButtonDidPressed(_ sender: UIButton) {
os_log("%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
delegate?.actionToolbarContainer(self, moreButtonDidPressed: sender)
}
} }
#if DEBUG #if DEBUG

View File

@ -62,6 +62,6 @@ protocol PutQuery: RequestQuery { }
protocol DeleteQuery: RequestQuery { } protocol DeleteQuery: RequestQuery { }
extension DeleteQuery { extension DeleteQuery {
// By default a `PostQuery` does not has query items // By default a `DeleteQuery` does not has query items
var queryItems: [URLQueryItem]? { nil } var queryItems: [URLQueryItem]? { nil }
} }