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 _noUserDescription = "-- User has no description set --";
|
||||||
private const string _noGroupDescription = "-- Syncshell 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 _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 ApiController _apiController;
|
||||||
private readonly ILogger<LightlessProfileManager> _logger;
|
private readonly ILogger<LightlessProfileManager> _logger;
|
||||||
private readonly LightlessConfigService _lightlessConfigService;
|
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 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 _loadingProfileGroupData = new(_lightlessLogoLoading, "Loading Syncshell Profile Data from server...", string.Empty);
|
||||||
private readonly LightlessGroupProfileData _defaultProfileGroupData = new(_lightlessLogo, _noGroupDescription, 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,
|
public LightlessProfileManager(ILogger<LightlessProfileManager> logger, LightlessConfigService lightlessConfigService,
|
||||||
@@ -43,32 +43,51 @@ public class LightlessProfileManager : MediatorSubscriberBase
|
|||||||
Mediator.Subscribe<ClearProfileUserDataMessage>(this, (msg) =>
|
Mediator.Subscribe<ClearProfileUserDataMessage>(this, (msg) =>
|
||||||
{
|
{
|
||||||
if (msg.UserData != null)
|
if (msg.UserData != null)
|
||||||
|
{
|
||||||
|
_logger.LogTrace("Received Clear Profile for User profile {data}", msg.UserData.AliasOrUID);
|
||||||
_lightlessUserProfiles.Remove(msg.UserData, out _);
|
_lightlessUserProfiles.Remove(msg.UserData, out _);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
_logger.LogTrace("Received Clear Profile for all User profiles");
|
||||||
_lightlessUserProfiles.Clear();
|
_lightlessUserProfiles.Clear();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Mediator.Subscribe<ClearProfileGroupDataMessage>(this, (msg) =>
|
Mediator.Subscribe<ClearProfileGroupDataMessage>(this, (msg) =>
|
||||||
{
|
{
|
||||||
if (msg.GroupData != null)
|
if (msg.GroupData != null)
|
||||||
|
{
|
||||||
|
_logger.LogTrace("Received Clear Profile for Group profile {data}", msg.GroupData.AliasOrGID);
|
||||||
_lightlessGroupProfiles.Remove(msg.GroupData, out _);
|
_lightlessGroupProfiles.Remove(msg.GroupData, out _);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
_logger.LogTrace("Received Clear Profile for all Group profiles");
|
||||||
_lightlessGroupProfiles.Clear();
|
_lightlessGroupProfiles.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Mediator.Subscribe<DisconnectedMessage>(this, (_) =>
|
Mediator.Subscribe<DisconnectedMessage>(this, (_) =>
|
||||||
{
|
{
|
||||||
|
_logger.LogTrace("Received Disconnect, Clearing Profiles");
|
||||||
_lightlessUserProfiles.Clear();
|
_lightlessUserProfiles.Clear();
|
||||||
_lightlessGroupProfiles.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)
|
public LightlessUserProfileData GetLightlessUserProfile(UserData data)
|
||||||
{
|
{
|
||||||
if (!_lightlessUserProfiles.TryGetValue(data, out var profile))
|
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));
|
_ = Task.Run(() => GetLightlessProfileFromService(data));
|
||||||
return (_loadingProfileUserData);
|
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)
|
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))
|
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));
|
_ = Task.Run(() => GetLightlessProfileFromService(data));
|
||||||
return (_loadingProfileGroupData);
|
return (_loadingProfileGroupData);
|
||||||
}
|
}
|
||||||
@@ -100,6 +122,7 @@ public class LightlessProfileManager : MediatorSubscriberBase
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
_logger.LogTrace("Inputting loading data in _lightlessUserProfiles for User {data}", data.AliasOrUID);
|
||||||
_lightlessUserProfiles[data] = _loadingProfileUserData;
|
_lightlessUserProfiles[data] = _loadingProfileUserData;
|
||||||
var profile = await _apiController.UserGetProfile(new API.Dto.User.UserDto(data)).ConfigureAwait(false);
|
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(data.Alias) && !string.Equals(data.Alias, data.UID, StringComparison.Ordinal) ? _lightlessSupporter : string.Empty,
|
||||||
string.IsNullOrEmpty(profile.Description) ? _noUserDescription : profile.Description);
|
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))
|
if (profileUserData.IsNSFW && !_lightlessConfigService.Current.ProfilesAllowNsfw && !string.Equals(_apiController.UID, data.UID, StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
_lightlessUserProfiles[data] = _nsfwProfileUserData;
|
_lightlessUserProfiles[data] = _nsfwProfileUserData;
|
||||||
@@ -134,6 +158,7 @@ public class LightlessProfileManager : MediatorSubscriberBase
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
_logger.LogTrace("Inputting loading data in _lightlessGroupProfiles for Group {data}", data.AliasOrGID);
|
||||||
_lightlessGroupProfiles[data] = _loadingProfileGroupData;
|
_lightlessGroupProfiles[data] = _loadingProfileGroupData;
|
||||||
var profile = await _apiController.GroupGetProfile(new API.Dto.Group.GroupDto(data)).ConfigureAwait(false);
|
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,
|
Description: string.IsNullOrEmpty(profile.Description) ? _noGroupDescription : profile.Description,
|
||||||
Tags: string.IsNullOrEmpty(profile.Tags) ? _noTags : profile.Tags);
|
Tags: string.IsNullOrEmpty(profile.Tags) ? _noTags : profile.Tags);
|
||||||
|
|
||||||
|
_logger.LogTrace("Replacing data in _lightlessGroupProfiles for Group {data}", data.AliasOrGID);
|
||||||
_lightlessGroupProfiles[data] = profileGroupData;
|
_lightlessGroupProfiles[data] = profileGroupData;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -69,7 +69,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase
|
|||||||
IsOpen = true;
|
IsOpen = true;
|
||||||
Mediator.Subscribe<ClearProfileGroupDataMessage>(this, (msg) =>
|
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?.Dispose();
|
||||||
_pfpTextureWrap = null;
|
_pfpTextureWrap = null;
|
||||||
@@ -87,15 +87,11 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase
|
|||||||
protected override void DrawInternal()
|
protected override void DrawInternal()
|
||||||
{
|
{
|
||||||
if (!_isModerator && !_isOwner) return;
|
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];
|
GroupFullInfo = _pairManager.Groups[GroupFullInfo.Group];
|
||||||
|
|
||||||
|
_profileData = _lightlessProfileManager.GetLightlessGroupProfile(GroupFullInfo.Group);
|
||||||
if (_lastProfileGroup == null || !_lastProfileGroup.Equals(GroupFullInfo.Group) || _profileData == null || ReferenceEquals(_profileData, _lightlessProfileManager.LoadingProfileGroupData))
|
|
||||||
{
|
|
||||||
_profileData = _lightlessProfileManager.GetLightlessGroupProfile(GroupFullInfo.Group);
|
|
||||||
_lastProfileGroup = GroupFullInfo.Group;
|
|
||||||
}
|
|
||||||
|
|
||||||
using var id = ImRaii.PushId("syncshell_admin_" + GroupFullInfo.GID);
|
using var id = ImRaii.PushId("syncshell_admin_" + GroupFullInfo.GID);
|
||||||
using (_uiSharedService.UidFont.Push())
|
using (_uiSharedService.UidFont.Push())
|
||||||
@@ -294,14 +290,14 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase
|
|||||||
}
|
}
|
||||||
using var image = Image.Load<Rgba32>(fileContent);
|
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;
|
_showFileDialogError = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_showFileDialogError = false;
|
_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);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -311,7 +307,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase
|
|||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Clear uploaded profile picture"))
|
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");
|
UiSharedService.AttachToolTip("Clear your currently uploaded profile picture");
|
||||||
if (_showFileDialogError)
|
if (_showFileDialogError)
|
||||||
@@ -356,13 +352,13 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase
|
|||||||
|
|
||||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Save, "Save Description"))
|
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");
|
UiSharedService.AttachToolTip("Sets your profile description text");
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Clear Description"))
|
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");
|
UiSharedService.AttachToolTip("Clears your profile description text");
|
||||||
ImGui.TreePop();
|
ImGui.TreePop();
|
||||||
@@ -386,7 +382,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase
|
|||||||
{
|
{
|
||||||
var tableFlags = ImGuiTableFlags.RowBg | ImGuiTableFlags.SizingStretchProp;
|
var tableFlags = ImGuiTableFlags.RowBg | ImGuiTableFlags.SizingStretchProp;
|
||||||
if (pairs.Count > 10) tableFlags |= ImGuiTableFlags.ScrollY;
|
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)
|
if (table)
|
||||||
{
|
{
|
||||||
ImGui.TableSetupColumn("Alias/UID/Note", ImGuiTableColumnFlags.None, 4);
|
ImGui.TableSetupColumn("Alias/UID/Note", ImGuiTableColumnFlags.None, 4);
|
||||||
|
|||||||
Reference in New Issue
Block a user