From b9591ab15635cdd11a134b0ae28e6ee81fe01f59 Mon Sep 17 00:00:00 2001 From: Casper Sparre Date: Fri, 20 Feb 2026 20:28:23 +0100 Subject: [PATCH] Updated to sort blocked before fetching --- Cajetan.OF-DL/Services/CajetanApiService.cs | 23 ++++++++++++++++++++ Cajetan.OF-DL/Services/ICajetanApiService.cs | 1 + Cajetan.OF-DL/Worker.cs | 2 ++ 3 files changed, 26 insertions(+) diff --git a/Cajetan.OF-DL/Services/CajetanApiService.cs b/Cajetan.OF-DL/Services/CajetanApiService.cs index fb4217a..d3511e8 100644 --- a/Cajetan.OF-DL/Services/CajetanApiService.cs +++ b/Cajetan.OF-DL/Services/CajetanApiService.cs @@ -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> GetUsersWithProgressAsync(string typeDisplay, string endpoint, string? typeParam, bool offsetByCount) { Dictionary usersOfType = await _eventHandler.WithStatusAsync( diff --git a/Cajetan.OF-DL/Services/ICajetanApiService.cs b/Cajetan.OF-DL/Services/ICajetanApiService.cs index e863580..de9d831 100644 --- a/Cajetan.OF-DL/Services/ICajetanApiService.cs +++ b/Cajetan.OF-DL/Services/ICajetanApiService.cs @@ -6,4 +6,5 @@ public interface ICajetanApiService : IApiService Task> GetUsersWithProgressAsync(string typeDisplay, string endpoint, string? typeParam, bool offsetByCount); Task> GetUsersWithUnreadMessagesAsync(); Task MarkAsUnreadAsync(string endpoint); + Task SortBlockedAsync(string endpoint, string order = "recent", string direction = "desc"); } diff --git a/Cajetan.OF-DL/Worker.cs b/Cajetan.OF-DL/Worker.cs index 3bae0fa..06a382f 100644 --- a/Cajetan.OF-DL/Worker.cs +++ b/Cajetan.OF-DL/Worker.cs @@ -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)