diff --git a/CHANGELOG.md b/CHANGELOG.md index eca5b24cc..4d8716342 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ ## [1.0.8-rc38] - unstable +### Added + +* [PostIt/Chat] Persist audio, audio-video and private-message contact preferences and announce them to ChatHub on connection and reconnection. Add the audio-only call display contract; filtering contacts and audio-only media are not implemented yet. + ### Fixed * [PostIt] Restore selectable error notification messages and update blog and rendez-vous tests for the current layouts and address editor. diff --git a/doc/architecture/audio-video-calls.md b/doc/architecture/audio-video-calls.md index 540c9da0d..66ba850e3 100644 --- a/doc/architecture/audio-video-calls.md +++ b/doc/architecture/audio-video-calls.md @@ -5,6 +5,10 @@ Ce document décrit l'architecture cible, l'implementation native actuelle et l'historique du transport direct. La préférence de confidentialité est persistée et éditable dans le profil. +PostIt conserve aussi trois activations de contact locales (audio, audio-video, +messages prives) et les annonce pour chaque connexion ChatHub, y compris apres +reconnexion. Ces activations ne filtrent pas encore les appels ni les messages : +elles ne constituent pas encore une protection de la vie privee. La signalisation est intégrée au chat, désactivée par défaut. Une page d'appel separee propose **WebRTC natif** et le transport direct VLC/SRTP sur Android et Desktop Linux. WebRTC utilise ICE/STUN/TURN et le masquage IP impose par la diff --git a/src/PostIt/PostIt.Tests/MessagingSessionTests.cs b/src/PostIt/PostIt.Tests/MessagingSessionTests.cs index 750a6cb79..418ba63d8 100644 --- a/src/PostIt/PostIt.Tests/MessagingSessionTests.cs +++ b/src/PostIt/PostIt.Tests/MessagingSessionTests.cs @@ -14,6 +14,7 @@ using PostIt.Services; using PostIt.ViewModels; using PostIt.ViewModels.Chat; using PostIt.Views; +using Yavsc.Abstract.Chat.Calls; namespace PostIt.Tests; @@ -308,6 +309,8 @@ public sealed class MessagingSessionTests await chat.JoinRoomCommand(); Assert.Equal(new[] { "first", "second" }, chat.JoinedRooms); var counter = server.Services.GetRequiredService(); + settings.AllowVideoCalls = false; + counter.ContactPreferences = null; counter.Context!.Abort(); var deadline = DateTime.UtcNow.AddSeconds(40); while (!counter.RoomsRejoined.Task.IsCompleted && DateTime.UtcNow < deadline) @@ -319,6 +322,7 @@ public sealed class MessagingSessionTests $"Connections={counter.Count}, transport={transport.Connection.State}, chat={chat.Status.Message}"); Assert.Equal(2, await transport.Connection.InvokeAsync("ConnectionCount")); Assert.Equal(new[] { "first", "second" }, counter.RejoinedRooms); + Assert.Equal(new ContactPreferences(true, false, true), counter.ContactPreferences); Platform.SuspendPlayback(); Assert.True(chat.IsConnected); @@ -366,7 +370,13 @@ public sealed class MessagingSessionTests var path = Path.Combine(Path.GetTempPath(), $"postit-chat-rooms-{Guid.NewGuid():N}"); try { - var settings = new Settings(path + ".settings") { ApiUrl = server.Urls.Single() + "/api/v1/" }; + var settings = new Settings(path + ".settings") + { + ApiUrl = server.Urls.Single() + "/api/v1/", + AllowAudioCalls = true, + AllowVideoCalls = false, + AllowPrivateMessages = false + }; settings.Authentication.Authority = "https://login.example.test"; var store = CreateStore(path); var jwt = "e30." + Convert.ToBase64String(Encoding.UTF8.GetBytes("{\"sub\":\"alice\"}")).TrimEnd('=') @@ -376,6 +386,8 @@ public sealed class MessagingSessionTests await using (var transport = new ChatHubConnection(api)) { await transport.StartAsync(TestContext.Current.CancellationToken); + Assert.Equal(new ContactPreferences(true, false, false), + server.Services.GetRequiredService().ContactPreferences); await transport.JoinAsync("SavedRoom", TestContext.Current.CancellationToken); Assert.Single(settings.ChatRoomsByAccount); } @@ -385,6 +397,8 @@ public sealed class MessagingSessionTests await using var resumedApi = new YavscApiClient(restored, store); await using var resumed = new ChatHubConnection(resumedApi); await resumed.StartAsync(TestContext.Current.CancellationToken); + Assert.Equal(new ContactPreferences(true, false, false), + server.Services.GetRequiredService().ContactPreferences); Assert.Equal(2, await resumed.Connection.InvokeAsync("ConnectionCount")); Assert.Equal("SavedRoom", Assert.Single(resumed.JoinedRooms).Name); Assert.Equal(new[] { "SavedRoom" }, server.Services.GetRequiredService().RejoinedRooms); @@ -437,12 +451,14 @@ public sealed class MessagingSessionTests { public int Count; public HubCallerContext? Context; + public ContactPreferences? ContactPreferences; public List RejoinedRooms { get; } = []; public TaskCompletionSource RoomsRejoined { get; } = new(TaskCreationOptions.RunContinuationsAsynchronously); } public sealed class TestChatHub(ConnectionCounter counter) : Hub { + public void SetContactPreferences(ContactPreferences preferences) => counter.ContactPreferences = preferences; public int ConnectionCount() => counter.Count; public ChatRoomInfo Join(string room) { diff --git a/src/PostIt/PostIt.Tests/SettingsLoadTests.cs b/src/PostIt/PostIt.Tests/SettingsLoadTests.cs index 415d256fe..565f0df30 100644 --- a/src/PostIt/PostIt.Tests/SettingsLoadTests.cs +++ b/src/PostIt/PostIt.Tests/SettingsLoadTests.cs @@ -5,6 +5,34 @@ namespace PostIt.Tests; [Trait("Category", "non-reg")] public class SettingsLoadTests { + [Fact] + public void Contact_options_survive_save_and_load_and_legacy_settings_keep_defaults() + { + var path = Path.Combine(Path.GetTempPath(), $"postit-contact-{Guid.NewGuid():N}.json"); + try + { + File.WriteAllText(path, "{}"); + var settings = new PostIt.ViewModels.Settings(path); + settings.Load(); + Assert.True(settings.AllowAudioCalls); + Assert.True(settings.AllowVideoCalls); + Assert.True(settings.AllowPrivateMessages); + + settings.AllowAudioCalls = false; + settings.AllowPrivateMessages = false; + Assert.True(settings.IsDirty); + settings.Save(); + + var restored = new PostIt.ViewModels.Settings(path); + restored.Load(); + Assert.False(restored.AllowAudioCalls); + Assert.True(restored.AllowVideoCalls); + Assert.False(restored.AllowPrivateMessages); + Assert.False(restored.IsDirty); + } + finally { File.Delete(path); } + } + /// /// On the dev machine, the user-level settings file /// (~/.config/PostIt/postit-settings.json) does not exist, so Load() diff --git a/src/PostIt/PostIt/Services/ChatHubConnection.cs b/src/PostIt/PostIt/Services/ChatHubConnection.cs index 8afbac353..d7a2886fc 100644 --- a/src/PostIt/PostIt/Services/ChatHubConnection.cs +++ b/src/PostIt/PostIt/Services/ChatHubConnection.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.SignalR.Client; using PostIt.ViewModels.Chat; using PostIt.Models; +using Yavsc.Abstract.Chat.Calls; namespace PostIt.Services; @@ -76,8 +77,20 @@ public sealed class ChatHubConnection : IAsyncDisposable RememberMessage(connection, message.Room, message.Name ?? "", message.Message ?? "")); connection.On("addPV", (sender, message) => RememberMessage(connection, null, sender, message)); - connection.Reconnected += _ => ReferenceEquals(Connection, connection) && IsCurrentConfiguration - ? RestoreRoomsAsync(connection, CancellationToken.None) : Task.CompletedTask; + connection.Reconnected += async _ => + { + if (!ReferenceEquals(Connection, connection) || !IsCurrentConfiguration) return; + try + { + await AnnounceContactPreferencesAsync(connection, CancellationToken.None); + await RestoreRoomsAsync(connection, CancellationToken.None); + } + catch (Exception ex) + { + ReportError($"Impossible d'annoncer les preferences de contact : {ex.Message}"); + await connection.StopAsync(); + } + }; return connection; } @@ -112,12 +125,26 @@ public sealed class ChatHubConnection : IAsyncDisposable if (Connection.State == HubConnectionState.Disconnected) { await Connection.StartAsync(ct); - await RestoreRoomsAsync(Connection, ct); + try + { + await AnnounceContactPreferencesAsync(Connection, ct); + await RestoreRoomsAsync(Connection, ct); + } + catch + { + await Connection.StopAsync(CancellationToken.None); + throw; + } } } finally { _gate.Release(); } } + private Task AnnounceContactPreferencesAsync(HubConnection connection, CancellationToken ct) => + connection.InvokeAsync(CallHubMethods.SetContactPreferences, + new ContactPreferences(_api.Settings.AllowAudioCalls, _api.Settings.AllowVideoCalls, + _api.Settings.AllowPrivateMessages), ct); + public async Task StopAsync(CancellationToken ct = default) { await _gate.WaitAsync(ct); diff --git a/src/PostIt/PostIt/ViewModels/Settings/Settings.cs b/src/PostIt/PostIt/ViewModels/Settings/Settings.cs index 81fd979bb..c261884f8 100644 --- a/src/PostIt/PostIt/ViewModels/Settings/Settings.cs +++ b/src/PostIt/PostIt/ViewModels/Settings/Settings.cs @@ -67,6 +67,12 @@ public partial class Settings : ViewModelBase [ObservableProperty] public partial string? LanCallAddress { get; set; } [ObservableProperty] + public partial bool AllowAudioCalls { get; set; } = true; + [ObservableProperty] + public partial bool AllowVideoCalls { get; set; } = true; + [ObservableProperty] + public partial bool AllowPrivateMessages { get; set; } = true; + [ObservableProperty] public partial bool AndroidKeepChatConnected { get; set; } [ObservableProperty] public partial bool ShareExceptionReports { get; set; } @@ -177,6 +183,9 @@ public partial class Settings : ViewModelBase partial void OnPodcastKeepScreenOnChanged(bool value) => MarkDirty(); partial void OnPodcastBlurBackgroundChanged(bool value) => MarkDirty(); partial void OnLanCallAddressChanged(string? value) => MarkDirty(); + partial void OnAllowAudioCallsChanged(bool value) => MarkDirty(); + partial void OnAllowVideoCallsChanged(bool value) => MarkDirty(); + partial void OnAllowPrivateMessagesChanged(bool value) => MarkDirty(); partial void OnAndroidKeepChatConnectedChanged(bool value) => MarkDirty(); partial void OnShareExceptionReportsChanged(bool value) => MarkDirty(); partial void OnChatRoomsByAccountChanged(Dictionary value) => MarkDirty(); @@ -445,6 +454,9 @@ public partial class Settings : ViewModelBase PodcastKeepScreenOn = settings.PodcastKeepScreenOn; PodcastBlurBackground = settings.PodcastBlurBackground; LanCallAddress = settings.LanCallAddress; + AllowAudioCalls = settings.AllowAudioCalls; + AllowVideoCalls = settings.AllowVideoCalls; + AllowPrivateMessages = settings.AllowPrivateMessages; AndroidKeepChatConnected = settings.AndroidKeepChatConnected; ShareExceptionReports = settings.ShareExceptionReports; ChatRoomsByAccount = settings.ChatRoomsByAccount ?? new(); diff --git a/src/PostIt/PostIt/Views/Layout/SettingsPage.axaml b/src/PostIt/PostIt/Views/Layout/SettingsPage.axaml index a4bb7ffe8..fcea45e48 100644 --- a/src/PostIt/PostIt/Views/Layout/SettingsPage.axaml +++ b/src/PostIt/PostIt/Views/Layout/SettingsPage.axaml @@ -49,6 +49,15 @@ + + + + + InviteCall(string roomName, string callee) => InviteCoreAsync(roomName, callee, CallTransports.WebRtc); diff --git a/src/Yavsc.Server/Services/CallSignalingService.cs b/src/Yavsc.Server/Services/CallSignalingService.cs index 978baf436..62ce36e1e 100644 --- a/src/Yavsc.Server/Services/CallSignalingService.cs +++ b/src/Yavsc.Server/Services/CallSignalingService.cs @@ -2,6 +2,7 @@ using System.Security.Cryptography; using System.Text; +using System.Collections.Concurrent; using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; @@ -33,8 +34,15 @@ public sealed class CallSignalingService( private readonly SemaphoreSlim _gate = new(1); private readonly Dictionary _calls = []; + private readonly ConcurrentDictionary _contactPreferences = new(); private readonly AudioVideoCallOptions _options = options.Value; + public void SetContactPreferences(string connection, ContactPreferences preferences) => + _contactPreferences[connection] = preferences; + + public ContactPreferences? GetContactPreferences(string connection) => + _contactPreferences.TryGetValue(connection, out var preferences) ? preferences : null; + public async Task InviteAsync( string room, string caller, string callee, string callerConnection, string[] calleeConnections, bool relayOnly, string transport = CallTransports.WebRtc) @@ -207,6 +215,7 @@ public sealed class CallSignalingService( public async Task DisconnectAsync(string connection) { + _contactPreferences.TryRemove(connection, out _); await _gate.WaitAsync(); try { diff --git a/src/test/Yavsc.Server.Tests/CallHubTests.cs b/src/test/Yavsc.Server.Tests/CallHubTests.cs index b71f0cbe8..1dab340f3 100644 --- a/src/test/Yavsc.Server.Tests/CallHubTests.cs +++ b/src/test/Yavsc.Server.Tests/CallHubTests.cs @@ -59,6 +59,24 @@ public sealed class CallHubTests } } + [Fact] + public async Task Contact_preferences_are_scoped_to_the_authenticated_connection_and_removed_on_disconnect() + { + using var f = new Fixture(); + using var alice = f.Hub("alice", "alice-1"); + using var spoof = f.Hub("bob", "alice-1"); + var preferences = new ContactPreferences(true, false, false); + + Assert.Throws(() => spoof.SetContactPreferences(preferences)); + Assert.Throws(() => alice.SetContactPreferences(null!)); + alice.SetContactPreferences(preferences); + Assert.Equal(preferences, f.Calls.GetContactPreferences("alice-1")); + Assert.Null(f.Calls.GetContactPreferences("bob-1")); + + await f.Calls.DisconnectAsync("alice-1"); + Assert.Null(f.Calls.GetContactPreferences("alice-1")); + } + [Fact] public async Task Lan_requires_https_at_invitation_acceptance_and_key_exchange() {