From 96aaebd72d4a8fbf2889a78ae20df309babb7d63 Mon Sep 17 00:00:00 2001 From: Casper Sparre Date: Sat, 21 Feb 2026 00:31:19 +0100 Subject: [PATCH] Reordered methods in CajetanApiService --- Cajetan.OF-DL/Services/CajetanApiService.cs | 108 ++++++++++---------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/Cajetan.OF-DL/Services/CajetanApiService.cs b/Cajetan.OF-DL/Services/CajetanApiService.cs index 832caeb..fcc5d5f 100644 --- a/Cajetan.OF-DL/Services/CajetanApiService.cs +++ b/Cajetan.OF-DL/Services/CajetanApiService.cs @@ -27,6 +27,37 @@ public class CajetanApiService(IAuthService authService, IConfigService configSe return GetAllSubscriptions(endpoint, includeRestricted, "expired"); } + public new async Task GetMessages(string endpoint, string folder, IStatusReporter statusReporter) + { + (bool couldExtract, long userId) = ExtractUserId(endpoint); + + _eventHandler.OnMessage("Getting Unread Chats", "grey"); + HashSet usersWithUnread = couldExtract ? await GetUsersWithUnreadMessagesAsync() : []; + + MessageEntities.MessageCollection messages = await base.GetMessages(endpoint, folder, statusReporter); + + if (usersWithUnread.Contains(userId)) + { + _eventHandler.OnMessage("Restoring unread state", "grey"); + await MarkAsUnreadAsync($"/chats/{userId}/mark-as-read"); + } + + return messages; + + static (bool couldExtract, long userId) ExtractUserId(string endpoint) + { + string withoutChatsAndMessages = endpoint + .Replace("chats", "", StringComparison.OrdinalIgnoreCase) + .Replace("messages", "", StringComparison.OrdinalIgnoreCase); + string trimmed = withoutChatsAndMessages.Trim(' ', '/', '\\'); + + if (long.TryParse(trimmed, out long userId)) + return (true, userId); + + return (false, default); + } + } + public new async Task?> GetListUsers(string endpoint) { if (!HasSignedRequestAuth()) @@ -122,29 +153,6 @@ 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( @@ -230,37 +238,6 @@ public class CajetanApiService(IAuthService authService, IConfigService configSe } } - public new async Task GetMessages(string endpoint, string folder, IStatusReporter statusReporter) - { - (bool couldExtract, long userId) = ExtractUserId(endpoint); - - _eventHandler.OnMessage("Getting Unread Chats", "grey"); - HashSet usersWithUnread = couldExtract ? await GetUsersWithUnreadMessagesAsync() : []; - - MessageEntities.MessageCollection messages = await base.GetMessages(endpoint, folder, statusReporter); - - if (usersWithUnread.Contains(userId)) - { - _eventHandler.OnMessage("Restoring unread state", "grey"); - await MarkAsUnreadAsync($"/chats/{userId}/mark-as-read"); - } - - return messages; - - static (bool couldExtract, long userId) ExtractUserId(string endpoint) - { - string withoutChatsAndMessages = endpoint - .Replace("chats", "", StringComparison.OrdinalIgnoreCase) - .Replace("messages", "", StringComparison.OrdinalIgnoreCase); - string trimmed = withoutChatsAndMessages.Trim(' ', '/', '\\'); - - if (long.TryParse(trimmed, out long userId)) - return (true, userId); - - return (false, default); - } - } - public async Task> GetUsersWithUnreadMessagesAsync() { MessageDtos.ChatsDto unreadChats = await GetChatsAsync("/chats", onlyUnread: true); @@ -302,6 +279,29 @@ public class CajetanApiService(IAuthService authService, IConfigService configSe } } + 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); + } + } + private async Task?> GetAllSubscriptions(string endpoint, bool includeRestricted, string type) { if (!HasSignedRequestAuth())