Compare commits

..

2 Commits

Author SHA1 Message Date
cake
6bff57e8da Added null parameter 2025-10-26 18:57:44 +01:00
cake
3a9446f9ae Fixed update on image 2025-10-26 18:57:22 +01:00
5 changed files with 30 additions and 35 deletions

View File

@@ -211,8 +211,7 @@ public partial class LightlessHub
if (isOwnerResult.ReferredGroup == null) return (false, null); if (isOwnerResult.ReferredGroup == null) return (false, null);
var groupPairSelf = await DbContext.GroupPairs.SingleOrDefaultAsync( var groupPairSelf = await DbContext.GroupPairs.SingleOrDefaultAsync(g => g.GroupGID == gid || g.Group.Alias == gid && g.GroupUserUID == UserUID).ConfigureAwait(false);
g => (g.GroupGID == gid || g.Group.Alias == gid) && g.GroupUserUID == UserUID).ConfigureAwait(false);
if (groupPairSelf == null || !groupPairSelf.IsModerator) return (false, null); if (groupPairSelf == null || !groupPairSelf.IsModerator) return (false, null);
return (true, isOwnerResult.ReferredGroup); return (true, isOwnerResult.ReferredGroup);

View File

@@ -799,8 +799,8 @@ public partial class LightlessHub
if (!hasRights) return; if (!hasRights) return;
var groupProfileDb = await DbContext.GroupProfiles var groupProfileDb = await DbContext.GroupProfiles
.Include(g => g.Group) .FirstOrDefaultAsync(g => g.Group.GID == dto.Group.GID || g.Group.Alias == dto.Group.GID,
.FirstOrDefaultAsync(g => g.GroupGID == dto.Group.GID, cancellationToken) cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
ImageCheckService.ImageLoadResult profileResult = new(); ImageCheckService.ImageLoadResult profileResult = new();
@@ -830,46 +830,40 @@ public partial class LightlessHub
} }
} }
var sanitizedProfileImage = profileResult?.Base64Image;
var sanitizedBannerImage = bannerResult?.Base64Image;
if (groupProfileDb == null) if (groupProfileDb == null)
{ {
groupProfileDb = new GroupProfile groupProfileDb = new GroupProfile
{ {
GroupGID = dto.Group.GID, GroupGID = dto.Group.GID,
Group = group,
ProfileDisabled = false, ProfileDisabled = false,
IsNSFW = dto.IsNsfw ?? false, IsNSFW = dto.IsNsfw ?? false,
}; };
groupProfileDb.UpdateProfileFromDto(dto, sanitizedProfileImage, sanitizedBannerImage); groupProfileDb.UpdateProfileFromDto(dto, profileResult?.Base64Image, bannerResult?.Base64Image);
await DbContext.GroupProfiles.AddAsync(groupProfileDb, cancellationToken).ConfigureAwait(false); await DbContext.GroupProfiles.AddAsync(groupProfileDb, cancellationToken).ConfigureAwait(false);
} }
else else
{ {
groupProfileDb.Group ??= group;
if (groupProfileDb?.ProfileDisabled ?? false) if (groupProfileDb?.ProfileDisabled ?? false)
{ {
await Clients.Caller.Client_ReceiveServerMessage(MessageSeverity.Error, "Your profile was permanently disabled and cannot be edited").ConfigureAwait(false); await Clients.Caller.Client_ReceiveServerMessage(MessageSeverity.Error, "Your profile was permanently disabled and cannot be edited").ConfigureAwait(false);
return; return;
} }
groupProfileDb.UpdateProfileFromDto(dto, sanitizedProfileImage, sanitizedBannerImage); groupProfileDb.UpdateProfileFromDto(dto, profileResult?.Base64Image, bannerResult?.Base64Image);
}
var userIds = await DbContext.GroupPairs var userIds = await DbContext.GroupPairs
.Where(p => p.GroupGID == groupProfileDb.GroupGID) .Where(p => p.GroupGID == groupProfileDb.GroupGID)
.Select(p => p.GroupUserUID) .Select(p => p.GroupUserUID)
.ToListAsync(cancellationToken) .ToListAsync(cancellationToken)
.ConfigureAwait(false);
if (userIds.Count > 0)
{
var profileDto = groupProfileDb.ToDTO();
await Clients.Users(userIds).Client_GroupSendProfile(profileDto)
.ConfigureAwait(false); .ConfigureAwait(false);
if (userIds.Count > 0)
{
var profileDto = groupProfileDb.ToDTO();
await Clients.Users(userIds).Client_GroupSendProfile(profileDto)
.ConfigureAwait(false);
}
} }
await DbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false); await DbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

View File

@@ -1128,7 +1128,7 @@ public partial class LightlessHub
if (!string.Equals(dto.User.UID, UserUID, StringComparison.Ordinal)) throw new HubException("Cannot modify profile data for anyone but yourself"); if (!string.Equals(dto.User.UID, UserUID, StringComparison.Ordinal)) throw new HubException("Cannot modify profile data for anyone but yourself");
var profileData = await DbContext.UserProfileData.SingleOrDefaultAsync(u => u.UserUID == dto.User.UID, cancellationToken: RequestAbortedToken).ConfigureAwait(false); var existingData = await DbContext.UserProfileData.SingleOrDefaultAsync(u => u.UserUID == dto.User.UID, cancellationToken: RequestAbortedToken).ConfigureAwait(false);
ImageCheckService.ImageLoadResult profileResult = new(); ImageCheckService.ImageLoadResult profileResult = new();
ImageCheckService.ImageLoadResult bannerResult = new(); ImageCheckService.ImageLoadResult bannerResult = new();
@@ -1157,33 +1157,35 @@ public partial class LightlessHub
} }
} }
if (profileData != null) if (existingData != null)
{ {
if (profileData.FlaggedForReport) if (existingData.FlaggedForReport)
{ {
await Clients.Caller.Client_ReceiveServerMessage(MessageSeverity.Error, "Your profile is currently flagged for report and cannot be edited").ConfigureAwait(false); await Clients.Caller.Client_ReceiveServerMessage(MessageSeverity.Error, "Your profile is currently flagged for report and cannot be edited").ConfigureAwait(false);
return; return;
} }
if (profileData.ProfileDisabled) if (existingData.ProfileDisabled)
{ {
await Clients.Caller.Client_ReceiveServerMessage(MessageSeverity.Error, "Your profile was permanently disabled and cannot be edited").ConfigureAwait(false); await Clients.Caller.Client_ReceiveServerMessage(MessageSeverity.Error, "Your profile was permanently disabled and cannot be edited").ConfigureAwait(false);
return; return;
} }
profileData.UpdateProfileFromDto(dto, profileResult.Base64Image, bannerResult.Base64Image); existingData.UpdateProfileFromDto(dto, profileResult.Base64Image, bannerResult.Base64Image);
} }
else else
{ {
profileData = new() UserProfileData newUserProfileData = new()
{ {
UserUID = dto.User.UID, UserUID = dto.User.UID,
Base64ProfileImage = dto.ProfilePictureBase64 ?? null,
UserDescription = dto.Description ?? null,
IsNSFW = dto.IsNSFW ?? false, IsNSFW = dto.IsNSFW ?? false,
}; };
profileData.UpdateProfileFromDto(dto, profileResult.Base64Image, bannerResult.Base64Image); existingData.UpdateProfileFromDto(dto, profileResult.Base64Image, bannerResult.Base64Image);
await DbContext.UserProfileData.AddAsync(profileData, cancellationToken).ConfigureAwait(false); await DbContext.UserProfileData.AddAsync(newUserProfileData, cancellationToken).ConfigureAwait(false);
} }

View File

@@ -45,8 +45,7 @@ public static class Extensions
return new GroupProfileDto(Group: null, Description: null, Tags: null, PictureBase64: null, BannerBase64: null, IsNsfw: false, IsDisabled: false); return new GroupProfileDto(Group: null, Description: null, Tags: null, PictureBase64: null, BannerBase64: null, IsNsfw: false, IsDisabled: false);
} }
var groupData = groupProfile.Group?.ToGroupData() var groupData = groupProfile.Group?.ToGroupData();
?? (!string.IsNullOrWhiteSpace(groupProfile.GroupGID) ? new GroupData(groupProfile.GroupGID) : null);
return new GroupProfileDto( return new GroupProfileDto(
groupData, groupData,

View File

@@ -329,12 +329,13 @@ public partial class LightlessWizardModule : InteractionModuleBase
private int? ParseCharacterIdFromLodestoneUrl(string lodestoneUrl) private int? ParseCharacterIdFromLodestoneUrl(string lodestoneUrl)
{ {
var regex = new Regex(@"^https:\/\/(na|eu|de|fr|jp)\.finalfantasyxiv\.com\/lodestone\/character\/(\d{8})/?$"); var regex = new Regex(@"https:\/\/(na|eu|de|fr|jp)\.finalfantasyxiv\.com\/lodestone\/character\/\d+");
var matches = regex.Match(lodestoneUrl); var matches = regex.Match(lodestoneUrl);
var isLodestoneUrl = matches.Success; var isLodestoneUrl = matches.Success;
if (!isLodestoneUrl || matches.Groups.Count < 1) return null; if (!isLodestoneUrl || matches.Groups.Count < 1) return null;
var stringId = matches.Groups[2].ToString();
lodestoneUrl = matches.Groups[0].ToString();
var stringId = lodestoneUrl.Split('/', StringSplitOptions.RemoveEmptyEntries).Last();
if (!int.TryParse(stringId, out int lodestoneId)) if (!int.TryParse(stringId, out int lodestoneId))
{ {
return null; return null;