Block / mute UI

This commit is contained in:
Justin Mazzocchi 2021-02-10 18:04:04 -08:00
parent 5de072aa8f
commit 78355a8afc
No known key found for this signature in database
GPG Key ID: E223E6937AAFB01C
9 changed files with 111 additions and 13 deletions

View File

@ -42,6 +42,8 @@ public extension CollectionItem {
case withNote case withNote
case withoutNote case withoutNote
case followRequest case followRequest
case mute
case block
} }
var itemId: Id? { var itemId: Id? {

View File

@ -10,6 +10,7 @@
"account.block" = "Block"; "account.block" = "Block";
"account.block-and-report" = "Block & report"; "account.block-and-report" = "Block & report";
"account.block.confirm-%@" = "Block %@?"; "account.block.confirm-%@" = "Block %@?";
"account.blocked" = "Blocked";
"account.domain-block-%@" = "Block domain %@"; "account.domain-block-%@" = "Block domain %@";
"account.domain-block.confirm-%@" = "Block domain %@?"; "account.domain-block.confirm-%@" = "Block domain %@?";
"account.domain-unblock-%@" = "Unblock domain %@"; "account.domain-unblock-%@" = "Unblock domain %@";
@ -30,6 +31,7 @@
"account.mute.confirm.hide-notifications" = "Hide notifications from this user?"; "account.mute.confirm.hide-notifications" = "Hide notifications from this user?";
"account.mute.confirm.duration" = "Duration"; "account.mute.confirm.duration" = "Duration";
"account.mute.target-%@" = "Muting %@"; "account.mute.target-%@" = "Muting %@";
"account.muted" = "Muted";
"account.reject-follow-request-button.accessibility-label" = "Reject follow request"; "account.reject-follow-request-button.accessibility-label" = "Reject follow request";
"account.request" = "Request"; "account.request" = "Request";
"account.request.cancel" = "Cancel follow request"; "account.request.cancel" = "Cancel follow request";

View File

@ -62,7 +62,7 @@
D03D87F425C23C44004DCBB2 /* SecondaryNavigationTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D03D87F325C23C44004DCBB2 /* SecondaryNavigationTitleView.swift */; }; D03D87F425C23C44004DCBB2 /* SecondaryNavigationTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D03D87F325C23C44004DCBB2 /* SecondaryNavigationTitleView.swift */; };
D0477F1525C68BAC005C5368 /* PrefetchRequestModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0477F1425C68BAC005C5368 /* PrefetchRequestModifier.swift */; }; D0477F1525C68BAC005C5368 /* PrefetchRequestModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0477F1425C68BAC005C5368 /* PrefetchRequestModifier.swift */; };
D0477F2C25C6EBAD005C5368 /* OpenInDefaultBrowserActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0477F2B25C6EBAD005C5368 /* OpenInDefaultBrowserActivity.swift */; }; D0477F2C25C6EBAD005C5368 /* OpenInDefaultBrowserActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0477F2B25C6EBAD005C5368 /* OpenInDefaultBrowserActivity.swift */; };
D0477F4625C72E50005C5368 /* FollowsYouLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0477F4525C72E50005C5368 /* FollowsYouLabel.swift */; }; D0477F4625C72E50005C5368 /* CapsuleLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0477F4525C72E50005C5368 /* CapsuleLabel.swift */; };
D04F9E8E259E9C950081B0C9 /* ViewModels in Frameworks */ = {isa = PBXBuildFile; productRef = D04F9E8D259E9C950081B0C9 /* ViewModels */; }; D04F9E8E259E9C950081B0C9 /* ViewModels in Frameworks */ = {isa = PBXBuildFile; productRef = D04F9E8D259E9C950081B0C9 /* ViewModels */; };
D05936CF25A8D79800754FDF /* EditAttachmentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D05936CE25A8D79800754FDF /* EditAttachmentViewController.swift */; }; D05936CF25A8D79800754FDF /* EditAttachmentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D05936CE25A8D79800754FDF /* EditAttachmentViewController.swift */; };
D05936D025A8D79800754FDF /* EditAttachmentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D05936CE25A8D79800754FDF /* EditAttachmentViewController.swift */; }; D05936D025A8D79800754FDF /* EditAttachmentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D05936CE25A8D79800754FDF /* EditAttachmentViewController.swift */; };
@ -271,7 +271,7 @@
D03D87F325C23C44004DCBB2 /* SecondaryNavigationTitleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecondaryNavigationTitleView.swift; sourceTree = "<group>"; }; D03D87F325C23C44004DCBB2 /* SecondaryNavigationTitleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecondaryNavigationTitleView.swift; sourceTree = "<group>"; };
D0477F1425C68BAC005C5368 /* PrefetchRequestModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrefetchRequestModifier.swift; sourceTree = "<group>"; }; D0477F1425C68BAC005C5368 /* PrefetchRequestModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrefetchRequestModifier.swift; sourceTree = "<group>"; };
D0477F2B25C6EBAD005C5368 /* OpenInDefaultBrowserActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenInDefaultBrowserActivity.swift; sourceTree = "<group>"; }; D0477F2B25C6EBAD005C5368 /* OpenInDefaultBrowserActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenInDefaultBrowserActivity.swift; sourceTree = "<group>"; };
D0477F4525C72E50005C5368 /* FollowsYouLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FollowsYouLabel.swift; sourceTree = "<group>"; }; D0477F4525C72E50005C5368 /* CapsuleLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CapsuleLabel.swift; sourceTree = "<group>"; };
D047FA8C24C3E21200AF17C5 /* Metatext.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Metatext.app; sourceTree = BUILT_PRODUCTS_DIR; }; D047FA8C24C3E21200AF17C5 /* Metatext.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Metatext.app; sourceTree = BUILT_PRODUCTS_DIR; };
D05936CE25A8D79800754FDF /* EditAttachmentViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditAttachmentViewController.swift; sourceTree = "<group>"; }; D05936CE25A8D79800754FDF /* EditAttachmentViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditAttachmentViewController.swift; sourceTree = "<group>"; };
D05936DD25A937EC00754FDF /* EditThumbnailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditThumbnailView.swift; sourceTree = "<group>"; }; D05936DD25A937EC00754FDF /* EditThumbnailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditThumbnailView.swift; sourceTree = "<group>"; };
@ -459,7 +459,7 @@
D05936DD25A937EC00754FDF /* EditThumbnailView.swift */, D05936DD25A937EC00754FDF /* EditThumbnailView.swift */,
D07EC7FC25B16994006DF726 /* EmojiCategoryHeaderView.swift */, D07EC7FC25B16994006DF726 /* EmojiCategoryHeaderView.swift */,
D0DDA77E25C6058300FA0F91 /* ExploreSectionHeaderView.swift */, D0DDA77E25C6058300FA0F91 /* ExploreSectionHeaderView.swift */,
D0477F4525C72E50005C5368 /* FollowsYouLabel.swift */, D0477F4525C72E50005C5368 /* CapsuleLabel.swift */,
D0BE97D625D0863E0057E161 /* ImagePastableTextView.swift */, D0BE97D625D0863E0057E161 /* ImagePastableTextView.swift */,
D0D2AC6625BD0484003D5DF2 /* LineChartView.swift */, D0D2AC6625BD0484003D5DF2 /* LineChartView.swift */,
D0BEB1F624F9A84B001B0F04 /* LoadingTableFooterView.swift */, D0BEB1F624F9A84B001B0F04 /* LoadingTableFooterView.swift */,
@ -1114,7 +1114,7 @@
D0E1F583251F13EC00D45315 /* WebfingerIndicatorView.swift in Sources */, D0E1F583251F13EC00D45315 /* WebfingerIndicatorView.swift in Sources */,
D0BEB20524FA1107001B0F04 /* FiltersView.swift in Sources */, D0BEB20524FA1107001B0F04 /* FiltersView.swift in Sources */,
D0DDA76B25C5F20800FA0F91 /* ExploreDataSource.swift in Sources */, D0DDA76B25C5F20800FA0F91 /* ExploreDataSource.swift in Sources */,
D0477F4625C72E50005C5368 /* FollowsYouLabel.swift in Sources */, D0477F4625C72E50005C5368 /* CapsuleLabel.swift in Sources */,
D035F88725B8016000DC75ED /* NavigationViewModel+Extensions.swift in Sources */, D035F88725B8016000DC75ED /* NavigationViewModel+Extensions.swift in Sources */,
D0C7D49B24F7616A001EBDBB /* PreferencesView.swift in Sources */, D0C7D49B24F7616A001EBDBB /* PreferencesView.swift in Sources */,
D09D972225C65682007E6394 /* SeparatorConfiguredCollectionViewListCell.swift in Sources */, D09D972225C65682007E6394 /* SeparatorConfiguredCollectionViewListCell.swift in Sources */,

View File

@ -5,6 +5,10 @@ import MastodonAPI
extension AccountsEndpoint { extension AccountsEndpoint {
var configuration: CollectionItem.AccountConfiguration { var configuration: CollectionItem.AccountConfiguration {
switch self { switch self {
case .mutes:
return .mute
case .blocks:
return .block
case .followRequests: case .followRequests:
return .followRequest return .followRequest
default: default:

View File

@ -114,6 +114,22 @@ public extension NavigationViewModel {
titleComponents: ["follow-requests"]))) titleComponents: ["follow-requests"])))
} }
func navigateToMutedUsers() {
presentingSecondaryNavigation = false
presentedNewStatusViewModel = nil
navigationsSubject.send(.collection(identityContext.service.service(
accountList: .mutes,
titleComponents: ["preferences.muted-users"])))
}
func navigateToBlockedUsers() {
presentingSecondaryNavigation = false
presentedNewStatusViewModel = nil
navigationsSubject.send(.collection(identityContext.service.service(
accountList: .blocks,
titleComponents: ["preferences.blocked-users"])))
}
func navigate(pushNotification: PushNotification) { func navigate(pushNotification: PushNotification) {
switch pushNotification.notificationType { switch pushNotification.notificationType {
case .followRequest: case .followRequest:

View File

@ -7,6 +7,7 @@ import ViewModels
struct PreferencesView: View { struct PreferencesView: View {
@StateObject var viewModel: PreferencesViewModel @StateObject var viewModel: PreferencesViewModel
@StateObject var identityContext: IdentityContext @StateObject var identityContext: IdentityContext
@EnvironmentObject var rootViewModel: RootViewModel
@Environment(\.accessibilityReduceMotion) var accessibilityReduceMotion @Environment(\.accessibilityReduceMotion) var accessibilityReduceMotion
init(viewModel: PreferencesViewModel) { init(viewModel: PreferencesViewModel) {
@ -27,12 +28,14 @@ struct PreferencesView: View {
destination: NotificationTypesPreferencesView( destination: NotificationTypesPreferencesView(
viewModel: .init(identityContext: viewModel.identityContext))) viewModel: .init(identityContext: viewModel.identityContext)))
} }
NavigationLink("preferences.muted-users", Button("preferences.muted-users") {
destination: TableView(viewModelClosure: viewModel.mutedUsersViewModel) rootViewModel.navigationViewModel?.navigateToMutedUsers()
.navigationTitle(Text("preferences.muted-users"))) }
NavigationLink("preferences.blocked-users", .foregroundColor(.primary)
destination: TableView(viewModelClosure: viewModel.blockedUsersViewModel) Button("preferences.blocked-users") {
.navigationTitle(Text("preferences.blocked-users"))) rootViewModel.navigationViewModel?.navigateToBlockedUsers()
}
.foregroundColor(.primary)
NavigationLink("preferences.blocked-domains", NavigationLink("preferences.blocked-domains",
destination: DomainBlocksView(viewModel: viewModel.domainBlocksViewModel())) destination: DomainBlocksView(viewModel: viewModel.domainBlocksViewModel()))
Toggle("preferences.use-preferences-from-server", Toggle("preferences.use-preferences-from-server",

View File

@ -19,7 +19,9 @@ final class AccountHeaderView: UIView {
let accountStackView = UIStackView() let accountStackView = UIStackView()
let accountLabel = UILabel() let accountLabel = UILabel()
let lockedImageView = UIImageView() let lockedImageView = UIImageView()
let followsYouLabel = FollowsYouLabel() let followsYouLabel = CapsuleLabel()
let mutedLabel = CapsuleLabel()
let blockedLabel = CapsuleLabel()
let fieldsStackView = UIStackView() let fieldsStackView = UIStackView()
let noteTextView = TouchFallthroughTextView() let noteTextView = TouchFallthroughTextView()
let followStackView = UIStackView() let followStackView = UIStackView()
@ -48,6 +50,8 @@ final class AccountHeaderView: UIView {
if !accountViewModel.isSelf, let relationship = accountViewModel.relationship { if !accountViewModel.isSelf, let relationship = accountViewModel.relationship {
followsYouLabel.isHidden = !relationship.followedBy followsYouLabel.isHidden = !relationship.followedBy
mutedLabel.isHidden = !relationship.muting
blockedLabel.isHidden = !relationship.blocking
followButton.setTitle( followButton.setTitle(
NSLocalizedString( NSLocalizedString(
accountViewModel.isLocked ? "account.request" : "account.follow", accountViewModel.isLocked ? "account.request" : "account.follow",
@ -316,6 +320,14 @@ private extension AccountHeaderView {
followsYouLabel.text = NSLocalizedString("account.follows-you", comment: "") followsYouLabel.text = NSLocalizedString("account.follows-you", comment: "")
followsYouLabel.isHidden = true followsYouLabel.isHidden = true
accountStackView.addArrangedSubview(mutedLabel)
mutedLabel.text = NSLocalizedString("account.muted", comment: "")
mutedLabel.isHidden = true
accountStackView.addArrangedSubview(blockedLabel)
blockedLabel.text = NSLocalizedString("account.blocked", comment: "")
blockedLabel.isHidden = true
accountStackView.addArrangedSubview(UIView()) accountStackView.addArrangedSubview(UIView())
baseStackView.addArrangedSubview(fieldsStackView) baseStackView.addArrangedSubview(fieldsStackView)

View File

@ -2,7 +2,7 @@
import UIKit import UIKit
final class FollowsYouLabel: UILabel { final class CapsuleLabel: UILabel {
override init(frame: CGRect) { override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
@ -34,7 +34,7 @@ final class FollowsYouLabel: UILabel {
} }
} }
private extension FollowsYouLabel { private extension CapsuleLabel {
var inset: CGFloat { bounds.height / 2 } var inset: CGFloat { bounds.height / 2 }
func initialSetup() { func initialSetup() {

View File

@ -12,6 +12,10 @@ final class AccountView: UIView {
let noteTextView = TouchFallthroughTextView() let noteTextView = TouchFallthroughTextView()
let acceptFollowRequestButton = UIButton() let acceptFollowRequestButton = UIButton()
let rejectFollowRequestButton = UIButton() let rejectFollowRequestButton = UIButton()
let muteButton = UIButton(type: .system)
let unmuteButton = UIButton(type: .system)
let blockButton = UIButton(type: .system)
let unblockButton = UIButton(type: .system)
private var accountConfiguration: AccountContentConfiguration private var accountConfiguration: AccountContentConfiguration
@ -135,6 +139,38 @@ private extension AccountView {
UIAction { [weak self] _ in self?.accountConfiguration.viewModel.rejectFollowRequest() }, UIAction { [weak self] _ in self?.accountConfiguration.viewModel.rejectFollowRequest() },
for: .touchUpInside) for: .touchUpInside)
stackView.addArrangedSubview(muteButton)
muteButton.setTitle(NSLocalizedString("account.mute", comment: ""), for: .normal)
muteButton.titleLabel?.adjustsFontForContentSizeCategory = true
muteButton.titleLabel?.font = .preferredFont(forTextStyle: .callout)
muteButton.addAction(
UIAction { [weak self] _ in self?.accountConfiguration.viewModel.confirmMute() },
for: .touchUpInside)
stackView.addArrangedSubview(unmuteButton)
unmuteButton.setTitle(NSLocalizedString("account.unmute", comment: ""), for: .normal)
unmuteButton.titleLabel?.adjustsFontForContentSizeCategory = true
unmuteButton.titleLabel?.font = .preferredFont(forTextStyle: .callout)
unmuteButton.addAction(
UIAction { [weak self] _ in self?.accountConfiguration.viewModel.confirmUnmute() },
for: .touchUpInside)
stackView.addArrangedSubview(blockButton)
blockButton.setTitle(NSLocalizedString("account.block", comment: ""), for: .normal)
blockButton.titleLabel?.adjustsFontForContentSizeCategory = true
blockButton.titleLabel?.font = .preferredFont(forTextStyle: .callout)
blockButton.addAction(
UIAction { [weak self] _ in self?.accountConfiguration.viewModel.confirmBlock() },
for: .touchUpInside)
stackView.addArrangedSubview(unblockButton)
unblockButton.setTitle(NSLocalizedString("account.unblock", comment: ""), for: .normal)
unblockButton.titleLabel?.adjustsFontForContentSizeCategory = true
unblockButton.titleLabel?.font = .preferredFont(forTextStyle: .callout)
unblockButton.addAction(
UIAction { [weak self] _ in self?.accountConfiguration.viewModel.confirmUnblock() },
for: .touchUpInside)
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
avatarImageView.widthAnchor.constraint(equalToConstant: .avatarDimension), avatarImageView.widthAnchor.constraint(equalToConstant: .avatarDimension),
avatarImageView.heightAnchor.constraint(equalToConstant: .avatarDimension), avatarImageView.heightAnchor.constraint(equalToConstant: .avatarDimension),
@ -142,6 +178,10 @@ private extension AccountView {
acceptFollowRequestButton.heightAnchor.constraint(greaterThanOrEqualToConstant: .avatarDimension), acceptFollowRequestButton.heightAnchor.constraint(greaterThanOrEqualToConstant: .avatarDimension),
rejectFollowRequestButton.widthAnchor.constraint(greaterThanOrEqualToConstant: .avatarDimension), rejectFollowRequestButton.widthAnchor.constraint(greaterThanOrEqualToConstant: .avatarDimension),
rejectFollowRequestButton.heightAnchor.constraint(greaterThanOrEqualToConstant: .avatarDimension), rejectFollowRequestButton.heightAnchor.constraint(greaterThanOrEqualToConstant: .avatarDimension),
muteButton.heightAnchor.constraint(greaterThanOrEqualToConstant: .avatarDimension),
unmuteButton.heightAnchor.constraint(greaterThanOrEqualToConstant: .avatarDimension),
blockButton.heightAnchor.constraint(greaterThanOrEqualToConstant: .avatarDimension),
unblockButton.heightAnchor.constraint(greaterThanOrEqualToConstant: .avatarDimension),
stackView.leadingAnchor.constraint(equalTo: readableContentGuide.leadingAnchor), stackView.leadingAnchor.constraint(equalTo: readableContentGuide.leadingAnchor),
stackView.topAnchor.constraint(equalTo: readableContentGuide.topAnchor), stackView.topAnchor.constraint(equalTo: readableContentGuide.topAnchor),
stackView.bottomAnchor.constraint(equalTo: readableContentGuide.bottomAnchor), stackView.bottomAnchor.constraint(equalTo: readableContentGuide.bottomAnchor),
@ -191,6 +231,25 @@ private extension AccountView {
acceptFollowRequestButton.isHidden = !isFollowRequest acceptFollowRequestButton.isHidden = !isFollowRequest
rejectFollowRequestButton.isHidden = !isFollowRequest rejectFollowRequestButton.isHidden = !isFollowRequest
if let relationship = viewModel.relationship {
if viewModel.configuration == .mute {
muteButton.isHidden = relationship.muting
unmuteButton.isHidden = !relationship.muting
blockButton.isHidden = true
unblockButton.isHidden = true
} else if viewModel.configuration == .block {
muteButton.isHidden = true
unmuteButton.isHidden = true
blockButton.isHidden = relationship.blocking
unblockButton.isHidden = !relationship.blocking
}
} else {
muteButton.isHidden = true
unmuteButton.isHidden = true
blockButton.isHidden = true
unblockButton.isHidden = true
}
let accessibilityAttributedLabel = NSMutableAttributedString(string: "") let accessibilityAttributedLabel = NSMutableAttributedString(string: "")
if !displayNameLabel.isHidden, let displayName = displayNameLabel.attributedText { if !displayNameLabel.isHidden, let displayName = displayNameLabel.attributedText {