Iceshrimp.NET/Iceshrimp.Frontend/Core/ControllerModels/UserControllerModel.cs

54 lines
No EOL
2.2 KiB
C#

using Iceshrimp.Frontend.Core.Miscellaneous;
using Iceshrimp.Frontend.Core.Services;
using Iceshrimp.Shared.Schemas.Web;
namespace Iceshrimp.Frontend.Core.ControllerModels;
internal class UserControllerModel(ApiClient api)
{
public Task<UserResponse?> GetUserAsync(string id) =>
api.CallNullableAsync<UserResponse>(HttpMethod.Get, $"/users/{id}");
public Task<UserProfileResponse?> GetUserProfileAsync(string id) =>
api.CallNullableAsync<UserProfileResponse>(HttpMethod.Get, $"/users/{id}/profile");
[LinkPagination(20, 80)]
public Task<List<NoteResponse>?> GetUserNotesAsync(string id, PaginationQuery pq) =>
api.CallNullableAsync<List<NoteResponse>>(HttpMethod.Get, $"/users/{id}/notes", pq);
public Task<UserResponse?> LookupUserAsync(string username, string? host)
{
var query = new QueryString();
query = query.Add("username", username);
if (host != null) query = query.Add("host", host);
return api.CallNullableAsync<UserResponse>(HttpMethod.Get, "/users/lookup", query);
}
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<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) =>
api.CallNullableAsync<UserResponse>(HttpMethod.Post, $"/users/{id}/refetch");
public Task<bool> RemoveUserFromFollowersAsync(string id) =>
api.CallNullableAsync(HttpMethod.Post, $"/users/{id}/remove_from_followers");
public Task<bool> UnfollowUserAsync(string id) => api.CallNullableAsync(HttpMethod.Post, $"/users/{id}/unfollow");
}