mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-22 00:01:00 +00:00
Bell button
This commit is contained in:
parent
2bab10b0fb
commit
5749225786
7 changed files with 77 additions and 8 deletions
|
@ -290,6 +290,12 @@ extension ContentDatabase {
|
|||
}
|
||||
}
|
||||
|
||||
migrator.registerMigration("1.0.0-notifying") { db in
|
||||
try db.alter(table: "relationship") { t in
|
||||
t.add(column: "notifying", .boolean)
|
||||
}
|
||||
}
|
||||
|
||||
return migrator
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
"account.mute.confirm.duration" = "Duration";
|
||||
"account.mute.target-%@" = "Mute %@";
|
||||
"account.muted" = "Muted";
|
||||
"account.notify" = "Turn on notifications";
|
||||
"account.reject-follow-request-button.accessibility-label" = "Reject follow request";
|
||||
"account.request" = "Request";
|
||||
"account.request.cancel" = "Cancel follow request";
|
||||
|
@ -51,6 +52,7 @@
|
|||
"account.unfollow.confirm-%@" = "Unfollow %@?";
|
||||
"account.unmute" = "Unmute";
|
||||
"account.unmute.confirm-%@" = "Unmute %@?";
|
||||
"account.unnotify" = "Turn off notifications";
|
||||
"activity.open-in-default-browser" = "Open in default browser";
|
||||
"add" = "Add";
|
||||
"apns-default-message" = "New notification";
|
||||
|
|
|
@ -11,6 +11,7 @@ public struct Relationship: Codable, Hashable {
|
|||
public let muting: Bool
|
||||
@DecodableDefault.False public private(set) var mutingNotifications: Bool
|
||||
@DecodableDefault.False public private(set) var showingReblogs: Bool
|
||||
public let notifying: Bool?
|
||||
public let blocking: Bool
|
||||
public let domainBlocking: Bool
|
||||
@DecodableDefault.False public private(set) var blockedBy: Bool
|
||||
|
|
|
@ -5,7 +5,7 @@ import HTTP
|
|||
import Mastodon
|
||||
|
||||
public enum RelationshipEndpoint {
|
||||
case accountsFollow(id: Account.Id, showReblogs: Bool? = nil)
|
||||
case accountsFollow(id: Account.Id, showReblogs: Bool? = nil, notify: Bool? = nil)
|
||||
case accountsUnfollow(id: Account.Id)
|
||||
case accountsBlock(id: Account.Id)
|
||||
case accountsUnblock(id: Account.Id)
|
||||
|
@ -32,7 +32,7 @@ extension RelationshipEndpoint: Endpoint {
|
|||
|
||||
public var pathComponentsInContext: [String] {
|
||||
switch self {
|
||||
case let .accountsFollow(id, _):
|
||||
case let .accountsFollow(id, _, _):
|
||||
return [id, "follow"]
|
||||
case let .accountsUnfollow(id):
|
||||
return [id, "unfollow"]
|
||||
|
@ -59,12 +59,18 @@ extension RelationshipEndpoint: Endpoint {
|
|||
|
||||
public var queryParameters: [URLQueryItem] {
|
||||
switch self {
|
||||
case let .accountsFollow(_, showReblogs):
|
||||
case let .accountsFollow(_, showReblogs, notify):
|
||||
var params = [URLQueryItem]()
|
||||
|
||||
if let showReblogs = showReblogs {
|
||||
return [URLQueryItem(name: "reblogs", value: String(showReblogs))]
|
||||
} else {
|
||||
return []
|
||||
params.append(URLQueryItem(name: "reblogs", value: String(showReblogs)))
|
||||
}
|
||||
|
||||
if let notify = notify {
|
||||
params.append(URLQueryItem(name: "notify", value: String(notify)))
|
||||
}
|
||||
|
||||
return params
|
||||
default:
|
||||
return []
|
||||
}
|
||||
|
|
|
@ -51,6 +51,14 @@ public extension AccountService {
|
|||
relationshipAction(.accountsFollow(id: account.id, showReblogs: true))
|
||||
}
|
||||
|
||||
func notify() -> AnyPublisher<Never, Error> {
|
||||
relationshipAction(.accountsFollow(id: account.id, notify: true))
|
||||
}
|
||||
|
||||
func unnotify() -> AnyPublisher<Never, Error> {
|
||||
relationshipAction(.accountsFollow(id: account.id, notify: false))
|
||||
}
|
||||
|
||||
func block() -> AnyPublisher<Never, Error> {
|
||||
relationshipAction(.accountsBlock(id: account.id))
|
||||
.collect()
|
||||
|
|
|
@ -137,6 +137,14 @@ public extension AccountViewModel {
|
|||
ignorableOutputEvent(accountService.showReblogs())
|
||||
}
|
||||
|
||||
func notify() {
|
||||
ignorableOutputEvent(accountService.notify())
|
||||
}
|
||||
|
||||
func unnotify() {
|
||||
ignorableOutputEvent(accountService.unnotify())
|
||||
}
|
||||
|
||||
func confirmBlock() {
|
||||
eventsSubject.send(Just(.confirmBlock(self)).setFailureType(to: Error.self).eraseToAnyPublisher())
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ final class AccountHeaderView: UIView {
|
|||
let relationshipButtonsStackView = UIStackView()
|
||||
let followButton = UIButton(type: .system)
|
||||
let unfollowButton = UIButton(type: .system)
|
||||
let notifyButton = UIButton()
|
||||
let unnotifyButton = UIButton()
|
||||
let displayNameLabel = AnimatedAttachmentLabel()
|
||||
let accountStackView = UIStackView()
|
||||
let accountLabel = UILabel()
|
||||
|
@ -69,6 +71,19 @@ final class AccountHeaderView: UIView {
|
|||
comment: ""),
|
||||
for: .normal)
|
||||
|
||||
if relationship.following, let notifying = relationship.notifying {
|
||||
if notifying {
|
||||
notifyButton.isHidden = true
|
||||
unnotifyButton.isHidden = false
|
||||
} else {
|
||||
notifyButton.isHidden = false
|
||||
unnotifyButton.isHidden = true
|
||||
}
|
||||
} else {
|
||||
notifyButton.isHidden = true
|
||||
unnotifyButton.isHidden = true
|
||||
}
|
||||
|
||||
relationshipButtonsStackView.isHidden = false
|
||||
unavailableLabel.isHidden = !relationship.blockedBy
|
||||
} else {
|
||||
|
@ -201,7 +216,7 @@ final class AccountHeaderView: UIView {
|
|||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
|
||||
for button in [followButton, unfollowButton] {
|
||||
for button in [followButton, unfollowButton, notifyButton, unnotifyButton] {
|
||||
let inset = (followButton.bounds.height - (button.titleLabel?.bounds.height ?? 0)) / 2
|
||||
|
||||
button.contentEdgeInsets = .init(top: 0, left: inset, bottom: 0, right: inset)
|
||||
|
@ -284,7 +299,7 @@ private extension AccountHeaderView {
|
|||
relationshipButtonsStackView.spacing = .defaultSpacing
|
||||
relationshipButtonsStackView.addArrangedSubview(UIView())
|
||||
|
||||
for button in [followButton, unfollowButton] {
|
||||
for button in [followButton, unfollowButton, notifyButton, unnotifyButton] {
|
||||
relationshipButtonsStackView.addArrangedSubview(button)
|
||||
button.titleLabel?.font = .preferredFont(forTextStyle: .headline)
|
||||
button.titleLabel?.adjustsFontForContentSizeCategory = true
|
||||
|
@ -296,6 +311,7 @@ private extension AccountHeaderView {
|
|||
systemName: "person.badge.plus",
|
||||
withConfiguration: UIImage.SymbolConfiguration(scale: .small)),
|
||||
for: .normal)
|
||||
followButton.isHidden = true
|
||||
followButton.addAction(
|
||||
UIAction { [weak self] _ in self?.viewModel.accountViewModel?.follow() },
|
||||
for: .touchUpInside)
|
||||
|
@ -306,10 +322,32 @@ private extension AccountHeaderView {
|
|||
withConfiguration: UIImage.SymbolConfiguration(scale: .small)),
|
||||
for: .normal)
|
||||
unfollowButton.setTitle(NSLocalizedString("account.unfollow", comment: ""), for: .normal)
|
||||
unfollowButton.isHidden = true
|
||||
unfollowButton.addAction(
|
||||
UIAction { [weak self] _ in self?.viewModel.accountViewModel?.confirmUnfollow() },
|
||||
for: .touchUpInside)
|
||||
|
||||
notifyButton.setImage(
|
||||
UIImage(systemName: "bell",
|
||||
withConfiguration: UIImage.SymbolConfiguration(scale: .large)),
|
||||
for: .normal)
|
||||
notifyButton.accessibilityLabel = NSLocalizedString("account.notify", comment: "")
|
||||
notifyButton.tintColor = .secondaryLabel
|
||||
notifyButton.isHidden = true
|
||||
notifyButton.addAction(
|
||||
UIAction { [weak self] _ in self?.viewModel.accountViewModel?.notify() },
|
||||
for: .touchUpInside)
|
||||
|
||||
unnotifyButton.setImage(
|
||||
UIImage(systemName: "bell.fill",
|
||||
withConfiguration: UIImage.SymbolConfiguration(scale: .large)),
|
||||
for: .normal)
|
||||
unnotifyButton.accessibilityLabel = NSLocalizedString("account.unnotify", comment: "")
|
||||
unnotifyButton.isHidden = true
|
||||
unnotifyButton.addAction(
|
||||
UIAction { [weak self] _ in self?.viewModel.accountViewModel?.unnotify() },
|
||||
for: .touchUpInside)
|
||||
|
||||
addSubview(baseStackView)
|
||||
baseStackView.translatesAutoresizingMaskIntoConstraints = false
|
||||
baseStackView.axis = .vertical
|
||||
|
|
Loading…
Reference in a new issue