Updated to sort blocked before fetching

This commit is contained in:
Casper Sparre 2026-02-20 20:28:23 +01:00
parent c87958f248
commit b9591ab156
3 changed files with 26 additions and 0 deletions

View File

@ -52,6 +52,29 @@ public class CajetanApiService(IAuthService authService, IConfigService configSe
return null; 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) public async Task<Dictionary<string, long>> GetUsersWithProgressAsync(string typeDisplay, string endpoint, string? typeParam, bool offsetByCount)
{ {
Dictionary<string, long> usersOfType = await _eventHandler.WithStatusAsync( 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<Dictionary<string, long>> GetUsersWithProgressAsync(string typeDisplay, string endpoint, string? typeParam, bool offsetByCount);
Task<HashSet<long>> GetUsersWithUnreadMessagesAsync(); Task<HashSet<long>> GetUsersWithUnreadMessagesAsync();
Task MarkAsUnreadAsync(string endpoint); 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_BLOCKED = "blocked-users.json";
const string OUTPUT_FILE_EXPIRED = "expired-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("Blocked", "/users/blocked", OUTPUT_FILE_BLOCKED);
await GetUsersAsync("Expired", "/subscriptions/subscribes", OUTPUT_FILE_EXPIRED, typeParam: "expired", offsetByCount: false); 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) async Task GetUsersAsync(string typeDisplay, string uri, string outputFile, string? typeParam = null, bool offsetByCount = true)