feat(server): settings sent alone move the hero frame with the project's hero
The sync of a local copy sends only the project; the server now maps its hero index to the frame the Library shows, through the same helper the archive engine's project writes use. Edits that name the hero are audited as such. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
4 files changed
+76
-10
No files matched your search
@@ -0,0 +1,26 @@
|
||||
using Titano.Core.Model;
|
||||
using Titano.Core.Project;
|
||||
using Titano.Data.Repositories;
|
||||
|
||||
namespace Titano.Data.Processing;
|
||||
|
||||
/// <summary>
|
||||
/// The index's hero frame (<see cref="Sequence.HeroFrameId"/>, the frame the Library shows) follows the project's hero
|
||||
/// (<see cref="ProjectSettings.HeroFrame"/>, a frame index; frame indices are positions).
|
||||
/// </summary>
|
||||
public static class HeroFrame
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="SequenceEdit.HeroFrameId"/> of a project whose hero went from <paramref name="before"/> to
|
||||
/// <paramref name="after"/>: null when it did not change, else the frame at the new index, or <see cref="Guid.Empty"/>
|
||||
/// (the first frame shows) when there is none.
|
||||
/// </summary>
|
||||
public static async Task<Guid?> EditAsync(TitanoDatabase db, Guid sequenceId, int? before, int? after, CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(db);
|
||||
if (before == after) return null;
|
||||
if (after is not >= 0) return Guid.Empty;
|
||||
var frames = await db.Frames.ListBySequenceAsync(sequenceId, after.Value - 1, 1, cancellationToken).ConfigureAwait(false);
|
||||
return frames is [{ } frame] && frame.Index == after ? frame.Id : Guid.Empty;
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,7 @@ internal sealed class ProjectStore(TitanoDatabase db, SequenceWriter writer)
|
||||
if (after == before) return false;
|
||||
AtomicFile.WriteAllText(folder.ProjectPath, after);
|
||||
// The Library shows the project's hero frame (advice fills it, a sync takes another PC's).
|
||||
var hero = edited.HeroFrame == current.HeroFrame ? (Guid?)null : await HeroFrameIdAsync(sequence.Id, edited.HeroFrame, cancellationToken).ConfigureAwait(false);
|
||||
var hero = await HeroFrame.EditAsync(db, sequence.Id, current.HeroFrame, edited.HeroFrame, cancellationToken).ConfigureAwait(false);
|
||||
var result = await db.Sequences.EditAsync(sequence.Id, new SequenceEdit { SettingsJson = after, HeroFrameId = hero }, row.SettingsVersion,
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
// A conflict means the API changed the settings meanwhile: apply the edit again on top of them.
|
||||
@@ -61,12 +61,4 @@ internal sealed class ProjectStore(TitanoDatabase db, SequenceWriter writer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The id of the frame at <paramref name="index"/> (frame indices are positions), or <see cref="Guid.Empty"/> to clear the hero.</summary>
|
||||
private async Task<Guid> HeroFrameIdAsync(Guid sequenceId, int? index, CancellationToken cancellationToken)
|
||||
{
|
||||
if (index is not >= 0) return Guid.Empty;
|
||||
var frames = await db.Frames.ListBySequenceAsync(sequenceId, index.Value - 1, 1, cancellationToken).ConfigureAwait(false);
|
||||
return frames is [{ } frame] && frame.Index == index ? frame.Id : Guid.Empty;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user