Updated to read both username and userid from list users

This commit is contained in:
Casper Sparre 2026-02-21 00:28:54 +01:00
parent a1dce61b33
commit 21efebe74f
5 changed files with 73 additions and 7 deletions

View File

@ -0,0 +1,8 @@
namespace OF_DL.Models.Dtos.Lists;
public class ListUsersDto
{
[JsonProperty("list")] public List<UsersListDto> List { get; set; } = [];
[JsonProperty("hasMore")] public bool? HasMore { get; set; }
[JsonProperty("nextOffset")] public int NextOffset { get; set; }
}

View File

@ -11,6 +11,7 @@ global using OF_DL.Services;
global using Serilog;
global using Serilog.Context;
global using Spectre.Console;
global using ListsDtos = OF_DL.Models.Dtos.Lists;
global using MessageDtos = OF_DL.Models.Dtos.Messages;
global using MessageEntities = OF_DL.Models.Entities.Messages;
global using SubscriptionsDtos = OF_DL.Models.Dtos.Subscriptions;

View File

@ -27,6 +27,64 @@ public class CajetanApiService(IAuthService authService, IConfigService configSe
return GetAllSubscriptions(endpoint, includeRestricted, "expired");
}
public new async Task<Dictionary<string, long>?> GetListUsers(string endpoint)
{
if (!HasSignedRequestAuth())
return null;
try
{
Dictionary<string, long> users = new(StringComparer.OrdinalIgnoreCase);
Log.Debug($"Calling GetListUsers - {endpoint}");
const int limit = 50;
int offset = 0;
Dictionary<string, string> getParams = new()
{
["format"] = "infinite",
["limit"] = limit.ToString()
};
while (true)
{
getParams["offset"] = offset.ToString();
string? body = await BuildHeaderAndExecuteRequests(getParams, endpoint, new HttpClient());
if (string.IsNullOrWhiteSpace(body))
break;
ListsDtos.ListUsersDto? listUsers = DeserializeJson<ListsDtos.ListUsersDto>(body, s_mJsonSerializerSettings);
if (listUsers?.List is null)
break;
foreach (ListsDtos.UsersListDto item in listUsers.List)
{
if (item.Id is null)
continue;
users.TryAdd(item.Username, item.Id.Value);
}
if (listUsers.HasMore is false)
break;
offset = listUsers.NextOffset;
}
return users;
}
catch (Exception ex)
{
ExceptionLoggerHelper.LogException(ex);
}
return null;
}
public async Task<UserEntities.UserInfo?> GetDetailedUserInfoAsync(string endpoint)
{
Log.Debug($"Calling GetDetailedUserInfo: {endpoint}");

View File

@ -2,6 +2,8 @@ namespace OF_DL.Services;
public interface ICajetanApiService : IApiService
{
new Task<Dictionary<string, long>?> GetListUsers(string endpoint);
Task<UserEntities.UserInfo?> GetDetailedUserInfoAsync(string endpoint);
Task<Dictionary<string, long>> GetUsersWithProgressAsync(string typeDisplay, string endpoint, string? typeParam, bool offsetByCount);
Task<HashSet<long>> GetUsersWithUnreadMessagesAsync();

View File

@ -332,17 +332,14 @@ internal class Worker(IServiceProvider serviceProvider)
Log.Information("Getting Users from list '{ListName:l}' (Include Restricted: {IncludeRestrictedSubscriptions})", name, currentConfig.IncludeRestrictedSubscriptions);
AnsiConsole.MarkupLine($"[green]Getting Users from list '{name}' (Include Restricted: {currentConfig.IncludeRestrictedSubscriptions})[/]");
List<string> listUsernames = await _apiService.GetListUsers($"/lists/{listId}/users") ?? [];
Dictionary<string, long> listUsernames = await _apiService.GetListUsers($"/lists/{listId}/users") ?? [];
foreach (string u in listUsernames)
foreach ((string username, long userId) in listUsernames)
{
if (usersFromLists.ContainsKey(u))
if (usersFromLists.ContainsKey(username))
continue;
if (!allUsersAndLists.Users.TryGetValue(u, out long userId))
continue;
usersFromLists[u] = userId;
usersFromLists[username] = userId;
}
}