Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Beacon.Plugin/Services/ProfileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ public void Save(SaveProfileRequest request, byte[]? portrait, string? fileName,
if (portrait is { Length: > 0 })
{
var previousImages = profile.Gallery.Select(image => image.ImageId).ToHashSet();
var replacing = profile.PortraitImageId;
var uploaded = await api.UploadPortraitAsync(profile.Id, portrait, fileName ?? "portrait.png", lifetime.Token);
if (uploaded.Ok && uploaded.Value is { } withImage)
{
Expand All @@ -320,7 +321,27 @@ public void Save(SaveProfileRequest request, byte[]? portrait, string? fileName,
lifetime.Token);

if (selected.Ok && selected.Value is { } withPortrait)
{
profile = withPortrait;

// Retire the likeness this one replaces.
//
// Without this, changing your portrait quietly stacks another image into a
// gallery that holds eight, and the ninth change fails outright with an
// error about a gallery the player never chose to fill. A picture added on
// purpose from the gallery is never the portrait unless it was picked, so
// only discarded portraits are swept up here.
if (replacing is { } previousPortrait && previousPortrait != newImage.ImageId)
{
var removed = await api.RemoveGalleryImageAsync(
profile.Id,
previousPortrait,
lifetime.Token);

if (removed.Ok && removed.Value is { } tidied)
profile = tidied;
}
}
else
Post(() => LastError = $"The picture uploaded, but could not be selected as the portrait: {selected.Error}");
}
Expand Down
Loading
Loading