diff --git a/Iceshrimp.Frontend/Core/ControllerModels/UserControllerModel.cs b/Iceshrimp.Frontend/Core/ControllerModels/UserControllerModel.cs index 58147a9a..18c3c6dd 100644 --- a/Iceshrimp.Frontend/Core/ControllerModels/UserControllerModel.cs +++ b/Iceshrimp.Frontend/Core/ControllerModels/UserControllerModel.cs @@ -27,6 +27,12 @@ internal class UserControllerModel(ApiClient api) public Task BiteUserAsync(string id) => api.CallAsync(HttpMethod.Post, $"/users/{id}/bite"); + public Task BlockUserAsync(string id) => + api.CallAsync(HttpMethod.Post, $"/users/{id}/block"); + + public Task UnblockUserAsync(string id) => + api.CallAsync(HttpMethod.Post, $"/users/{id}/unblock"); + public Task FollowUserAsync(string id) => api.CallNullableAsync(HttpMethod.Post, $"/users/{id}/follow"); public Task RefetchUserAsync(string id) => diff --git a/Iceshrimp.Frontend/Pages/ProfileView.razor b/Iceshrimp.Frontend/Pages/ProfileView.razor index 1cc9f1c7..5c06a3c5 100644 --- a/Iceshrimp.Frontend/Pages/ProfileView.razor +++ b/Iceshrimp.Frontend/Pages/ProfileView.razor @@ -80,6 +80,18 @@ @Loc["Remove follower"] } + @if (Profile != null && Profile.Relations.HasFlag(Relations.Blocking)) + { + + @Loc["Unblock"] + + } + else + { + + @Loc["Block"] + + } } @if (UserResponse.Host != null && Profile?.Url != null) { @@ -259,6 +271,50 @@ private void RemoveFromFollowers() => GlobalComponentSvc.ConfirmDialog?.Confirm(new EventCallback(this, RemoveFromFollowersAction), Loc["Remove {0} from followers?", UserResponse.DisplayName ?? UserResponse.Username], buttonText: Loc["Remove follower"]); + private void Block() => + GlobalComponentSvc.ConfirmDialog?.Confirm(new EventCallback(this, BlockCallback), Loc["Block {0}?", UserResponse.DisplayName ?? UserResponse.Username], buttonText: Loc["Block"]); + + private async Task BlockCallback(bool confirm) + { + if (!confirm) return; + + try + { + await Api.Users.BlockUserAsync(UserResponse.Id); + + await GlobalComponentSvc.NoticeDialog?.Display(Loc["Blocked {0}", UserResponse.DisplayName ?? UserResponse.Username])!; + + Profile!.Relations += (int)Relations.Blocking; + StateHasChanged(); + } + catch (ApiException e) + { + await GlobalComponentSvc.NoticeDialog?.Display(e.Response.Message ?? Loc["An unknown error occurred"], NoticeDialog.NoticeType.Error)!; + } + } + + private void Unblock() => + GlobalComponentSvc.ConfirmDialog?.Confirm(new EventCallback(this, UnblockCallback), Loc["Unblock {0}?", UserResponse.DisplayName ?? UserResponse.Username], buttonText: Loc["Unblock"]); + + private async Task UnblockCallback(bool confirm) + { + if (!confirm) return; + + try + { + await Api.Users.UnblockUserAsync(UserResponse.Id); + + await GlobalComponentSvc.NoticeDialog?.Display(Loc["Unblocked {0}", UserResponse.DisplayName ?? UserResponse.Username])!; + + Profile!.Relations -= (int)Relations.Blocking; + StateHasChanged(); + } + catch (ApiException e) + { + await GlobalComponentSvc.NoticeDialog?.Display(e.Response.Message ?? Loc["An unknown error occurred"], NoticeDialog.NoticeType.Error)!; + } + } + private void OpenOriginal() { if (Profile?.Url != null)