Add per-channel message retention with daily background sweep
Privacy filter trimmed history "by what" — this adds the time axis. Each ChatType gets its own retention window in days; channels without an explicit override fall back to a configurable global default. The master switch defaults to OFF: the plugin never deletes history without explicit user consent. MessageStore.DeleteByRetentionPolicy builds an OR'd WHERE clause over (ChatType = X AND Date < cutoff_X) plus a NOT IN catch-all for the global default, hard-deletes matches, and only runs VACUUM when something was actually removed. Plugin.RunRetentionSweepIfDue runs at most once per 24 hours on a background thread (off the load path) and persists the timestamp so subsequent restarts skip the sweep until enough time has passed. The Privacy tab gains a retention section with the master switch, default-days input, per-channel override tree, reset buttons, and a Ctrl+Shift "apply now" action that mirrors the auto-sweep but on demand. Spec defaults: Tells 365 days, own-conversation channels (Party, Cross-Party, Alliance, PvP Team, FC, Linkshells 1-8, Cross-World Linkshells 1-8, ExtraChat 1-8) 90 days, fallback 30 days.
This commit is contained in:
@@ -156,6 +156,11 @@ public sealed class Plugin : IDalamudPlugin
|
||||
|
||||
MessageManager = new MessageManager(this); // Does it require UI?
|
||||
|
||||
// Hellion Chat — daily retention sweep, off-thread so it never
|
||||
// blocks plugin load. Skips itself when disabled or already ran
|
||||
// within the past 24 hours.
|
||||
RunRetentionSweepIfDue();
|
||||
|
||||
ChatLogWindow = new ChatLogWindow(this);
|
||||
SettingsWindow = new SettingsWindow(this);
|
||||
DbViewer = new DbViewer(this);
|
||||
@@ -305,6 +310,46 @@ public sealed class Plugin : IDalamudPlugin
|
||||
}
|
||||
}
|
||||
|
||||
private void RunRetentionSweepIfDue()
|
||||
{
|
||||
if (!Config.RetentionEnabled)
|
||||
return;
|
||||
if (DateTimeOffset.UtcNow - Config.RetentionLastRunAt < TimeSpan.FromHours(24))
|
||||
return;
|
||||
|
||||
// Snapshot the policy so the user can edit settings while we run.
|
||||
var policy = Config.RetentionPerChannelDays.ToDictionary(p => (int)(ushort)p.Key, p => p.Value);
|
||||
var defaultDays = Config.RetentionDefaultDays;
|
||||
|
||||
new Thread(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var deleted = MessageManager.Store.DeleteByRetentionPolicy(policy, defaultDays);
|
||||
Config.RetentionLastRunAt = DateTimeOffset.UtcNow;
|
||||
SaveConfig();
|
||||
|
||||
if (deleted > 0)
|
||||
{
|
||||
Log.Information($"Retention sweep deleted {deleted} expired messages.");
|
||||
Framework.Run(() =>
|
||||
{
|
||||
MessageManager.ClearAllTabs();
|
||||
MessageManager.FilterAllTabsAsync();
|
||||
}).Wait();
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Information("Retention sweep ran, nothing expired.");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e, "Retention sweep failed");
|
||||
}
|
||||
}) { IsBackground = true }.Start();
|
||||
}
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
ChatLogWindow.BeginFrame();
|
||||
|
||||
Reference in New Issue
Block a user