Show disabled boosts accounts

This commit is contained in:
Marcin Czachurski 2023-10-23 08:47:36 +02:00
parent eed0f72d53
commit 8309cdecbd
4 changed files with 87 additions and 0 deletions

View File

@ -12,6 +12,20 @@ class AccountRelationshipHandler {
public static let shared = AccountRelationshipHandler()
private init() { }
func getAccountRelationships(for accountId: String, modelContext: ModelContext) -> [AccountRelationship] {
do {
var fetchDescriptor = FetchDescriptor<AccountRelationship>(
predicate: #Predicate { $0.pixelfedAccount?.id == accountId }
)
fetchDescriptor.includePendingChanges = true
return try modelContext.fetch(fetchDescriptor)
} catch {
CoreDataError.shared.handle(error, message: "Error during fetching account relationship (isBoostedMutedForAccount).")
return []
}
}
/// Check if boosted statuses from given account are muted.
func isBoostedStatusesMuted(accountId: String, status: Status, modelContext: ModelContext) -> Bool {
if status.reblog == nil {

View File

@ -307,6 +307,29 @@
}
}
},
"accounts.navigationBar.disabledBoosts" : {
"comment" : "Disabled boosts",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Disabled boosts"
}
},
"es" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Potenciadores desactivados"
}
},
"pl" : {
"stringUnit" : {
"state" : "translated",
"value" : "Ukryte podbicia"
}
}
}
},
"accounts.navigationBar.favouritedBy" : {
"comment" : "Favourited by",
"localizations" : {
@ -9819,6 +9842,29 @@
}
}
},
"userProfile.title.disabledBoosts" : {
"comment" : "Disabled boosts",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Disabled boosts"
}
},
"es" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Potenciadores desactivados"
}
},
"pl" : {
"stringUnit" : {
"state" : "translated",
"value" : "Ukryte podbicia"
}
}
}
},
"userProfile.title.edit" : {
"comment" : "Edit profile",
"localizations" : {

View File

@ -22,6 +22,7 @@ struct AccountsView: View {
case blocks
case mutes
case search(query: String)
case disabledBoosts
public var title: String {
switch self {
@ -37,6 +38,8 @@ struct AccountsView: View {
return NSLocalizedString("accounts.navigationBar.blocked", comment: "Blocked")
case .mutes:
return NSLocalizedString("accounts.navigationBar.mutes", comment: "Mutes")
case .disabledBoosts:
return NSLocalizedString("accounts.navigationBar.disabledBoosts", comment: "Disabled boosts")
case .search(let query):
return query
}
@ -45,6 +48,7 @@ struct AccountsView: View {
@Environment(ApplicationState.self) var applicationState
@Environment(Client.self) var client
@Environment(\.modelContext) private var modelContext
@State var listType: ListType
@ -188,6 +192,25 @@ struct AccountsView: View {
} else {
return []
}
case .disabledBoosts:
if let accountId = self.applicationState.account?.id, self.downloadedPage == 1 {
let accountRelationships = AccountRelationshipHandler.shared.getAccountRelationships(for: accountId, modelContext: modelContext)
var downloadedAccounts: [Account] = []
for accountRelationship in accountRelationships {
do {
if let account = try await self.client.accounts?.account(withId: accountRelationship.accountId) {
downloadedAccounts.append(account)
}
} catch {
ErrorService.shared.handle(error, message: "accounts.error.loadingAccountsFailed", showToastr: false)
}
}
return downloadedAccounts
} else {
return []
}
}
}

View File

@ -270,6 +270,10 @@ struct UserProfileView: View {
Label(NSLocalizedString("userProfile.title.mutes", comment: "Muted accounts"), systemImage: "message.and.waveform.fill")
}
NavigationLink(value: RouteurDestinations.accounts(listType: .disabledBoosts)) {
Label(NSLocalizedString("userProfile.title.disabledBoosts", comment: "Disabled boosts"), image: "custom.rocket.fill")
}
if account.locked {
NavigationLink(value: RouteurDestinations.followRequests) {
Label(NSLocalizedString("userProfile.title.followRequests", comment: "FollowRequests"), systemImage: "person.crop.circle.badge.checkmark")