From 30ee13eff2cbc66151eb824df2bac629eea33a20 Mon Sep 17 00:00:00 2001 From: Stef Kariotidis Date: Sat, 29 Aug 2026 23:58:56 +0300 Subject: [PATCH 1/2] WIP: remove dormant user SSE production seam (checkpoint) --- .../Interfaces/ISseClient.cs | 8 -------- .../Models/SseEventModels.cs | 2 +- src/WayfarerMobile/Services/SseClient.cs | 20 ------------------- 3 files changed, 1 insertion(+), 29 deletions(-) diff --git a/src/WayfarerMobile.Core/Interfaces/ISseClient.cs b/src/WayfarerMobile.Core/Interfaces/ISseClient.cs index 19877864..d758afd0 100644 --- a/src/WayfarerMobile.Core/Interfaces/ISseClient.cs +++ b/src/WayfarerMobile.Core/Interfaces/ISseClient.cs @@ -71,14 +71,6 @@ public interface ISseClient : IDisposable #region Methods - /// - /// Subscribe to per-user SSE channel for location updates. - /// - /// Username to subscribe to. - /// Token to cancel the subscription. - /// Task that completes when subscription ends. - Task SubscribeToUserAsync(string userName, CancellationToken cancellationToken = default); - /// /// Subscribe to consolidated group SSE channel for location and membership updates. /// All event types (location, visibility-changed, member-left, etc.) come through this single stream. diff --git a/src/WayfarerMobile.Core/Models/SseEventModels.cs b/src/WayfarerMobile.Core/Models/SseEventModels.cs index db79d1d3..31eb3b02 100644 --- a/src/WayfarerMobile.Core/Models/SseEventModels.cs +++ b/src/WayfarerMobile.Core/Models/SseEventModels.cs @@ -2,7 +2,7 @@ namespace WayfarerMobile.Core.Models; /// /// SSE event for location updates. -/// Received from channels: location-update-{userName} or group-{groupId} (consolidated) +/// Received from the consolidated group-{groupId} channel. /// public class SseLocationEvent { diff --git a/src/WayfarerMobile/Services/SseClient.cs b/src/WayfarerMobile/Services/SseClient.cs index 7710f5d5..d981e7d5 100644 --- a/src/WayfarerMobile/Services/SseClient.cs +++ b/src/WayfarerMobile/Services/SseClient.cs @@ -125,26 +125,6 @@ public SseClient( #region Public Methods - /// - public async Task SubscribeToUserAsync(string userName, CancellationToken cancellationToken = default) - { - if (string.IsNullOrWhiteSpace(userName)) - { - _logger.LogWarning("Cannot subscribe to SSE: userName is empty"); - return; - } - - string? serverUrl = _settings.ServerUrl; - if (string.IsNullOrWhiteSpace(serverUrl)) - { - _logger.LogError("Server URL not configured for SSE subscription"); - return; - } - - string url = $"{serverUrl.TrimEnd('/')}/api/mobile/sse/location-update/{Uri.EscapeDataString(userName)}"; - await SubscribeAsync(url, $"user:{userName}", cancellationToken).ConfigureAwait(false); - } - /// public async Task SubscribeToGroupAsync(string groupId, CancellationToken cancellationToken = default) { From db4462bb18e5b1666bed5a61fa03ae1a9b9abb9e Mon Sep 17 00:00:00 2001 From: Stef Kariotidis Date: Sun, 30 Aug 2026 00:02:58 +0300 Subject: [PATCH 2/2] Remove dormant user SSE test surface --- .../Unit/Services/SseClientTests.cs | 54 +------------------ 1 file changed, 2 insertions(+), 52 deletions(-) diff --git a/tests/WayfarerMobile.Tests/Unit/Services/SseClientTests.cs b/tests/WayfarerMobile.Tests/Unit/Services/SseClientTests.cs index 13ba0fcf..736db6a5 100644 --- a/tests/WayfarerMobile.Tests/Unit/Services/SseClientTests.cs +++ b/tests/WayfarerMobile.Tests/Unit/Services/SseClientTests.cs @@ -161,47 +161,6 @@ public void Reconnecting_CanSubscribeAndUnsubscribe() eventRaised.Should().BeFalse(); } - [Fact] - public async Task SubscribeToUserAsync_EmptyUserName_LogsWarningAndReturns() - { - var client = CreateClient(); - await client.SubscribeToUserAsync(string.Empty); - client.IsConnected.Should().BeFalse(); - } - - [Fact] - public async Task SubscribeToUserAsync_NoServerUrl_LogsErrorAndReturns() - { - _mockSettings.Setup(s => s.ServerUrl).Returns((string?)null); - var client = CreateClient(); - await client.SubscribeToUserAsync("testuser"); - client.IsConnected.Should().BeFalse(); - } - - [Fact] - public async Task SubscribeToUserAsync_ValidUserName_BuildsCorrectUrl() - { - _mockSettings.Setup(s => s.ServerUrl).Returns("https://api.example.com"); - string? capturedUrl = null; - - _mockHttpHandler - .Protected() - .Setup>( - "SendAsync", - ItExpr.IsAny(), - ItExpr.IsAny()) - .Callback((req, _) => capturedUrl = req.RequestUri?.ToString()) - .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("") }); - - var client = CreateClient(); - using var cts = new CancellationTokenSource(100); - try { await client.SubscribeToUserAsync("testuser", cts.Token); } - catch (OperationCanceledException) { } - catch (HttpRequestException) { } - - capturedUrl.Should().Be("https://api.example.com/api/mobile/sse/location-update/testuser"); - } - [Fact] public async Task SubscribeToGroupAsync_EmptyGroupId_LogsWarningAndReturns() { @@ -252,7 +211,7 @@ public async Task Subscribe_SetsAuthorizationHeader() var client = CreateClient(); using var cts = new CancellationTokenSource(100); - try { await client.SubscribeToUserAsync("testuser", cts.Token); } + try { await client.SubscribeToGroupAsync("group-abc-123", cts.Token); } catch (OperationCanceledException) { } catch (HttpRequestException) { } @@ -277,7 +236,7 @@ public async Task Subscribe_SetsAcceptHeader() var client = CreateClient(); using var cts = new CancellationTokenSource(100); - try { await client.SubscribeToUserAsync("testuser", cts.Token); } + try { await client.SubscribeToGroupAsync("group-abc-123", cts.Token); } catch (OperationCanceledException) { } catch (HttpRequestException) { } @@ -535,15 +494,6 @@ public TestSseClient(ISettingsService settings, ILogger logger, I _httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory)); } - public Task SubscribeToUserAsync(string userName, CancellationToken cancellationToken = default) - { - if (string.IsNullOrWhiteSpace(userName)) { _logger.LogWarning("userName is empty"); return Task.CompletedTask; } - var serverUrl = _settings.ServerUrl; - if (string.IsNullOrWhiteSpace(serverUrl)) { _logger.LogError("Server URL not configured"); return Task.CompletedTask; } - var url = serverUrl.TrimEnd((char)47) + "/api/mobile/sse/location-update/" + Uri.EscapeDataString(userName); - return SubscribeAsync(url, "user:" + userName, cancellationToken); - } - public Task SubscribeToGroupAsync(string groupId, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(groupId)) { _logger.LogWarning("groupId is empty"); return Task.CompletedTask; }