Redone syncshell admin ui, fixed some bugs on edit profile.

This commit is contained in:
cake
2025-12-09 05:45:19 +01:00
parent 25f0d41581
commit 675918624d
12 changed files with 684 additions and 344 deletions

View File

@@ -2,26 +2,17 @@ using Dalamud.Bindings.ImGui;
using Dalamud.Interface;
using Dalamud.Interface.Colors;
using Dalamud.Interface.Components;
using Dalamud.Interface.ImGuiFileDialog;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii;
using LightlessSync.API.Data;
using LightlessSync.API.Dto.Group;
using LightlessSync.Services;
using LightlessSync.Services.Mediator;
using LightlessSync.Services.Profiles;
using LightlessSync.UI.Tags;
using LightlessSync.Utils;
using Microsoft.Extensions.Logging;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Threading.Tasks;
namespace LightlessSync.UI;
@@ -68,6 +59,7 @@ public partial class EditProfileUi
_bannerTextureWrap = null;
_showProfileImageError = false;
_showBannerImageError = false;
_groupVisibilityInitialized = false;
}
private void DrawGroupEditor(float scale)
@@ -376,6 +368,8 @@ public partial class EditProfileUi
private void DrawGroupProfileVisibilityControls()
{
EnsureGroupVisibilityStateInitialised();
bool changedNsfw = DrawCheckboxRow("Profile is NSFW", _groupIsNsfw, out var newNsfw, "Flag this profile as not safe for work.");
if (changedNsfw)
_groupIsNsfw = newNsfw;
@@ -504,33 +498,36 @@ public partial class EditProfileUi
try
{
var fileContent = await File.ReadAllBytesAsync(filePath).ConfigureAwait(false);
await using var stream = new MemoryStream(fileContent);
var format = await Image.DetectFormatAsync(stream).ConfigureAwait(false);
if (!IsSupportedImageFormat(format))
var stream = new MemoryStream(fileContent);
await using (stream.ConfigureAwait(false))
{
_showBannerImageError = true;
return;
var format = await Image.DetectFormatAsync(stream).ConfigureAwait(false);
if (!IsSupportedImageFormat(format))
{
_showBannerImageError = true;
return;
}
using var image = Image.Load<Rgba32>(fileContent);
if (image.Width > 840 || image.Height > 260 || fileContent.Length > 2000 * 1024)
{
_showBannerImageError = true;
return;
}
await _apiController.GroupSetProfile(new GroupProfileDto(
_groupInfo.Group,
Description: null,
Tags: null,
PictureBase64: null,
BannerBase64: Convert.ToBase64String(fileContent),
IsNsfw: null,
IsDisabled: null)).ConfigureAwait(false);
_showBannerImageError = false;
_queuedBannerImage = fileContent;
Mediator.Publish(new ClearProfileGroupDataMessage(_groupInfo.Group));
}
using var image = Image.Load<Rgba32>(fileContent);
if (image.Width > 840 || image.Height > 260 || fileContent.Length > 2000 * 1024)
{
_showBannerImageError = true;
return;
}
await _apiController.GroupSetProfile(new GroupProfileDto(
_groupInfo.Group,
Description: null,
Tags: null,
PictureBase64: null,
BannerBase64: Convert.ToBase64String(fileContent),
IsNsfw: null,
IsDisabled: null)).ConfigureAwait(false);
_showBannerImageError = false;
_queuedBannerImage = fileContent;
Mediator.Publish(new ClearProfileGroupDataMessage(_groupInfo.Group));
}
catch (Exception ex)
{
@@ -588,6 +585,16 @@ public partial class EditProfileUi
}
}
private void EnsureGroupVisibilityStateInitialised()
{
if (_groupInfo == null || _groupVisibilityInitialized)
return;
_groupIsNsfw = _groupServerIsNsfw;
_groupIsDisabled = _groupServerIsDisabled;
_groupVisibilityInitialized = true;
}
private async Task SubmitGroupTagChanges(int[] payload)
{
if (_groupInfo is null)
@@ -695,11 +702,15 @@ public partial class EditProfileUi
}
}
_groupIsNsfw = profile.IsNsfw;
_groupIsDisabled = profile.IsDisabled;
_groupServerIsNsfw = profile.IsNsfw;
_groupServerIsDisabled = profile.IsDisabled;
}
if (!_groupVisibilityInitialized)
{
_groupIsNsfw = _groupServerIsNsfw;
_groupIsDisabled = _groupServerIsDisabled;
_groupVisibilityInitialized = true;
}
}
}