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)
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -69,7 +69,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase
|
||||
IsOpen = true;
|
||||
Mediator.Subscribe<ClearProfileGroupDataMessage>(this, (msg) =>
|
||||
{
|
||||
if (msg.GroupData == null || string.Equals(msg.GroupData.GID, GroupFullInfo.Group.GID, StringComparison.Ordinal))
|
||||
if (msg.GroupData == null || string.Equals(msg.GroupData.AliasOrGID, GroupFullInfo.Group.AliasOrGID, StringComparison.Ordinal))
|
||||
{
|
||||
_pfpTextureWrap?.Dispose();
|
||||
_pfpTextureWrap = null;
|
||||
@@ -87,15 +87,11 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase
|
||||
protected override void DrawInternal()
|
||||
{
|
||||
if (!_isModerator && !_isOwner) return;
|
||||
//_logger.LogInformation("Drawing Syncshell Admin UI for {group}", GroupFullInfo.GroupAliasOrGID);
|
||||
|
||||
_logger.LogTrace("Drawing Syncshell Admin UI for {group}", GroupFullInfo.GroupAliasOrGID);
|
||||
GroupFullInfo = _pairManager.Groups[GroupFullInfo.Group];
|
||||
|
||||
|
||||
if (_lastProfileGroup == null || !_lastProfileGroup.Equals(GroupFullInfo.Group) || _profileData == null || ReferenceEquals(_profileData, _lightlessProfileManager.LoadingProfileGroupData))
|
||||
{
|
||||
_profileData = _lightlessProfileManager.GetLightlessGroupProfile(GroupFullInfo.Group);
|
||||
_lastProfileGroup = GroupFullInfo.Group;
|
||||
}
|
||||
_profileData = _lightlessProfileManager.GetLightlessGroupProfile(GroupFullInfo.Group);
|
||||
|
||||
using var id = ImRaii.PushId("syncshell_admin_" + GroupFullInfo.GID);
|
||||
using (_uiSharedService.UidFont.Push())
|
||||
@@ -294,14 +290,14 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase
|
||||
}
|
||||
using var image = Image.Load<Rgba32>(fileContent);
|
||||
|
||||
if (image.Width > 256 || image.Height > 256 || (fileContent.Length > 250 * 1024))
|
||||
if (image.Width > 512 || image.Height > 512 || (fileContent.Length > 2000 * 1024))
|
||||
{
|
||||
_showFileDialogError = true;
|
||||
return;
|
||||
}
|
||||
|
||||
_showFileDialogError = false;
|
||||
await _apiController.GroupSetProfile(new GroupProfileDto(new GroupData(GroupFullInfo.Group.GID), Description: null, Tags: null, Convert.ToBase64String(fileContent)))
|
||||
await _apiController.GroupSetProfile(new GroupProfileDto(new GroupData(GroupFullInfo.Group.AliasOrGID), Description: null, Tags: null, Convert.ToBase64String(fileContent)))
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
});
|
||||
@@ -311,7 +307,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase
|
||||
ImGui.SameLine();
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Clear uploaded profile picture"))
|
||||
{
|
||||
_ = _apiController.GroupSetProfile(new GroupProfileDto(new GroupData(GroupFullInfo.Group.GID), Description: null, Tags: null, PictureBase64: null));
|
||||
_ = _apiController.GroupSetProfile(new GroupProfileDto(new GroupData(GroupFullInfo.Group.AliasOrGID), Description: null, Tags: null, PictureBase64: null));
|
||||
}
|
||||
UiSharedService.AttachToolTip("Clear your currently uploaded profile picture");
|
||||
if (_showFileDialogError)
|
||||
@@ -356,13 +352,13 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase
|
||||
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Save, "Save Description"))
|
||||
{
|
||||
_ = _apiController.GroupSetProfile(new GroupProfileDto(new GroupData(GroupFullInfo.Group.GID), Description: _descriptionText, Tags: null, PictureBase64: null));
|
||||
_ = _apiController.GroupSetProfile(new GroupProfileDto(new GroupData(GroupFullInfo.Group.AliasOrGID), Description: _descriptionText, Tags: null, PictureBase64: null));
|
||||
}
|
||||
UiSharedService.AttachToolTip("Sets your profile description text");
|
||||
ImGui.SameLine();
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Clear Description"))
|
||||
{
|
||||
_ = _apiController.GroupSetProfile(new GroupProfileDto(new GroupData(GroupFullInfo.Group.GID), Description: null, Tags: null, PictureBase64: null));
|
||||
_ = _apiController.GroupSetProfile(new GroupProfileDto(new GroupData(GroupFullInfo.Group.AliasOrGID), Description: null, Tags: null, PictureBase64: null));
|
||||
}
|
||||
UiSharedService.AttachToolTip("Clears your profile description text");
|
||||
ImGui.TreePop();
|
||||
@@ -386,7 +382,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase
|
||||
{
|
||||
var tableFlags = ImGuiTableFlags.RowBg | ImGuiTableFlags.SizingStretchProp;
|
||||
if (pairs.Count > 10) tableFlags |= ImGuiTableFlags.ScrollY;
|
||||
using var table = ImRaii.Table("userList#" + GroupFullInfo.Group.GID, 3, tableFlags);
|
||||
using var table = ImRaii.Table("userList#" + GroupFullInfo.Group.AliasOrGID, 3, tableFlags);
|
||||
if (table)
|
||||
{
|
||||
ImGui.TableSetupColumn("Alias/UID/Note", ImGuiTableColumnFlags.None, 4);
|
||||
|
||||
Reference in New Issue
Block a user