WIP: RynthChat: Network tab Join/Leave bar and Global sends #17

Draft
AwfulWaffle wants to merge 17 commits from AwfulWaffle/RynthCore:chat/network-join into main
3 changed files with 43 additions and 11 deletions
Showing only changes of commit 0eec23f6fd - Show all commits

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>
Daniel Wallace 2026-11-15 09:05:29 -08:00

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>

View file

@ -1449,6 +1449,16 @@ internal static class Program
Check(!offRoute.ShowsIn("Network", "Chat") && offRoute.ShowsIn("Every", "Chat"), "another server: only the every-server rule runs");
Check(!none.ShowsIn("Network", "Chat") && none.ShowsIn("Every", "Chat"), "no servers known: only the every-server rule runs");
Case("ResolveNewTab_HiddenServerTabIsAClash");
// "New tab: Network" on another server, where the DreamWeave Network tab is hidden.
string[] visible = { "All", "Chat", "Mine" };
string[] everyTab = { "All", "Chat", "Mine", "Network", "Network 2" };
Check(ChatServerTabs.ResolveNewTab("mine", visible, everyTab) == ("Mine", true), "a visible tab of that name is that tab (its own case)");
Check(ChatServerTabs.ResolveNewTab("chat", visible, everyTab) == ("Chat", true), "a base tab too");
Check(ChatServerTabs.ResolveNewTab("Network", visible, everyTab) == ("Network 3", false), "a hidden server tab: a free numbered name, not the server's tab");
Check(ChatServerTabs.ResolveNewTab("Network", visible, new[] { "All", "Network" }) == ("Network 2", false), "the first free number");
Check(ChatServerTabs.ResolveNewTab("Fresh", visible, everyTab) == ("Fresh", false), "no match: the name itself, new");
Case("Apply rules compile");
foreach (RynthChatFilterDto r in new TabSim { Room = "LFG" }.Apply(d).Inserts)
{