From 1fb4eb2befe465caea4d0faca807c91a9829d648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Car=C3=ADcio?= Date: Thu, 19 Jan 2023 18:22:31 +0100 Subject: [PATCH] Allow to block/unblock and mute/unmute accounts (#120) * Allow to block and unblock accounts * Mute and unmute accounts * Implement Localization (#80) * Implement localization * Fix some localization keys * Adapt to recent changes * Allow to block and unblock accounts * Mute and unmute accounts * Add localization Co-authored-by: Thomas <38211057+vollkorntomate@users.noreply.github.com> Co-authored-by: Thomas Ricouard --- .../Localization/en.lproj/Localizable.strings | 4 + .../Sources/Account/AccountDetailView.swift | 103 ++++++++++++++++++ .../Sources/Network/Endpoint/Accounts.swift | 12 ++ 3 files changed, 119 insertions(+) diff --git a/IceCubesApp/Resources/Localization/en.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/en.lproj/Localizable.strings index a6ad87ea..15afb6e7 100644 --- a/IceCubesApp/Resources/Localization/en.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/en.lproj/Localizable.strings @@ -122,6 +122,10 @@ "account.action.edit-info" = "Edit Info"; "account.action.mention" = "Mention"; "account.action.message" = "Message"; +"account.action.block" = "Block"; +"account.action.unblock" = "Unblock"; +"account.action.mute" = "Mute"; +"account.action.unmute" = "Unmute"; "account.boosted-by" = "Boosted by"; "account.detail.about" = "About"; "account.detail.familiar-followers" = "Also followed by"; diff --git a/Packages/Account/Sources/Account/AccountDetailView.swift b/Packages/Account/Sources/Account/AccountDetailView.swift index d73f184e..c918ba28 100644 --- a/Packages/Account/Sources/Account/AccountDetailView.swift +++ b/Packages/Account/Sources/Account/AccountDetailView.swift @@ -366,6 +366,109 @@ public struct AccountDetailView: View { } label: { Label("account.action.message", systemImage: "tray.full") } + + Divider() + + if viewModel.relationship?.blocking == true { + Button { + Task { + do { + viewModel.relationship = try await client.post(endpoint: Accounts.unblock(id: account.id)) + } catch { + print("Error while unblocking: \(error.localizedDescription)") + } + } + } label: { + Label("account.action.unblock", systemImage: "person.crop.circle.badge.exclamationmark") + } + } else { + Button { + Task { + do { + viewModel.relationship = try await client.post(endpoint: Accounts.block(id: account.id)) + } catch { + print("Error while blocking: \(error.localizedDescription)") + } + } + } label: { + Label("account.action.block", systemImage: "person.crop.circle.badge.xmark") + } + } + if viewModel.relationship?.muting == true { + Button { + Task { + do { + viewModel.relationship = try await client.post(endpoint: Accounts.unmute(id: account.id)) + } catch { + print("Error while unmuting: \(error.localizedDescription)") + } + } + } label: { + Label("account.action.unmute", systemImage: "speaker") + } + } else { + Button { + Task { + do { + viewModel.relationship = try await client.post(endpoint: Accounts.mute(id: account.id)) + } catch { + print("Error while muting: \(error.localizedDescription)") + } + } + } label: { + Label("account.action.mute", systemImage: "speaker.slash") + } + } + if viewModel.relationship?.blocking == true { + Button { + Task { + do { + viewModel.relationship = try await client.post(endpoint: Accounts.unblock(id: account.id)) + } catch { + print("Error while unblocking: \(error.localizedDescription)") + } + } + } label: { + Label("Unblock", systemImage: "person.crop.circle.badge.exclamationmark") + } + } else { + Button { + Task { + do { + viewModel.relationship = try await client.post(endpoint: Accounts.block(id: account.id)) + } catch { + print("Error while blocking: \(error.localizedDescription)") + } + } + } label: { + Label("Block", systemImage: "person.crop.circle.badge.xmark") + } + } + if viewModel.relationship?.muting == true { + Button { + Task { + do { + viewModel.relationship = try await client.post(endpoint: Accounts.unmute(id: account.id)) + } catch { + print("Error while unmuting: \(error.localizedDescription)") + } + } + } label: { + Label("Unmute", systemImage: "speaker") + } + } else { + Button { + Task { + do { + viewModel.relationship = try await client.post(endpoint: Accounts.mute(id: account.id)) + } catch { + print("Error while muting: \(error.localizedDescription)") + } + } + } label: { + Label("Mute", systemImage: "speaker.slash") + } + } Divider() } diff --git a/Packages/Network/Sources/Network/Endpoint/Accounts.swift b/Packages/Network/Sources/Network/Endpoint/Accounts.swift index c723cf3e..cf00cf32 100644 --- a/Packages/Network/Sources/Network/Endpoint/Accounts.swift +++ b/Packages/Network/Sources/Network/Endpoint/Accounts.swift @@ -30,6 +30,10 @@ public enum Accounts: Endpoint { case following(id: String, maxId: String?) case lists(id: String) case preferences + case block(id: String) + case unblock(id: String) + case mute(id: String) + case unmute(id: String) public func path() -> String { switch self { @@ -67,6 +71,14 @@ public enum Accounts: Endpoint { return "accounts/\(id)/lists" case .preferences: return "preferences" + case let .block(id): + return "accounts/\(id)/block" + case let .unblock(id): + return "accounts/\(id)/unblock" + case let .mute(id): + return "accounts/\(id)/mute" + case let .unmute(id): + return "accounts/\(id)/unmute" } }