mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-11-19 15:18:06 +01:00
feat: enhance chat functionality with auto-join, persistent read positions, and theme border customization
This commit is contained in:
@@ -42,6 +42,18 @@ public class SavedServer
|
||||
/// user's machine — the server never sees them.
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ChannelKeys { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Channels the user explicitly left with /leave. Excluded from the automatic
|
||||
/// join-all-channels pass at connect until the user joins them again.
|
||||
/// </summary>
|
||||
public List<string> LeftChannels { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Last message the user has read per channel (message id as string), persisted so
|
||||
/// unread counts, @mention highlights, and the "new messages" marker survive restarts.
|
||||
/// </summary>
|
||||
public Dictionary<string, string> LastReadMessages { get; set; } = [];
|
||||
}
|
||||
|
||||
public class AccountPreset
|
||||
|
||||
@@ -9,6 +9,10 @@ public static class ConfigManager
|
||||
|
||||
private static readonly string ConfigPath = Path.Combine(ConfigDir, "config.json");
|
||||
|
||||
// Load-mutate-save cycles run from both the UI thread and background tasks
|
||||
// (token refresh, room keys, last-read checkpoints) — serialize file access.
|
||||
private static readonly Lock FileLock = new();
|
||||
|
||||
private static readonly JsonSerializerOptions JsonOptions = new()
|
||||
{
|
||||
WriteIndented = true,
|
||||
@@ -17,54 +21,66 @@ public static class ConfigManager
|
||||
|
||||
public static ClientConfig Load()
|
||||
{
|
||||
try
|
||||
lock (FileLock)
|
||||
{
|
||||
if (!File.Exists(ConfigPath))
|
||||
return new ClientConfig();
|
||||
try
|
||||
{
|
||||
if (!File.Exists(ConfigPath))
|
||||
return new ClientConfig();
|
||||
|
||||
var json = File.ReadAllText(ConfigPath);
|
||||
return JsonSerializer.Deserialize<ClientConfig>(json, JsonOptions) ?? new ClientConfig();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new ClientConfig();
|
||||
var json = File.ReadAllText(ConfigPath);
|
||||
return JsonSerializer.Deserialize<ClientConfig>(json, JsonOptions) ?? new ClientConfig();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new ClientConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Save(ClientConfig config)
|
||||
{
|
||||
try
|
||||
lock (FileLock)
|
||||
{
|
||||
Directory.CreateDirectory(ConfigDir);
|
||||
var json = JsonSerializer.Serialize(config, JsonOptions);
|
||||
File.WriteAllText(ConfigPath, json);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Silently fail — config save is best-effort
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(ConfigDir);
|
||||
var json = JsonSerializer.Serialize(config, JsonOptions);
|
||||
File.WriteAllText(ConfigPath, json);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Silently fail — config save is best-effort
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveServer(SavedServer server)
|
||||
{
|
||||
var config = Load();
|
||||
var existing = config.SavedServers.FindIndex(s =>
|
||||
string.Equals(s.Url, server.Url, StringComparison.OrdinalIgnoreCase));
|
||||
lock (FileLock)
|
||||
{
|
||||
var config = Load();
|
||||
var existing = config.SavedServers.FindIndex(s =>
|
||||
string.Equals(s.Url, server.Url, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (existing >= 0)
|
||||
config.SavedServers[existing] = server;
|
||||
else
|
||||
config.SavedServers.Add(server);
|
||||
if (existing >= 0)
|
||||
config.SavedServers[existing] = server;
|
||||
else
|
||||
config.SavedServers.Add(server);
|
||||
|
||||
Save(config);
|
||||
Save(config);
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemoveServer(string url)
|
||||
{
|
||||
var config = Load();
|
||||
config.SavedServers.RemoveAll(s =>
|
||||
string.Equals(s.Url, url, StringComparison.OrdinalIgnoreCase));
|
||||
lock (FileLock)
|
||||
{
|
||||
var config = Load();
|
||||
config.SavedServers.RemoveAll(s =>
|
||||
string.Equals(s.Url, url, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
Save(config);
|
||||
Save(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user