mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-11-10 07:08:11 +01:00
fix: save refreshed tokens for server URLs with a trailing slash
This commit is contained in:
@@ -2232,8 +2232,7 @@ public sealed class AppOrchestrator : IDisposable
|
||||
if (url is null) return;
|
||||
|
||||
var config = ConfigManager.Load();
|
||||
var server = config.SavedServers.FirstOrDefault(s =>
|
||||
string.Equals(s.Url, url, StringComparison.OrdinalIgnoreCase));
|
||||
var server = config.FindServer(url);
|
||||
if (server is null) return;
|
||||
|
||||
mutate(server);
|
||||
|
||||
@@ -18,6 +18,14 @@ public class ClientConfig
|
||||
/// Applies to copy-paste/drag-drop attachments, which have no per-file size flag.
|
||||
/// </summary>
|
||||
public string DefaultAsciiSize { get; set; } = "m";
|
||||
|
||||
/// <summary>
|
||||
/// Finds a saved server by URL. A trailing slash is ignored: entries keep the URL as the
|
||||
/// user typed it, while <see cref="Services.ApiClient.BaseUrl"/> has the slash removed.
|
||||
/// </summary>
|
||||
public SavedServer? FindServer(string url) =>
|
||||
SavedServers.FirstOrDefault(s =>
|
||||
string.Equals(s.Url.TrimEnd('/'), url.TrimEnd('/'), StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
public class NotificationConfig
|
||||
|
||||
@@ -152,7 +152,7 @@ internal sealed class ConnectionManager : IAsyncDisposable
|
||||
// all of them, not just channels opened this session. Channels the user left
|
||||
// with /leave stay out until rejoined; protected channels we can't enter
|
||||
// silently (no cached membership) are skipped, never prompted for.
|
||||
var leftChannels = FindServer(ConfigManager.Load(), info.ServerUrl)?.LeftChannels ?? [];
|
||||
var leftChannels = ConfigManager.Load().FindServer(info.ServerUrl)?.LeftChannels ?? [];
|
||||
foreach (var channel in channels)
|
||||
{
|
||||
if (channel.Name.Equals(HubConstants.DefaultChannel, StringComparison.OrdinalIgnoreCase))
|
||||
@@ -332,7 +332,7 @@ internal sealed class ConnectionManager : IAsyncDisposable
|
||||
{
|
||||
if (_apiClient?.RefreshToken is null) return;
|
||||
var config = ConfigManager.Load();
|
||||
var server = FindServer(config, _apiClient.BaseUrl);
|
||||
var server = config.FindServer(_apiClient.BaseUrl);
|
||||
if (server is not null && server.RememberMe)
|
||||
{
|
||||
server.RefreshToken = _apiClient.RefreshToken;
|
||||
@@ -340,10 +340,6 @@ internal sealed class ConnectionManager : IAsyncDisposable
|
||||
}
|
||||
}
|
||||
|
||||
private static SavedServer? FindServer(ClientConfig config, string url) =>
|
||||
config.SavedServers.FirstOrDefault(s =>
|
||||
string.Equals(s.Url, url, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
// ── Dispose ───────────────────────────────────────────────────────────
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using EchoHub.Client.Config;
|
||||
using Xunit;
|
||||
|
||||
namespace EchoHub.Tests;
|
||||
|
||||
public class ClientConfigTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("https://echo.example.com/", "https://echo.example.com")]
|
||||
[InlineData("https://echo.example.com", "https://echo.example.com/")]
|
||||
[InlineData("https://echo.example.com", "https://echo.example.com")]
|
||||
[InlineData("https://ECHO.example.com/", "https://echo.example.com")]
|
||||
public void FindServer_IgnoresTrailingSlashAndCase(string savedUrl, string lookupUrl)
|
||||
{
|
||||
var config = new ClientConfig();
|
||||
var server = new SavedServer { Name = "echo", Url = savedUrl };
|
||||
config.SavedServers.Add(server);
|
||||
|
||||
Assert.Same(server, config.FindServer(lookupUrl));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FindServer_OtherServer_ReturnsNull()
|
||||
{
|
||||
var config = new ClientConfig();
|
||||
config.SavedServers.Add(new SavedServer { Name = "echo", Url = "https://echo.example.com/" });
|
||||
|
||||
Assert.Null(config.FindServer("https://other.example.com"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user