RynthChat: a new tab never lands in a hidden server tab

"New tab: Network" on a server where the DreamWeave Network tab is
hidden returned that hidden tab, so the player's new rule filled the
server's tab. ChatServerTabs.ResolveNewTab now keeps "returns the
existing one" for a visible tab only; a hidden match gets a free
numbered name ("Network 2"). An unreadable settings file is logged
once per run instead of on every 2 s retry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daniel Wallace 2026-11-15 09:05:29 -08:00
commit 0eec23f6fd
3 changed files with 43 additions and 11 deletions

View file

@ -695,13 +695,13 @@ internal static class ChatModel
{
name = name.Trim();
if (name.Length == 0) return null;
// Every tab, also one hidden because its server is not active (as RenameCustomTab), or a
// second tab of the same name would be made beside it.
string? existing = BuildTabs(null).FirstOrDefault(t => string.Equals(t, name, StringComparison.OrdinalIgnoreCase));
if (existing == null || !IsBaseTab(existing)) EnsureCustomTab(existing ?? name);
if (select) ActiveChannel = existing ?? name;
// A tab the player sees by that name is that tab; one hidden because its server is not
// active is that server's, so the new tab gets a free name beside it ("Network 2").
(string tab, bool existing) = ChatServerTabs.ResolveNewTab(name, AllTabs(), BuildTabs(null));
if (!existing || !IsBaseTab(tab)) EnsureCustomTab(tab);
if (select) ActiveChannel = tab;
SaveSettings();
return existing ?? name;
return tab;
}
private static void EnsureCustomTab(string name)
@ -1709,9 +1709,13 @@ internal static class ChatModel
}
catch (Exception ex)
{
RynthLog.UI($"ChatModel: settings load failed: {ex.Message}");
// One copy per run: the retry every 2 s must not leave a copy each time.
if (!_keptUnreadable) { _keptUnreadable = true; KeepUnreadable(); }
// Logged and copied once per run: the retry every 2 s must not repeat either.
if (!_keptUnreadable)
{
_keptUnreadable = true;
RynthLog.UI($"ChatModel: settings load failed (retrying every 2 s, logged once): {ex.Message}");
KeepUnreadable();
}
return false;
}
}

View file

@ -168,9 +168,27 @@ internal static class ChatServerTabs
private static string FreeName(string name, string clashBase, IReadOnlyCollection<string> tabs)
{
if (!Has(tabs, name)) return name;
if (!Has(tabs, clashBase)) return clashBase;
return Numbered(clashBase, tabs);
}
/// <summary><paramref name="name"/> if no tab has it, else "name 2", "name 3"...</summary>
private static string Numbered(string name, IReadOnlyCollection<string> tabs)
{
if (!Has(tabs, name)) return name;
for (int n = 2; ; n++)
if (!Has(tabs, clashBase + " " + n)) return clashBase + " " + n;
if (!Has(tabs, name + " " + n)) return name + " " + n;
}
/// <summary>
/// The tab "New tab: <paramref name="name"/>" means (ChatModel.AddCustomTab): a tab the player
/// can see by that name is that tab (Existing); one that exists but is hidden (an inactive
/// server's) is not theirs to fill, so a free "name 2" is made instead; else the name itself.
/// </summary>
internal static (string Tab, bool Existing) ResolveNewTab(string name, IReadOnlyCollection<string> visibleTabs, IReadOnlyCollection<string> everyTab)
{
string? shown = visibleTabs.FirstOrDefault(t => string.Equals(t, name, StringComparison.OrdinalIgnoreCase));
if (shown != null) return (shown, true);
return (Numbered(name, everyTab), false);
}
/// <summary>