From 8309cdecbdfbffdc31a70600682ec8cd58bf9473 Mon Sep 17 00:00:00 2001 From: Marcin Czachurski Date: Mon, 23 Oct 2023 08:47:36 +0200 Subject: [PATCH] Show disabled boosts accounts --- CoreData/AccountRelationshipHandler.swift | 14 ++++++ Localization/Localizable.xcstrings | 46 +++++++++++++++++++ Vernissage/Views/AccountsView.swift | 23 ++++++++++ .../UserProfileView/UserProfileView.swift | 4 ++ 4 files changed, 87 insertions(+) diff --git a/CoreData/AccountRelationshipHandler.swift b/CoreData/AccountRelationshipHandler.swift index 3040383..19898de 100644 --- a/CoreData/AccountRelationshipHandler.swift +++ b/CoreData/AccountRelationshipHandler.swift @@ -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( + 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 { diff --git a/Localization/Localizable.xcstrings b/Localization/Localizable.xcstrings index 13dd086..11ad321 100644 --- a/Localization/Localizable.xcstrings +++ b/Localization/Localizable.xcstrings @@ -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" : { diff --git a/Vernissage/Views/AccountsView.swift b/Vernissage/Views/AccountsView.swift index 09f2e7b..7522155 100644 --- a/Vernissage/Views/AccountsView.swift +++ b/Vernissage/Views/AccountsView.swift @@ -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 [] + } } } diff --git a/Vernissage/Views/UserProfileView/UserProfileView.swift b/Vernissage/Views/UserProfileView/UserProfileView.swift index 3194ae3..8c65ca3 100644 --- a/Vernissage/Views/UserProfileView/UserProfileView.swift +++ b/Vernissage/Views/UserProfileView/UserProfileView.swift @@ -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")