Added more documentation, fixed some small issues with cache
This commit is contained in:
@@ -19,7 +19,7 @@ public class LightlessProfileManager : MediatorSubscriberBase
|
||||
private const string _noUserDescription = "-- User has no description set --";
|
||||
private const string _noGroupDescription = "-- Syncshell has no description set --";
|
||||
private const string _noTags = "-- Syncshell has no tags set --";
|
||||
private const string _nsfw = "Profile not displayed - NSFW";
|
||||
private const string _nsfwDescription = "Profile not displayed - NSFW";
|
||||
private readonly ApiController _apiController;
|
||||
private readonly ILogger<LightlessProfileManager> _logger;
|
||||
private readonly LightlessConfigService _lightlessConfigService;
|
||||
@@ -30,7 +30,7 @@ public class LightlessProfileManager : MediatorSubscriberBase
|
||||
private readonly LightlessUserProfileData _loadingProfileUserData = new(IsFlagged: false, IsNSFW: false, _lightlessLogoLoading, string.Empty, "Loading User Profile Data from server...");
|
||||
private readonly LightlessGroupProfileData _loadingProfileGroupData = new(_lightlessLogoLoading, "Loading Syncshell Profile Data from server...", string.Empty);
|
||||
private readonly LightlessGroupProfileData _defaultProfileGroupData = new(_lightlessLogo, _noGroupDescription, string.Empty);
|
||||
private readonly LightlessUserProfileData _nsfwProfileUserData = new(IsFlagged: false, IsNSFW: false, _lightlessLogoNsfw, string.Empty, _nsfw);
|
||||
private readonly LightlessUserProfileData _nsfwProfileUserData = new(IsFlagged: false, IsNSFW: false, _lightlessLogoNsfw, string.Empty, _nsfwDescription);
|
||||
|
||||
|
||||
public LightlessProfileManager(ILogger<LightlessProfileManager> logger, LightlessConfigService lightlessConfigService,
|
||||
@@ -43,32 +43,51 @@ public class LightlessProfileManager : MediatorSubscriberBase
|
||||
Mediator.Subscribe<ClearProfileUserDataMessage>(this, (msg) =>
|
||||
{
|
||||
if (msg.UserData != null)
|
||||
{
|
||||
_logger.LogTrace("Received Clear Profile for User profile {data}", msg.UserData.AliasOrUID);
|
||||
_lightlessUserProfiles.Remove(msg.UserData, out _);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogTrace("Received Clear Profile for all User profiles");
|
||||
_lightlessUserProfiles.Clear();
|
||||
}
|
||||
});
|
||||
|
||||
Mediator.Subscribe<ClearProfileGroupDataMessage>(this, (msg) =>
|
||||
{
|
||||
if (msg.GroupData != null)
|
||||
{
|
||||
_logger.LogTrace("Received Clear Profile for Group profile {data}", msg.GroupData.AliasOrGID);
|
||||
_lightlessGroupProfiles.Remove(msg.GroupData, out _);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogTrace("Received Clear Profile for all Group profiles");
|
||||
_lightlessGroupProfiles.Clear();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Mediator.Subscribe<DisconnectedMessage>(this, (_) =>
|
||||
{
|
||||
_logger.LogTrace("Received Disconnect, Clearing Profiles");
|
||||
_lightlessUserProfiles.Clear();
|
||||
_lightlessGroupProfiles.Clear();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches User Profile from cache or API
|
||||
/// </summary>
|
||||
/// <param name="data">User Data of given user</param>
|
||||
/// <returns>LightlessUserProfileData of given user</returns>
|
||||
public LightlessUserProfileData GetLightlessUserProfile(UserData data)
|
||||
{
|
||||
if (!_lightlessUserProfiles.TryGetValue(data, out var profile))
|
||||
{
|
||||
_logger.LogInformation($"Getting data from {data.AliasOrUID}");
|
||||
_logger.LogTrace("Requesting User profile for {data}", data);
|
||||
_ = Task.Run(() => GetLightlessProfileFromService(data));
|
||||
return (_loadingProfileUserData);
|
||||
}
|
||||
@@ -77,13 +96,16 @@ public class LightlessProfileManager : MediatorSubscriberBase
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Fetches Group Profile from cache or API
|
||||
/// </summary>
|
||||
/// <param name="data">Group Data of given group</param>
|
||||
/// <returns>LightlessGroupProfileData of given group</returns>
|
||||
public LightlessGroupProfileData GetLightlessGroupProfile(GroupData data)
|
||||
{
|
||||
_logger.LogInformation("Requesting group profile for {data}", data);
|
||||
_logger.LogInformation("Dis in cache? {}", _lightlessGroupProfiles.TryGetValue(data, out var test));
|
||||
if (!_lightlessGroupProfiles.TryGetValue(data, out var profile))
|
||||
{
|
||||
_logger.LogInformation($"Getting data from {data.GID}");
|
||||
_logger.LogTrace("Requesting group profile for {data}", data);
|
||||
_ = Task.Run(() => GetLightlessProfileFromService(data));
|
||||
return (_loadingProfileGroupData);
|
||||
}
|
||||
@@ -100,6 +122,7 @@ public class LightlessProfileManager : MediatorSubscriberBase
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogTrace("Inputting loading data in _lightlessUserProfiles for User {data}", data.AliasOrUID);
|
||||
_lightlessUserProfiles[data] = _loadingProfileUserData;
|
||||
var profile = await _apiController.UserGetProfile(new API.Dto.User.UserDto(data)).ConfigureAwait(false);
|
||||
|
||||
@@ -108,6 +131,7 @@ public class LightlessProfileManager : MediatorSubscriberBase
|
||||
!string.IsNullOrEmpty(data.Alias) && !string.Equals(data.Alias, data.UID, StringComparison.Ordinal) ? _lightlessSupporter : string.Empty,
|
||||
string.IsNullOrEmpty(profile.Description) ? _noUserDescription : profile.Description);
|
||||
|
||||
_logger.LogTrace("Replacing data in _lightlessUserProfiles for User {data}", data.AliasOrUID);
|
||||
if (profileUserData.IsNSFW && !_lightlessConfigService.Current.ProfilesAllowNsfw && !string.Equals(_apiController.UID, data.UID, StringComparison.Ordinal))
|
||||
{
|
||||
_lightlessUserProfiles[data] = _nsfwProfileUserData;
|
||||
@@ -134,6 +158,7 @@ public class LightlessProfileManager : MediatorSubscriberBase
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogTrace("Inputting loading data in _lightlessGroupProfiles for Group {data}", data.AliasOrGID);
|
||||
_lightlessGroupProfiles[data] = _loadingProfileGroupData;
|
||||
var profile = await _apiController.GroupGetProfile(new API.Dto.Group.GroupDto(data)).ConfigureAwait(false);
|
||||
|
||||
@@ -141,6 +166,7 @@ public class LightlessProfileManager : MediatorSubscriberBase
|
||||
Description: string.IsNullOrEmpty(profile.Description) ? _noGroupDescription : profile.Description,
|
||||
Tags: string.IsNullOrEmpty(profile.Tags) ? _noTags : profile.Tags);
|
||||
|
||||
_logger.LogTrace("Replacing data in _lightlessGroupProfiles for Group {data}", data.AliasOrGID);
|
||||
_lightlessGroupProfiles[data] = profileGroupData;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user