RynthChat: server-scoped default tabs from plugin manifests
SectionRegistry.Rebuild hands every manifest's chatTabs and the active server ids to ChatModel.ApplyServerTabs, which seeds each entry's tab once (seededTabs), rewrites its owned rules from the manifest, and gates the tab (tabServers) and its rules (ChatFilterRule.Server, ChatRouter) on the server being active. The pump records the Global room from network room lines (globalRooms) and rewrites the Global-room rule. - Apply is a no-op when nothing changed (EditFiltersIfChanged; rules compared as canonical forms with ChatServerTabs.SameRule), since Rebuild runs every second, and waits for the settings file to load first. - Rules an older engine stripped of "owner" are reclaimed by content (ChatServerTabs.Reclaim) instead of a second set being added. - A deleted server tab stays deleted across a reload: its disabled owned rules no longer re-create it in LoadSettings. - AllTabs caches per filter version and active-server set. - The rule editor marks server rules; a manifest with a dropped chatTabs entry is logged as partly read, not as unread. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
620e6b1507
commit
a92b282fd6
6 changed files with 542 additions and 32 deletions
|
|
@ -1215,6 +1215,52 @@ internal static class Program
|
|||
Check(!p.CreateTab && !p.Pin, "a seeded tab that is gone is not re-created");
|
||||
Check(p.Rules.All(r => !r.Enabled), "its rules stay disabled");
|
||||
|
||||
Case("Refresh_IsANoOpWhenNothingChanged");
|
||||
// ChatModel.ApplyServerTabs runs every second: a plan made from its own output must match it
|
||||
// rule for rule (SameRule), and want no create, pin or seed mark, or every Rebuild would save.
|
||||
owned = ChatServerTabs.Plan(d, State(), "Trade").Rules;
|
||||
p = ChatServerTabs.Plan(d, State(seeded: new[] { key }, tabs: new[] { "All", "Network" }, owned: owned), "Trade");
|
||||
Check(!p.CreateTab && !p.Pin && !p.MarkSeeded, "seeded: nothing to create, pin or mark");
|
||||
Check(p.Rules.Length == owned.Length && p.Rules.Zip(owned).All(z => ChatServerTabs.SameRule(z.First, z.Second)), "every rule is the same as before");
|
||||
var absent = new RynthChatFilterDto { Owner = key, Server = "dreamweave", Tab = "Network", Action = "copy", When = null, Mode = null, Pattern = "x", GlobalRoom = null, Enabled = true };
|
||||
var empty = new RynthChatFilterDto { Owner = key, Server = "dreamweave", Tab = "Network", Action = "copy", When = "", Mode = "", Pattern = "x", GlobalRoom = false, Enabled = true };
|
||||
Check(ChatServerTabs.SameRule(absent, empty), "absent and empty When / Mode / GlobalRoom are the same");
|
||||
Check(ChatServerTabs.SameRule(empty, new RynthChatFilterDto { Owner = key, Server = "dreamweave", Tab = "Network", Action = "copy", Pattern = "x", Color = "#FF0000", ColorMode = "line" }),
|
||||
"a colour the player gave the rule is not a difference");
|
||||
Check(!ChatServerTabs.SameRule(owned[2], ChatServerTabs.Plan(d, State(), "General").Rules[2]), "a new Global room is a difference");
|
||||
var off = ChatServerTabs.Plan(d, State(), "Trade").Rules;
|
||||
off[0].Enabled = false;
|
||||
Check(!ChatServerTabs.SameRule(owned[0], off[0]), "on / off is a difference");
|
||||
|
||||
Case("Reclaim_FindsRulesAnOlderEngineStripped");
|
||||
// An older engine rewrote the file: its copy of the rules has no owner, server or globalRoom.
|
||||
RynthChatFilterDto Strip(RynthChatFilterDto r) => new() { Tab = r.Tab, Action = r.Action, When = r.When, Mode = r.Mode, Pattern = r.Pattern, Enabled = r.Enabled };
|
||||
RynthChatFilterDto[] ours = ChatServerTabs.Plan(d, State(), "Trade").Rules;
|
||||
var player = new RynthChatFilterDto { Tab = "RP", Action = "copy", Mode = "startswith", Pattern = "[Roleplay] " };
|
||||
var file = new List<RynthChatFilterDto> { player, Strip(ours[1]), new() { Tab = "Junk", Action = "hide", Pattern = "spam" }, Strip(ours[0]), Strip(ours[2]) };
|
||||
int[]? found = ChatServerTabs.Reclaim(d, file);
|
||||
Check(found != null && found.SequenceEqual(new[] { 3, 1, 4 }), $"found in declaration order, not the player's look-alike Global rule: {(found == null ? "null" : string.Join(",", found))}");
|
||||
foreach (RynthChatFilterDto r in file) if (r.Tab == "Network") r.Tab = "DN";
|
||||
found = ChatServerTabs.Reclaim(d, file);
|
||||
Check(found != null && found.SequenceEqual(new[] { 3, 1, 4 }), "a renamed tab's stripped rules are found too");
|
||||
Check(ChatServerTabs.Reclaim(d, new[] { player, Strip(ours[0]) }) == null, "an incomplete set is not reclaimed");
|
||||
file[3].Owner = key;
|
||||
Check(ChatServerTabs.Reclaim(d, file) == null, "a rule that still has an owner is not reclaimed");
|
||||
Check(ChatServerTabs.Reclaim(d, new[] { Strip(ours[0]), Strip(ours[1]), new RynthChatFilterDto { Tab = "Other", Action = "copy", Mode = "startswith", Pattern = "[Trade] " } }) == null,
|
||||
"the set must be in one tab");
|
||||
|
||||
Case("Router_SkipsRulesOfInactiveServers");
|
||||
var serverRule = new ChatFilterRule { Pattern = "^x", Tab = "Network", Action = ChatRuleAction.Copy, Server = "dreamweave" };
|
||||
serverRule.Recompile();
|
||||
var anyRule = new ChatFilterRule { Pattern = "^x", Tab = "Every", Action = ChatRuleAction.Copy };
|
||||
anyRule.Recompile();
|
||||
ChatRoute on = new ChatRouter(new[] { serverRule, anyRule }, null, "", countHits: false, new[] { "DreamWeave" }).Evaluate("x", "Chat", 2, null);
|
||||
ChatRoute offRoute = new ChatRouter(new[] { serverRule, anyRule }, null, "", countHits: false, new[] { "aelrynth" }).Evaluate("x", "Chat", 2, null);
|
||||
ChatRoute none = new ChatRouter(new[] { serverRule, anyRule }, null, "", countHits: false).Evaluate("x", "Chat", 2, null);
|
||||
Check(on.ShowsIn("Network", "Chat") && on.ShowsIn("Every", "Chat"), "its server active (any case): both rules run");
|
||||
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("Plan rules compile");
|
||||
foreach (RynthChatFilterDto r in ChatServerTabs.Plan(d, State(), "LFG").Rules)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue