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 <ricouard77@gmail.com>
This commit is contained in:
Rafael Caricio 2023-01-19 18:22:31 +01:00 committed by GitHub
parent 980b9a5dd6
commit 1fb4eb2bef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 119 additions and 0 deletions

View file

@ -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";

View file

@ -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()
}

View file

@ -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"
}
}