forked from sim0n00ps/OF-DL
Compare commits
1 Commits
0f479a0268
...
f421bf128f
| Author | SHA1 | Date | |
|---|---|---|---|
| f421bf128f |
@ -13,6 +13,6 @@ global using Serilog.Context;
|
|||||||
global using Spectre.Console;
|
global using Spectre.Console;
|
||||||
global using MessageDtos = OF_DL.Models.Dtos.Messages;
|
global using MessageDtos = OF_DL.Models.Dtos.Messages;
|
||||||
global using MessageEntities = OF_DL.Models.Entities.Messages;
|
global using MessageEntities = OF_DL.Models.Entities.Messages;
|
||||||
global using SubscriptionDtos = OF_DL.Models.Dtos.Subscriptions;
|
global using SubscriptionsDtos = OF_DL.Models.Dtos.Subscriptions;
|
||||||
global using UserDtos = OF_DL.Models.Dtos.Users;
|
global using UserDtos = OF_DL.Models.Dtos.Users;
|
||||||
global using UserEntities = OF_DL.Models.Entities.Users;
|
global using UserEntities = OF_DL.Models.Entities.Users;
|
||||||
|
|||||||
@ -15,6 +15,18 @@ public class CajetanApiService(IAuthService authService, IConfigService configSe
|
|||||||
return userInfo;
|
return userInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public new Task<Dictionary<string, long>?> GetActiveSubscriptions(string endpoint, bool includeRestricted)
|
||||||
|
{
|
||||||
|
Log.Debug("Calling GetActiveSubscriptions");
|
||||||
|
return GetAllSubscriptions(endpoint, includeRestricted, "active");
|
||||||
|
}
|
||||||
|
|
||||||
|
public new Task<Dictionary<string, long>?> GetExpiredSubscriptions(string endpoint, bool includeRestricted)
|
||||||
|
{
|
||||||
|
Log.Debug("Calling GetExpiredSubscriptions");
|
||||||
|
return GetAllSubscriptions(endpoint, includeRestricted, "expired");
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<UserEntities.UserInfo?> GetDetailedUserInfoAsync(string endpoint)
|
public async Task<UserEntities.UserInfo?> GetDetailedUserInfoAsync(string endpoint)
|
||||||
{
|
{
|
||||||
Log.Debug($"Calling GetDetailedUserInfo: {endpoint}");
|
Log.Debug($"Calling GetDetailedUserInfo: {endpoint}");
|
||||||
@ -116,12 +128,12 @@ public class CajetanApiService(IAuthService authService, IConfigService configSe
|
|||||||
if (string.IsNullOrWhiteSpace(body))
|
if (string.IsNullOrWhiteSpace(body))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
SubscriptionDtos.SubscriptionsDto? subscriptions = DeserializeJson<SubscriptionDtos.SubscriptionsDto>(body, s_mJsonSerializerSettings);
|
SubscriptionsDtos.SubscriptionsDto? subscriptions = DeserializeJson<SubscriptionsDtos.SubscriptionsDto>(body, s_mJsonSerializerSettings);
|
||||||
|
|
||||||
if (subscriptions?.List is null)
|
if (subscriptions?.List is null)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
foreach (SubscriptionDtos.ListItemDto item in subscriptions.List)
|
foreach (SubscriptionsDtos.ListItemDto item in subscriptions.List)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(item?.Username))
|
if (string.IsNullOrWhiteSpace(item?.Username))
|
||||||
continue;
|
continue;
|
||||||
@ -232,6 +244,75 @@ public class CajetanApiService(IAuthService authService, IConfigService configSe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<Dictionary<string, long>?> GetAllSubscriptions(string endpoint, bool includeRestricted, string type)
|
||||||
|
{
|
||||||
|
if (!HasSignedRequestAuth())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Dictionary<string, long> users = new(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
Log.Debug("Calling GetAllSubscrptions");
|
||||||
|
|
||||||
|
const int limit = 25;
|
||||||
|
int offset = 0;
|
||||||
|
|
||||||
|
Dictionary<string, string> getParams = new()
|
||||||
|
{
|
||||||
|
["type"] = type,
|
||||||
|
["format"] = "infinite",
|
||||||
|
["limit"] = limit.ToString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
getParams["offset"] = offset.ToString();
|
||||||
|
|
||||||
|
string? body = await BuildHeaderAndExecuteRequests(getParams, endpoint, new HttpClient());
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(body))
|
||||||
|
break;
|
||||||
|
|
||||||
|
SubscriptionsDtos.SubscriptionsDto? subscriptionsDto = DeserializeJson<SubscriptionsDtos.SubscriptionsDto>(body, s_mJsonSerializerSettings);
|
||||||
|
|
||||||
|
if (subscriptionsDto?.List is null)
|
||||||
|
break;
|
||||||
|
|
||||||
|
foreach (SubscriptionsDtos.ListItemDto item in subscriptionsDto.List)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(item.Username))
|
||||||
|
{
|
||||||
|
Log.Warning("Found '{Type:l}' subscription user with empty username (id: {Id})", type, item.Id);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (users.ContainsKey(item.Username))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
bool isRestricted = item.IsRestricted ?? false;
|
||||||
|
bool isRestrictedButAllowed = isRestricted && includeRestricted;
|
||||||
|
|
||||||
|
if (!isRestricted || isRestrictedButAllowed)
|
||||||
|
users.Add(item.Username, item.Id);
|
||||||
|
|
||||||
|
if (subscriptionsDto.HasMore is false)
|
||||||
|
break;
|
||||||
|
|
||||||
|
offset += limit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
ExceptionLoggerHelper.LogException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private async Task<MessageDtos.ChatsDto> GetChatsAsync(string endpoint, bool onlyUnread)
|
private async Task<MessageDtos.ChatsDto> GetChatsAsync(string endpoint, bool onlyUnread)
|
||||||
{
|
{
|
||||||
Log.Debug($"Calling GetChats - {endpoint}");
|
Log.Debug($"Calling GetChats - {endpoint}");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user