From d86ea87d59765a768c824fd1ad9a4d8922044b72 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sun, 22 Nov 2026 23:19:45 +0000 Subject: [PATCH] fix(postit): preserve newly created blog posts Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- CHANGELOG.md | 2 ++ .../PostIt.Tests/PostItViewModelTests.cs | 26 +++++++++++++++++++ .../PostIt/ViewModels/Blogs/BlogsViewModel.cs | 26 +++++++++++++------ .../Layout/ActionStatusViewModelExtensions.cs | 7 +---- src/Yavsc.Server/Helpers/PayloadHelpers.cs | 2 ++ src/Yavsc.Server/Services/BlogSpotService.cs | 1 + src/test/Yavsc.Blogs.Tests/BlogApiTests.cs | 2 ++ 7 files changed, 52 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 164899d03..7dcf4a68f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,8 @@ ### Fixed +* [PostIt/Blogs] Keep a newly created post readable when its creation response temporarily omits author details, and include the author in server-side create/detail payloads so relative resource URLs can be resolved after save. + * [PostIt/Capture] Automatically upload finalized screen recordings as `video/mp4` to `Mes fichiers / screencast`, streaming the multipart file from disk and retaining the local copy if the upload fails. * [PostIt/Capture] Decode the PipeWire node identifier from the ScreenCast portal `streams` array of `(node id, properties)` structures, let the user choose a full screen, a window or the portal picker, and mux system audio from the default output monitor into the H.264/AAC MP4. Stop GStreamer with SIGINT so the muxer receives EOS and writes a valid `moov` atom. diff --git a/src/PostIt/PostIt.Tests/PostItViewModelTests.cs b/src/PostIt/PostIt.Tests/PostItViewModelTests.cs index 9c20f5c51..9c1b51f89 100644 --- a/src/PostIt/PostIt.Tests/PostItViewModelTests.cs +++ b/src/PostIt/PostIt.Tests/PostItViewModelTests.cs @@ -1,6 +1,7 @@ using Avalonia.Controls; using Avalonia.Threading; using Avalonia.VisualTree; +using PostIt.Models; using Yavsc.Blogspot; using Yavsc.Api.Client; using PostIt.Services; @@ -102,6 +103,31 @@ public class PostItViewModelTests(AvaloniaUiFixture ui) Assert.False(vm.IsBusy); } + [Fact] + public async Task Creating_post_without_author_keeps_article_readable_and_success_status() + { + var recorder = new CallRecorder(); + var vm = new BlogsViewModel(new BlogApiClient(new RecordingYavscApiClient(recorder), + "https://blogs.example.test/api/v1/"), + new Settings + { + Authentication = new AuthenticationSettings + { + Authority = "https://org.example.test" + } + }); + vm.DraftTitle = "Nouveau billet"; + vm.DraftArticle = "Contenu lisible."; + + await vm.SaveAsync(); + + Assert.NotNull(vm.SelectedPost); + Assert.Equal("Contenu lisible.", vm.ReaderArticle); + Assert.Null(vm.ReaderBaseUrl); + Assert.Equal(StatusSeverity.Info, vm.ActionStatus.Severity); + Assert.Equal("Billet 42 créé.", vm.StatusMessage); + } + [Fact] public Task Published_badge_tracks_post_publication_state() => ui.RunAsync(() => diff --git a/src/PostIt/PostIt/ViewModels/Blogs/BlogsViewModel.cs b/src/PostIt/PostIt/ViewModels/Blogs/BlogsViewModel.cs index 94fcbb826..2ddbfb1a6 100644 --- a/src/PostIt/PostIt/ViewModels/Blogs/BlogsViewModel.cs +++ b/src/PostIt/PostIt/ViewModels/Blogs/BlogsViewModel.cs @@ -156,7 +156,7 @@ public partial class BlogsViewModel : ViewModelBase, IActionStatusViewModel [ObservableProperty] public partial string? ReaderBaseUrl { get; private set; } - public string ReaderArticle => ReaderBaseUrl is not null ? SelectedPost?.Article ?? string.Empty : string.Empty; + public string ReaderArticle => SelectedPost?.Article ?? string.Empty; public string ReaderAuthor => SelectedPost?.Author?.UserName ?? string.Empty; public string ReaderTitle => SelectedPost?.Title ?? string.Empty; public DateTime? ReaderDateModified => SelectedPost?.DateModified; @@ -647,15 +647,17 @@ public partial class BlogsViewModel : ViewModelBase, IActionStatusViewModel private void UpdateReader() { string? baseUrl = null; - try + if (SelectedPost is not null && !string.IsNullOrWhiteSpace(ReaderAuthor)) { - if (SelectedPost is not null) + try + { baseUrl = BlogResourceService.GetUserBaseUri( Settings.Authentication.Authority, ReaderAuthor).AbsoluteUri; - } - catch (Exception ex) when (ex is ArgumentException or InvalidOperationException or UriFormatException) - { - this.SetErrorStatus($"Impossible de résoudre les ressources du billet : {ex.Message}"); + } + catch (Exception ex) when (ex is ArgumentException or InvalidOperationException or UriFormatException) + { + this.SetErrorStatus($"Impossible de résoudre les ressources du billet : {ex.Message}"); + } } ReaderBaseUrl = baseUrl; OnPropertyChanged(nameof(SelectedPost)); @@ -719,7 +721,15 @@ public partial class BlogsViewModel : ViewModelBase, IActionStatusViewModel .OrderByDescending(p => p.DateModified); var selection = SelectedPost; - var visiblePosts = filtered.Select(post => post.Id == selection?.Id ? selection : post).ToArray(); + if (selection is { Id: > 0, Author: null }) + { + var hydratedSelection = Posts.FirstOrDefault(post => + post.Id == selection.Id && post.Author is not null); + if (hydratedSelection is not null) + selection = hydratedSelection; + } + + var visiblePosts = filtered.Select(post => post.Id == selection?.Id ? selection! : post).ToArray(); _preserveDraft = true; try { diff --git a/src/PostIt/PostIt/ViewModels/Layout/ActionStatusViewModelExtensions.cs b/src/PostIt/PostIt/ViewModels/Layout/ActionStatusViewModelExtensions.cs index 089d84ef5..89063a348 100644 --- a/src/PostIt/PostIt/ViewModels/Layout/ActionStatusViewModelExtensions.cs +++ b/src/PostIt/PostIt/ViewModels/Layout/ActionStatusViewModelExtensions.cs @@ -1,4 +1,3 @@ -using Microsoft.Extensions.DependencyInjection; using PostIt.Models; using PostIt.Services; @@ -34,10 +33,6 @@ public static class ActionStatusViewModelExtensions viewModel.StatusMessage = normalizedMessage; viewModel.ActionStatus = statusNotice; - if (App.Current is App app && app.ServiceProvider is { } serviceProvider) - { - var notificationService = serviceProvider.GetRequiredService(); - notificationService.Post(normalizedMessage, severity); - } + NotificationService.Instance.Post(normalizedMessage, severity); } } diff --git a/src/Yavsc.Server/Helpers/PayloadHelpers.cs b/src/Yavsc.Server/Helpers/PayloadHelpers.cs index cd359bb45..1d701bad5 100644 --- a/src/Yavsc.Server/Helpers/PayloadHelpers.cs +++ b/src/Yavsc.Server/Helpers/PayloadHelpers.cs @@ -1,4 +1,5 @@ using Yavsc.Models.Blog; +using Yavsc.Blogspot; public static class PayloadHelpers { @@ -14,6 +15,7 @@ public static class PayloadHelpers post.DateModified, post.UserModified, post.AuthorId, + Author = ((IBlogPost)post).Author, ACL = post.GetACL(), Tags = post.GetTags(), post.IsPublished diff --git a/src/Yavsc.Server/Services/BlogSpotService.cs b/src/Yavsc.Server/Services/BlogSpotService.cs index 49e351297..0f9a42b91 100644 --- a/src/Yavsc.Server/Services/BlogSpotService.cs +++ b/src/Yavsc.Server/Services/BlogSpotService.cs @@ -110,6 +110,7 @@ public class BlogSpotService // Sauvegarder le post d'abord pour obtenir son ID // Le créateur vient de l'authentification, donc on ne le prend pas du post post.AuthorId = userId; + post.Author = _context.Users.Single(u => u.Id == userId); _context.BlogSpot.Add(post); _context.SaveChanges(userId); // A freshly created post has no BlogSpotPublication row, diff --git a/src/test/Yavsc.Blogs.Tests/BlogApiTests.cs b/src/test/Yavsc.Blogs.Tests/BlogApiTests.cs index 9f1e1598e..b0903c9e2 100644 --- a/src/test/Yavsc.Blogs.Tests/BlogApiTests.cs +++ b/src/test/Yavsc.Blogs.Tests/BlogApiTests.cs @@ -191,6 +191,8 @@ public sealed class BlogApiTests : IClassFixture ); Assert.NotNull(created); Assert.Equal("tester", created!.AuthorId); + Assert.NotNull(created.Author); + Assert.Equal("tester", created.Author.UserName); var listResponse = await http.GetAsync(_fixture.BlogSpotUrl(), TestContext.Current.CancellationToken);