Show text on relationship-button based on relationship (IOS-192)

This commit is contained in:
Nathan Mattes 2023-12-27 15:45:06 +01:00
parent 1b1274c2f7
commit dda0ae2d7c
7 changed files with 49 additions and 26 deletions

View File

@ -150,10 +150,10 @@ extension Persistence.MastodonUser {
relationship.requested.flatMap { user.update(isFollowRequested: $0, by: me) }
// relationship.endorsed.flatMap { user.update(isEndorsed: $0, by: me) }
me.update(isFollowing: relationship.followedBy, by: user)
relationship.muting.flatMap { user.update(isMuting: $0, by: me) }
user.update(isMuting: relationship.muting, by: me)
user.update(isBlocking: relationship.blocking, by: me)
relationship.domainBlocking.flatMap { user.update(isDomainBlocking: $0, by: me) }
relationship.blockedBy.flatMap { me.update(isBlocking: $0, by: user) }
relationship.showingReblogs.flatMap { me.update(isShowingReblogs: $0, by: user) }
user.update(isDomainBlocking: relationship.domainBlocking, by: me)
me.update(isBlocking: relationship.blockedBy, by: user)
me.update(isShowingReblogs: relationship.showingReblogs, by: user)
}
}

View File

@ -72,7 +72,7 @@ extension APIService {
authorization: authenticationBox.userAuthorization
).singleOutput().value.first
let oldShowReblogs = relationship?.showingReblogs == true
let oldShowReblogs = relationship?.showingReblogs ?? true
let newShowReblogs = (oldShowReblogs == false)
let response = try await Mastodon.API.Account.follow(

View File

@ -73,7 +73,7 @@ extension APIService {
let muteContext = MastodonMuteContext(
targetUserID: account.id,
targetUsername: account.username,
isMuting: relationship.muting ?? false
isMuting: relationship.muting
)
let result: Result<Mastodon.Response.Content<Mastodon.Entity.Relationship>, Error>

View File

@ -17,22 +17,33 @@ extension Mastodon.Entity {
/// # Reference
/// [Document](https://docs.joinmastodon.org/entities/relationship/)
public struct Relationship: Codable, Sendable, Equatable, Hashable {
public typealias ID = String
public let id: ID
/// The account ID
public let id: String
/// Are you following this user?
public let following: Bool
/// Do you have a pending follow request for this user?
public let requested: Bool?
public let endorsed: Bool?
/// Are you featuring this user on your profile?
public let endorsed: Bool
/// Are you followed by this user?
public let followedBy: Bool
public let muting: Bool?
public let mutingNotifications: Bool?
public let showingReblogs: Bool?
public let notifying: Bool?
/// Are you muting this user?
public let muting: Bool
/// Are you muting notifications from this user?
public let mutingNotifications: Bool
/// Are you receiving this users boosts in your home timeline?
public let showingReblogs: Bool
/// Have you enabled notifications for this user?
public let notifying: Bool
/// Are you blocking this user?
public let blocking: Bool
public let domainBlocking: Bool?
public let blockedBy: Bool?
/// Are you blocking this users domain?
public let domainBlocking: Bool
/// Is this user blocking you?
public let blockedBy: Bool
/// This users profile bio
public let note: String?
enum CodingKeys: String, CodingKey {
case id
case following

View File

@ -248,7 +248,7 @@ extension StatusView {
).singleOutput().value {
guard let rel = relationship.first else { return }
DispatchQueue.main.async { [self] in
viewModel.isMuting = rel.muting ?? false
viewModel.isMuting = rel.muting
viewModel.isBlocking = rel.blocking
viewModel.isFollowed = rel.followedBy
}

View File

@ -267,7 +267,7 @@ public extension UserView {
buttonState = .none
} else if relationship.following {
buttonState = .unfollow
} else if relationship.blocking || (relationship.domainBlocking ?? false) {
} else if relationship.blocking || relationship.domainBlocking {
buttonState = .blocked
} else if relationship.requested ?? false {
buttonState = .pending

View File

@ -57,25 +57,37 @@ extension ProfileRelationshipActionButton {
extension ProfileRelationshipActionButton {
public func configure(relationship: Mastodon.Entity.Relationship, between user: Mastodon.Entity.Account, and me: Mastodon.Entity.Account, isEditing: Bool = false, isUpdating: Bool = false) {
public func configure(relationship: Mastodon.Entity.Relationship, between account: Mastodon.Entity.Account, and me: Mastodon.Entity.Account, isEditing: Bool = false, isUpdating: Bool = false) {
let isMyself = (user == me)
let isMyself = (account == me)
let title: String
if isMyself {
if isEditing {
title = "SAVE"
title = L10n.Common.Controls.Actions.save
} else {
title = "EDIT"
title = L10n.Common.Controls.Friendship.editInfo
}
} else if relationship.blocking {
title = L10n.Common.Controls.Friendship.blocked
} else if relationship.domainBlocking {
#warning("Wait for #1198 (Domain Block, IOS-5) to be merged")
title = "Unblock domain"
} else if (relationship.requested ?? false) {
title = L10n.Common.Controls.Friendship.pending
} else if relationship.muting {
title = L10n.Common.Controls.Friendship.muted
} else if relationship.following {
title = L10n.Common.Controls.Friendship.follow
title = L10n.Common.Controls.Friendship.following
} else if account.locked {
title = L10n.Common.Controls.Friendship.request
} else {
title = "TITLE"
title = L10n.Common.Controls.Friendship.follow
}
setTitle(title, for: .normal)
if relationship.blocking || user.suspended ?? false {
if relationship.blocking || account.suspended ?? false {
isEnabled = false
} else {
isEnabled = true