From f5aacf76246a8f1f096bbe4a16f4e5852d054570 Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Sat, 30 Jan 2021 16:38:56 -0800 Subject: [PATCH] Blocked by state --- Localizations/Localizable.strings | 1 + .../ViewModels/Entities/CollectionUpdate.swift | 7 +++++++ .../View Models/CollectionItemsViewModel.swift | 5 +---- .../ViewModels/View Models/ProfileViewModel.swift | 13 ++++++++++++- Views/UIKit/AccountHeaderView.swift | 11 +++++++++++ 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/Localizations/Localizable.strings b/Localizations/Localizable.strings index c036882..5dd34fe 100644 --- a/Localizations/Localizable.strings +++ b/Localizations/Localizable.strings @@ -21,6 +21,7 @@ "account.statuses-and-replies" = "Posts & Replies"; "account.media" = "Media"; "account.show-reblogs" = "Show boosts"; +"account.unavailable" = "Profile unavailable"; "account.unblock" = "Unblock"; "account.unblock.confirm-%@" = "Unblock %@?"; "account.unfollow" = "Unfollow"; diff --git a/ViewModels/Sources/ViewModels/Entities/CollectionUpdate.swift b/ViewModels/Sources/ViewModels/Entities/CollectionUpdate.swift index 53e6176..ce33770 100644 --- a/ViewModels/Sources/ViewModels/Entities/CollectionUpdate.swift +++ b/ViewModels/Sources/ViewModels/Entities/CollectionUpdate.swift @@ -5,3 +5,10 @@ public struct CollectionUpdate: Hashable { public let maintainScrollPositionItemId: String? public let shouldAdjustContentInset: Bool } + +extension CollectionUpdate { + static let empty: Self = Self( + sections: [], + maintainScrollPositionItemId: nil, + shouldAdjustContentInset: false) +} diff --git a/ViewModels/Sources/ViewModels/View Models/CollectionItemsViewModel.swift b/ViewModels/Sources/ViewModels/View Models/CollectionItemsViewModel.swift index 799f408..4a3c32f 100644 --- a/ViewModels/Sources/ViewModels/View Models/CollectionItemsViewModel.swift +++ b/ViewModels/Sources/ViewModels/View Models/CollectionItemsViewModel.swift @@ -11,10 +11,7 @@ public class CollectionItemsViewModel: ObservableObject { @Published public var alertItem: AlertItem? public private(set) var nextPageMaxId: String? - @Published private var lastUpdate = CollectionUpdate( - sections: [], - maintainScrollPositionItemId: nil, - shouldAdjustContentInset: false) + @Published private var lastUpdate = CollectionUpdate.empty private let collectionService: CollectionService private var viewModelCache = [CollectionItem: (viewModel: CollectionItemViewModel, events: AnyCancellable)]() private let eventsSubject = PassthroughSubject() diff --git a/ViewModels/Sources/ViewModels/View Models/ProfileViewModel.swift b/ViewModels/Sources/ViewModels/View Models/ProfileViewModel.swift index f7fe9ea..186bcfa 100644 --- a/ViewModels/Sources/ViewModels/View Models/ProfileViewModel.swift +++ b/ViewModels/Sources/ViewModels/View Models/ProfileViewModel.swift @@ -67,7 +67,18 @@ extension ProfileViewModel: CollectionViewModel { } public var updates: AnyPublisher { - collectionViewModel.flatMap(\.updates).eraseToAnyPublisher() + collectionViewModel.flatMap(\.updates) + .combineLatest($accountViewModel.map { $0?.relationship }) + .map { + let (updates, relationship) = $0 + + if let relationship = relationship, relationship.blockedBy { + return .empty + } else { + return updates + } + } + .eraseToAnyPublisher() } public var title: AnyPublisher { diff --git a/Views/UIKit/AccountHeaderView.swift b/Views/UIKit/AccountHeaderView.swift index 7ea465a..2f6737e 100644 --- a/Views/UIKit/AccountHeaderView.swift +++ b/Views/UIKit/AccountHeaderView.swift @@ -24,6 +24,7 @@ final class AccountHeaderView: UIView { let followingButton = UIButton() let followersButton = UIButton() let segmentedControl = UISegmentedControl() + let unavailableLabel = UILabel() var viewModel: ProfileViewModel? { didSet { @@ -47,8 +48,10 @@ final class AccountHeaderView: UIView { unfollowButton.isHidden = !relationship.following relationshipButtonsStackView.isHidden = false + unavailableLabel.isHidden = !relationship.blockedBy } else { relationshipButtonsStackView.isHidden = true + unavailableLabel.isHidden = true } if accountViewModel.displayName.isEmpty { @@ -319,6 +322,14 @@ private extension AccountHeaderView { baseStackView.addArrangedSubview(segmentedControl) + baseStackView.addArrangedSubview(unavailableLabel) + unavailableLabel.adjustsFontForContentSizeCategory = true + unavailableLabel.font = .preferredFont(forTextStyle: .title3) + unavailableLabel.textAlignment = .center + unavailableLabel.numberOfLines = 0 + unavailableLabel.text = NSLocalizedString("account.unavailable", comment: "") + unavailableLabel.isHidden = true + let headerImageAspectRatioConstraint = headerImageView.heightAnchor.constraint( equalTo: headerImageView.widthAnchor, multiplier: 1 / 3)