From d37ce2d38a2d594616b206272105dc6d52a6f251 Mon Sep 17 00:00:00 2001 From: Jason Dove <1695733+jasongdove@users.noreply.github.com> Date: Tue, 23 Jan 2024 13:10:52 -0600 Subject: [PATCH] update xmltv channel list on channel edit (#1570) --- CHANGELOG.md | 2 ++ .../Channels/Commands/CreateChannelHandler.cs | 16 +++++++------ .../Channels/Commands/UpdateChannelHandler.cs | 24 +++++++------------ 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e0f5bce..1707693f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Fix crop scale behavior with NVIDIA, QSV acceleration - Fix bug that corrupted uploaded images (watermarks, channel logos) - Re-uploading images should fix them +- Recreate XMLTV channel list (including logos) when channels are edited in ErsatzTV + - This bug caused the ErsatzTV logo to be used instead of channel logos in some cases ### Changed - Upgrade from .NET 7 to .NET 8 diff --git a/ErsatzTV.Application/Channels/Commands/CreateChannelHandler.cs b/ErsatzTV.Application/Channels/Commands/CreateChannelHandler.cs index 486bd132..b1a61e6e 100644 --- a/ErsatzTV.Application/Channels/Commands/CreateChannelHandler.cs +++ b/ErsatzTV.Application/Channels/Commands/CreateChannelHandler.cs @@ -1,33 +1,35 @@ using System.Globalization; using System.Text.RegularExpressions; +using System.Threading.Channels; using ErsatzTV.Core; using ErsatzTV.Core.Domain; using ErsatzTV.Core.Domain.Filler; using ErsatzTV.Infrastructure.Data; using ErsatzTV.Infrastructure.Extensions; using Microsoft.EntityFrameworkCore; +using Channel = ErsatzTV.Core.Domain.Channel; namespace ErsatzTV.Application.Channels; -public class CreateChannelHandler : IRequestHandler> +public class CreateChannelHandler( + ChannelWriter workerChannel, + IDbContextFactory dbContextFactory) + : IRequestHandler> { - private readonly IDbContextFactory _dbContextFactory; - - public CreateChannelHandler(IDbContextFactory dbContextFactory) => _dbContextFactory = dbContextFactory; - public async Task> Handle( CreateChannel request, CancellationToken cancellationToken) { - await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); + await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken); Validation validation = await Validate(dbContext, request); return await validation.Apply(c => PersistChannel(dbContext, c)); } - private static async Task PersistChannel(TvContext dbContext, Channel channel) + private async Task PersistChannel(TvContext dbContext, Channel channel) { await dbContext.Channels.AddAsync(channel); await dbContext.SaveChangesAsync(); + await workerChannel.WriteAsync(new RefreshChannelList()); return new CreateChannelResult(channel.Id); } diff --git a/ErsatzTV.Application/Channels/Commands/UpdateChannelHandler.cs b/ErsatzTV.Application/Channels/Commands/UpdateChannelHandler.cs index 43d7f990..db64d1bc 100644 --- a/ErsatzTV.Application/Channels/Commands/UpdateChannelHandler.cs +++ b/ErsatzTV.Application/Channels/Commands/UpdateChannelHandler.cs @@ -12,26 +12,18 @@ using Channel = ErsatzTV.Core.Domain.Channel; namespace ErsatzTV.Application.Channels; -public class UpdateChannelHandler : IRequestHandler> +public class UpdateChannelHandler( + ChannelWriter workerChannel, + IDbContextFactory dbContextFactory) + : IRequestHandler> { - private readonly IDbContextFactory _dbContextFactory; - private readonly ChannelWriter _workerChannel; - - public UpdateChannelHandler( - ChannelWriter workerChannel, - IDbContextFactory dbContextFactory) - { - _workerChannel = workerChannel; - _dbContextFactory = dbContextFactory; - } - public async Task> Handle( UpdateChannel request, CancellationToken cancellationToken) { - await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); + await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken); Validation validation = await Validate(dbContext, request); - return await LanguageExtensions.Apply(validation, c => ApplyUpdateRequest(dbContext, c, request)); + return await validation.Apply(c => ApplyUpdateRequest(dbContext, c, request)); } private async Task ApplyUpdateRequest(TvContext dbContext, Channel c, UpdateChannel update) @@ -85,9 +77,11 @@ public class UpdateChannelHandler : IRequestHandler