RynthChat: All is pinned by default
pinnedTabs absent (never set, or a file from before pins) means All is pinned (ChatPins.FromSettings); saving always writes the array, so unpinning everything persists as [] and is not mistaken for "never set". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
6e271c0955
commit
ef61144592
3 changed files with 41 additions and 5 deletions
|
|
@ -476,7 +476,7 @@ internal static class ChatModel
|
|||
private static string[] _seededTabs = Array.Empty<string>(); // owner keys
|
||||
private static Dictionary<string, string> _tabServers = NewMap(); // tab -> server id
|
||||
private static Dictionary<string, string> _globalRooms = NewMap(); // server id -> room
|
||||
private static string[] _pinnedTabs = Array.Empty<string>(); // pin order
|
||||
private static string[] _pinnedTabs = ChatPins.FromSettings(null); // pin order (All until a file says otherwise)
|
||||
// Published by ApplyServerTabs (render thread), read lock-free by the pump and the faces.
|
||||
private static volatile string[] _activeServers = Array.Empty<string>();
|
||||
private static volatile SectionChatTabDecl[] _tabDecls = Array.Empty<SectionChatTabDecl>();
|
||||
|
|
@ -1816,9 +1816,7 @@ internal static class ChatModel
|
|||
string[] seeded = (dto.SeededTabs ?? Array.Empty<string>())
|
||||
.Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => s.Trim())
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase).ToArray();
|
||||
string[] pinned = (dto.PinnedTabs ?? Array.Empty<string>())
|
||||
.Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => s.Trim())
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase).ToArray();
|
||||
string[] pinned = ChatPins.FromSettings(dto.PinnedTabs); // absent = All; [] stays empty
|
||||
// Under EditLock, as ApplyServerTabs (render thread) edits the same lists.
|
||||
lock (EditLock)
|
||||
{
|
||||
|
|
@ -1893,7 +1891,7 @@ internal static class ChatModel
|
|||
SeededTabs = NullIfEmpty(Volatile.Read(ref _seededTabs)),
|
||||
TabServers = NullIfEmpty(Volatile.Read(ref _tabServers)),
|
||||
GlobalRooms = NullIfEmpty(Volatile.Read(ref _globalRooms)),
|
||||
PinnedTabs = NullIfEmpty(Volatile.Read(ref _pinnedTabs)),
|
||||
PinnedTabs = Volatile.Read(ref _pinnedTabs), // always written, empty included: [] = nothing pinned, absent = All
|
||||
Filters = Filters.Select(ToDto).ToArray(),
|
||||
// Only presets the user touched: new presets in later builds start off.
|
||||
Presets = RynthCore.Engine.UI.Panels.RynthChatPresets.All
|
||||
|
|
|
|||
|
|
@ -28,6 +28,27 @@ internal static class ChatPins
|
|||
return pins.Append(tab).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>The tab pinned when nothing was ever saved.</summary>
|
||||
internal const string DefaultPin = "All";
|
||||
|
||||
/// <summary>
|
||||
/// The pins a settings file means: absent (never set, or a file from before pins) = All
|
||||
/// pinned; a saved array, empty included, is exactly what the player left. Blank names are
|
||||
/// dropped and repeats (any case) kept once.
|
||||
/// </summary>
|
||||
internal static string[] FromSettings(string[]? saved)
|
||||
{
|
||||
if (saved == null) return new[] { DefaultPin };
|
||||
var result = new List<string>(saved.Length);
|
||||
foreach (string s in saved)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(s)) continue;
|
||||
string name = s.Trim();
|
||||
if (!result.Any(r => Same(r, name))) result.Add(name);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>Pins <paramref name="tab"/> at the end unless it is pinned already (idempotent, unlike Toggle). A blank name changes nothing.</summary>
|
||||
internal static string[] Add(string[] pins, string tab)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1647,6 +1647,23 @@ internal static class Program
|
|||
Check(ChatPins.Add(added, "").Length == 2 && ChatPins.Add(added, " ").Length == 2, "a blank name adds nothing");
|
||||
Check(ChatPins.Add(Array.Empty<string>(), " Net ").SequenceEqual(new[] { "Net" }), "trimmed");
|
||||
|
||||
Case("PinsDefault_AbsentMeansAll");
|
||||
Check(ChatPins.FromSettings(null).SequenceEqual(new[] { "All" }), "never set = All pinned");
|
||||
RynthChatSettingsDto oldFile = JsonSerializer.Deserialize(
|
||||
"{\"version\":1,\"customTabs\":[\"Mine\"]}", RynthChatJsonContext.Default.RynthChatSettingsDto)!;
|
||||
Check(oldFile.PinnedTabs == null && ChatPins.FromSettings(oldFile.PinnedTabs).SequenceEqual(new[] { "All" }),
|
||||
"a file from before pins = All pinned");
|
||||
|
||||
Case("PinsDefault_EmptyRoundTrips");
|
||||
var noPins = new RynthChatSettingsDto { PinnedTabs = ChatPins.Remove(ChatPins.FromSettings(null), "All") };
|
||||
string noPinsJson = JsonSerializer.Serialize(noPins, RynthChatJsonContext.Default.RynthChatSettingsDto);
|
||||
Check(noPinsJson.Contains("\"pinnedTabs\":[]", StringComparison.Ordinal), "unpinning everything is written as []: " + noPinsJson);
|
||||
RynthChatSettingsDto noPinsBack = JsonSerializer.Deserialize(noPinsJson, RynthChatJsonContext.Default.RynthChatSettingsDto)!;
|
||||
Check(noPinsBack.PinnedTabs != null && ChatPins.FromSettings(noPinsBack.PinnedTabs).Length == 0, "and loads as nothing pinned, not All");
|
||||
string nullJson = JsonSerializer.Serialize(new RynthChatSettingsDto(), RynthChatJsonContext.Default.RynthChatSettingsDto);
|
||||
Check(!nullJson.Contains("pinnedTabs", StringComparison.Ordinal), "WhenWritingNull still drops only null");
|
||||
string[] kept = ChatPins.FromSettings(new[] { "Chat", " ", "chat", "Network" });
|
||||
Check(kept.SequenceEqual(new[] { "Chat", "Network" }), "a saved list is cleaned, order kept");
|
||||
Case("Layout_ZeroPins");
|
||||
Check(ChatPins.Layout(Array.Empty<float>(), 500, 22, 2) == (0, false), "nothing to draw, no overflow button");
|
||||
Check(ChatPins.Layout(Array.Empty<float>(), -50, 22, 2) == (0, false), "also in no room");
|
||||
|
|
|
|||
Loading…
Reference in a new issue