diff --git a/OF DL/Helpers/APIHelper.cs b/OF DL/Helpers/APIHelper.cs index 966b2e7..d750259 100644 --- a/OF DL/Helpers/APIHelper.cs +++ b/OF DL/Helpers/APIHelper.cs @@ -314,47 +314,44 @@ public class APIHelper : IAPIHelper try { Dictionary users = new(); - Subscriptions subscriptions = new(); + + int limit = 25; + int offset = 0; + + getParams["limit"] = limit.ToString(); + getParams["offset"] = offset.ToString(); Log.Debug("Calling GetAllSubscrptions"); - string? body = await BuildHeaderAndExecuteRequests(getParams, endpoint, new HttpClient()); - - subscriptions = JsonConvert.DeserializeObject(body); - if (subscriptions != null && subscriptions.hasMore) + while (true) { - getParams["offset"] = subscriptions.list.Count.ToString(); + string? body = await BuildHeaderAndExecuteRequests(getParams, endpoint, new HttpClient()); - while (true) + if (string.IsNullOrWhiteSpace(body)) + break; + + Subscriptions? subscriptions = JsonConvert.DeserializeObject(body, m_JsonSerializerSettings); + + if (subscriptions?.list is null) + break; + + foreach (Subscriptions.List item in subscriptions.list) { - Subscriptions newSubscriptions = new(); - string? loopbody = await BuildHeaderAndExecuteRequests(getParams, endpoint, new HttpClient()); + if (users.ContainsKey(item.username)) + continue; - if (!string.IsNullOrEmpty(loopbody) && (!loopbody.Contains("[]") || loopbody.Trim() != "[]")) - { - newSubscriptions = JsonConvert.DeserializeObject(loopbody, m_JsonSerializerSettings); - } - else - { - break; - } + bool isRestricted = item.isRestricted ?? false; + bool isRestrictedButAllowed = isRestricted && includeRestricted; - subscriptions.list.AddRange(newSubscriptions.list); - if (!newSubscriptions.hasMore) - { - break; - } - getParams["offset"] = subscriptions.list.Count.ToString(); + if (!isRestricted || isRestrictedButAllowed) + users.Add(item.username, item.id); } - } - foreach (Subscriptions.List subscription in subscriptions.list) - { - if ((!(subscription.isRestricted ?? false) || ((subscription.isRestricted ?? false) && includeRestricted)) - && !users.ContainsKey(subscription.username)) - { - users.Add(subscription.username, subscription.id); - } + if (!subscriptions.hasMore) + break; + + offset += limit; + getParams["offset"] = offset.ToString(); } return users; @@ -377,8 +374,6 @@ public class APIHelper : IAPIHelper { Dictionary getParams = new() { - { "offset", "0" }, - { "limit", "50" }, { "type", "active" }, { "format", "infinite"} }; @@ -392,8 +387,6 @@ public class APIHelper : IAPIHelper Dictionary getParams = new() { - { "offset", "0" }, - { "limit", "50" }, { "type", "expired" }, { "format", "infinite"} };