Add contact preferences announcement
Persist contact options and announce them on chat connection and reconnection. Prepare the audio-only call contract; enforcement and audio-only media remain unimplemented. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
0886b5e4e7
commit
9c4cce6840
11 changed files with 150 additions and 5 deletions
|
|
@ -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<ConnectionCounter>();
|
||||
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<int>("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<ConnectionCounter>().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<ConnectionCounter>().ContactPreferences);
|
||||
Assert.Equal(2, await resumed.Connection.InvokeAsync<int>("ConnectionCount"));
|
||||
Assert.Equal("SavedRoom", Assert.Single(resumed.JoinedRooms).Name);
|
||||
Assert.Equal(new[] { "SavedRoom" }, server.Services.GetRequiredService<ConnectionCounter>().RejoinedRooms);
|
||||
|
|
@ -437,12 +451,14 @@ public sealed class MessagingSessionTests
|
|||
{
|
||||
public int Count;
|
||||
public HubCallerContext? Context;
|
||||
public ContactPreferences? ContactPreferences;
|
||||
public List<string> 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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On the dev machine, the user-level settings file
|
||||
/// (~/.config/PostIt/postit-settings.json) does not exist, so Load()
|
||||
|
|
|
|||
|
|
@ -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<string, string>("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);
|
||||
|
|
|
|||
|
|
@ -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<string, string[]> 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();
|
||||
|
|
|
|||
|
|
@ -49,6 +49,15 @@
|
|||
<CheckBox Grid.Row="11" x:Name="DarkModeCheckBox" IsChecked="{Binding DarkMode, Mode=TwoWay}"/>
|
||||
|
||||
<StackPanel Grid.Row="12" Spacing="8">
|
||||
<TextBlock Text="Moyens de contact" FontWeight="SemiBold" />
|
||||
<CheckBox Content="Autoriser les appels audio"
|
||||
IsChecked="{Binding AllowAudioCalls, Mode=TwoWay}" />
|
||||
<CheckBox Content="Autoriser les appels audio-video"
|
||||
IsChecked="{Binding AllowVideoCalls, Mode=TwoWay}" />
|
||||
<CheckBox Content="Autoriser les messages prives"
|
||||
IsChecked="{Binding AllowPrivateMessages, Mode=TwoWay}" />
|
||||
<TextBlock Text="Ces preferences sont annoncees au serveur a la connexion et a la reconnexion. Leur application aux appels et aux messages n'est pas encore implementee ; elles ne bloquent donc pas les contacts."
|
||||
TextWrapping="Wrap" />
|
||||
<StackPanel IsVisible="{Binding SupportsBackgroundChatService}" Spacing="6">
|
||||
<CheckBox x:Name="BackgroundChatCheckBox"
|
||||
Content="Garder la connexion au serveur active et la reprendre au demarrage du telephone"
|
||||
|
|
|
|||
Loading…
Reference in a new issue