daily card user remove aware

This commit is contained in:
DismissedLight
2024-07-05 17:28:33 +08:00
parent d133295599
commit 7f6430fe80
3 changed files with 13 additions and 4 deletions

View File

@@ -175,12 +175,11 @@ internal sealed partial class CachedImage : Microsoft.UI.Xaml.Controls.Control,
SourceName = Path.GetFileName(imageUri.ToString());
IImageCache imageCache = this.ServiceProvider().GetRequiredService<IImageCache>();
string file = default;
try
{
HutaoException.ThrowIf(string.IsNullOrEmpty(imageUri.Host), SH.ControlImageCachedImageInvalidResourceUri);
ElementTheme theme = ShowAsMonoChrome ? ThemeHelper.ApplicationToElement(ThemeHelper.ElementToApplication(ActualTheme)) : ElementTheme.Default;
file = await imageCache.GetFileFromCacheAsync(imageUri, theme).ConfigureAwait(true); // BitmapImage need to be created by main thread.
string file = await imageCache.GetFileFromCacheAsync(imageUri, theme).ConfigureAwait(true); // BitmapImage need to be created by main thread.
CachedName = Path.GetFileName(file);
token.ThrowIfCancellationRequested(); // check token state to determine whether the operation should be canceled.
return file.ToUri();
@@ -193,7 +192,6 @@ internal sealed partial class CachedImage : Microsoft.UI.Xaml.Controls.Control,
}
catch (Exception ex)
{
Debug.WriteLine(file);
Debug.WriteLine(ex);
return default;
}

View File

@@ -48,6 +48,8 @@
<cwc:SettingsCard MinHeight="40" Padding="0,0,16,0">
<cwc:SettingsCard.Resources>
<x:Double x:Key="SettingsCardLeftIndention">16</x:Double>
<x:Double x:Key="SettingsCardWrapThreshold">0</x:Double>
<x:Double x:Key="SettingsCardWrapNoIconThreshold">0</x:Double>
</cwc:SettingsCard.Resources>
<cwc:SettingsCard.Header>
<TextBlock Text="{Binding Name}" TextWrapping="NoWrap"/>

View File

@@ -1,11 +1,13 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using CommunityToolkit.Mvvm.Messaging;
using Snap.Hutao.Core.ExceptionService;
using Snap.Hutao.Model.Entity;
using Snap.Hutao.Service.DailyNote;
using Snap.Hutao.Service.Metadata;
using Snap.Hutao.Service.Notification;
using Snap.Hutao.Service.User;
using Snap.Hutao.UI.Xaml.View.Page;
using System.Collections.ObjectModel;
@@ -16,7 +18,7 @@ namespace Snap.Hutao.ViewModel.DailyNote;
/// </summary>
[Injection(InjectAs.Transient)]
[ConstructorGenerated(CallBaseConstructor = true)]
internal sealed partial class DailyNoteViewModelSlim : Abstraction.ViewModelSlim<DailyNotePage>
internal sealed partial class DailyNoteViewModelSlim : Abstraction.ViewModelSlim<DailyNotePage>, IRecipient<UserRemovedMessage>
{
private readonly ITaskContext taskContext;
private readonly IInfoBarService infoBarService;
@@ -30,6 +32,13 @@ internal sealed partial class DailyNoteViewModelSlim : Abstraction.ViewModelSlim
/// </summary>
public List<DailyNoteEntry>? DailyNoteEntries { get => dailyNoteEntries; set => SetProperty(ref dailyNoteEntries, value); }
public void Receive(UserRemovedMessage message)
{
HashSet<string> removedUids = message.RemovedUser.UserGameRoles.SourceCollection.Select(role => role.GameUid).ToHashSet();
List<DailyNoteEntry>? entries = DailyNoteEntries?.Where(entry => !removedUids.Contains(entry.Uid)).ToList();
taskContext.BeginInvokeOnMainThread(() => { DailyNoteEntries = entries; });
}
/// <inheritdoc/>
protected override async Task LoadAsync()
{