Compare commits

..

13 Commits

4 changed files with 32 additions and 3 deletions

View File

@ -52,6 +52,29 @@ public class CajetanApiService(IAuthService authService, IConfigService configSe
return null;
}
public async Task SortBlockedAsync(string endpoint, string order = "recent", string direction = "desc")
{
Log.Debug($"Calling SortBlocked - {endpoint}");
try
{
var reqBody = new { order, direction };
var result = new { success = false, canAddFriends = false };
string? body = await BuildHeaderAndExecuteRequests([], endpoint, GetHttpClient(), HttpMethod.Post, reqBody);
if (!string.IsNullOrWhiteSpace(body))
result = JsonConvert.DeserializeAnonymousType(body, result);
if (result?.success != true)
_eventHandler.OnMessage($"Failed to sort blocked (order: {order}, direction; {direction})! Endpoint: {endpoint}", "yellow");
}
catch (Exception ex)
{
ExceptionLoggerHelper.LogException(ex);
}
}
public async Task<Dictionary<string, long>> GetUsersWithProgressAsync(string typeDisplay, string endpoint, string? typeParam, bool offsetByCount)
{
Dictionary<string, long> usersOfType = await _eventHandler.WithStatusAsync(

View File

@ -6,4 +6,5 @@ public interface ICajetanApiService : IApiService
Task<Dictionary<string, long>> GetUsersWithProgressAsync(string typeDisplay, string endpoint, string? typeParam, bool offsetByCount);
Task<HashSet<long>> GetUsersWithUnreadMessagesAsync();
Task MarkAsUnreadAsync(string endpoint);
Task SortBlockedAsync(string endpoint, string order = "recent", string direction = "desc");
}

View File

@ -228,7 +228,9 @@ internal class Worker(IServiceProvider serviceProvider)
const string OUTPUT_FILE_BLOCKED = "blocked-users.json";
const string OUTPUT_FILE_EXPIRED = "expired-users.json";
await _apiService.SortBlockedAsync("/lists/blocked/sort");
await GetUsersAsync("Blocked", "/users/blocked", OUTPUT_FILE_BLOCKED);
await GetUsersAsync("Expired", "/subscriptions/subscribes", OUTPUT_FILE_EXPIRED, typeParam: "expired", offsetByCount: false);
async Task GetUsersAsync(string typeDisplay, string uri, string outputFile, string? typeParam = null, bool offsetByCount = true)

View File

@ -2773,11 +2773,11 @@ public class ApiService(IAuthService authService, IConfigService configService,
protected async Task<string?> BuildHeaderAndExecuteRequests(Dictionary<string, string> getParams, string endpoint,
HttpClient client, HttpMethod? method = null)
HttpClient client, HttpMethod? method = null, object? reqBody = null)
{
Log.Debug("Calling BuildHeaderAndExecuteRequests");
HttpRequestMessage request = await BuildHttpRequestMessage(getParams, endpoint, method);
HttpRequestMessage request = await BuildHttpRequestMessage(getParams, endpoint, method, reqBody);
using HttpResponseMessage response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
string body = await response.Content.ReadAsStringAsync();
@ -2789,7 +2789,7 @@ public class ApiService(IAuthService authService, IConfigService configService,
protected Task<HttpRequestMessage> BuildHttpRequestMessage(Dictionary<string, string> getParams,
string endpoint, HttpMethod? method = null)
string endpoint, HttpMethod? method = null, object? reqBody = null)
{
Log.Debug("Calling BuildHttpRequestMessage");
@ -2802,6 +2802,9 @@ public class ApiService(IAuthService authService, IConfigService configService,
HttpRequestMessage request = new(method ?? HttpMethod.Get, $"{Constants.ApiUrl}{endpoint}{queryParams}");
if ((method == HttpMethod.Post || method == HttpMethod.Put || method == HttpMethod.Patch) && reqBody != null)
request.Content = new StringContent(JsonConvert.SerializeObject(reqBody, s_mJsonSerializerSettings), Encoding.UTF8, "application/json");
Log.Debug($"Full request URL: {Constants.ApiUrl}{endpoint}{queryParams}");
foreach (KeyValuePair<string, string> keyValuePair in headers)