[frontend/pages] Add mute and unmute actions to profile page

This commit is contained in:
pancakes 2025-02-23 16:28:32 +10:00 committed by Laura Hausmann
parent 00e0a958b5
commit 97679c275b
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 65 additions and 0 deletions

View file

@ -35,6 +35,15 @@ internal class UserControllerModel(ApiClient api)
public Task<bool> FollowUserAsync(string id) => api.CallNullableAsync(HttpMethod.Post, $"/users/{id}/follow"); public Task<bool> FollowUserAsync(string id) => api.CallNullableAsync(HttpMethod.Post, $"/users/{id}/follow");
public Task MuteUserAsync(string id, DateTime? expires) =>
api.CallAsync(HttpMethod.Post, $"/users/{id}/mute",
expires != null
? QueryString.Create("expires", expires.Value.ToUniversalTime().ToString("O"))
: QueryString.Empty);
public Task UnmuteUserAsync(string id) =>
api.CallAsync(HttpMethod.Post, $"/users/{id}/unmute");
public Task<UserResponse?> RefetchUserAsync(string id) => public Task<UserResponse?> RefetchUserAsync(string id) =>
api.CallNullableAsync<UserResponse>(HttpMethod.Post, $"/users/{id}/refetch"); api.CallNullableAsync<UserResponse>(HttpMethod.Post, $"/users/{id}/refetch");

View file

@ -80,6 +80,18 @@
<Text>@Loc["Remove follower"]</Text> <Text>@Loc["Remove follower"]</Text>
</MenuElement> </MenuElement>
} }
@if (Profile != null && Profile.Relations.HasFlag(Relations.Muting))
{
<MenuElement Icon="Icons.Eye" OnSelect="Unmute">
<Text>@Loc["Unmute"]</Text>
</MenuElement>
}
else
{
<MenuElement Icon="Icons.EyeSlash" OnSelect="Mute">
<Text>@Loc["Mute"]</Text>
</MenuElement>
}
@if (Profile != null && Profile.Relations.HasFlag(Relations.Blocking)) @if (Profile != null && Profile.Relations.HasFlag(Relations.Blocking))
{ {
<MenuElement Icon="Icons.Prohibit" OnSelect="Unblock"> <MenuElement Icon="Icons.Prohibit" OnSelect="Unblock">
@ -271,6 +283,50 @@
private void RemoveFromFollowers() => private void RemoveFromFollowers() =>
GlobalComponentSvc.ConfirmDialog?.Confirm(new EventCallback<bool>(this, RemoveFromFollowersAction), Loc["Remove {0} from followers?", UserResponse.DisplayName ?? UserResponse.Username], buttonText: Loc["Remove follower"]); GlobalComponentSvc.ConfirmDialog?.Confirm(new EventCallback<bool>(this, RemoveFromFollowersAction), Loc["Remove {0} from followers?", UserResponse.DisplayName ?? UserResponse.Username], buttonText: Loc["Remove follower"]);
private void Mute() =>
GlobalComponentSvc.ConfirmDialog?.Confirm(new EventCallback<bool>(this, MuteCallback), Loc["Mute {0}?", UserResponse.DisplayName ?? UserResponse.Username], buttonText: Loc["Block"]);
private async Task MuteCallback(bool confirm)
{
if (!confirm) return;
try
{
await Api.Users.MuteUserAsync(UserResponse.Id, null);
await GlobalComponentSvc.NoticeDialog?.Display(Loc["Muted {0}", UserResponse.DisplayName ?? UserResponse.Username])!;
Profile!.Relations += (int)Relations.Muting;
StateHasChanged();
}
catch (ApiException e)
{
await GlobalComponentSvc.NoticeDialog?.Display(e.Response.Message ?? Loc["An unknown error occurred"], NoticeDialog.NoticeType.Error)!;
}
}
private void Unmute() =>
GlobalComponentSvc.ConfirmDialog?.Confirm(new EventCallback<bool>(this, UnmuteCallback), Loc["Unmute {0}?", UserResponse.DisplayName ?? UserResponse.Username], buttonText: Loc["Unblock"]);
private async Task UnmuteCallback(bool confirm)
{
if (!confirm) return;
try
{
await Api.Users.UnmuteUserAsync(UserResponse.Id);
await GlobalComponentSvc.NoticeDialog?.Display(Loc["Unmuted {0}", UserResponse.DisplayName ?? UserResponse.Username])!;
Profile!.Relations -= (int)Relations.Muting;
StateHasChanged();
}
catch (ApiException e)
{
await GlobalComponentSvc.NoticeDialog?.Display(e.Response.Message ?? Loc["An unknown error occurred"], NoticeDialog.NoticeType.Error)!;
}
}
private void Block() => private void Block() =>
GlobalComponentSvc.ConfirmDialog?.Confirm(new EventCallback<bool>(this, BlockCallback), Loc["Block {0}?", UserResponse.DisplayName ?? UserResponse.Username], buttonText: Loc["Block"]); GlobalComponentSvc.ConfirmDialog?.Confirm(new EventCallback<bool>(this, BlockCallback), Loc["Block {0}?", UserResponse.DisplayName ?? UserResponse.Username], buttonText: Loc["Block"]);