make UserGameRole observable

This commit is contained in:
qhy040404
2024-06-16 20:41:19 +08:00
parent 558551c8ad
commit 95d64c2895
3 changed files with 20 additions and 8 deletions

View File

@@ -24,6 +24,7 @@ internal sealed partial class UserInitializationService : IUserInitializationSer
private readonly IUserFingerprintService userFingerprintService;
private readonly IUidProfilePictureDbService uidProfilePictureDbService;
private readonly IServiceProvider serviceProvider;
private readonly ITaskContext taskContext;
public async ValueTask<ViewModel.User.User> ResumeUserAsync(Model.Entity.User inner, CancellationToken token = default)
{
@@ -70,9 +71,8 @@ internal sealed partial class UserInitializationService : IUserInitializationSer
EnkaClient enkaClient = scope.ServiceProvider
.GetRequiredService<EnkaClient>();
enkaResponse = await enkaClient
.GetForwardPlayerInfoAsync(userGameRole, token)
.ConfigureAwait(false);
enkaResponse = await enkaClient.GetForwardPlayerInfoAsync(userGameRole, token).ConfigureAwait(false)
?? await enkaClient.GetPlayerInfoAsync(userGameRole, token).ConfigureAwait(false);
}
if (enkaResponse is { PlayerInfo: { } playerInfo })
@@ -290,6 +290,8 @@ internal sealed partial class UserInitializationService : IUserInitializationSer
.ConfigureAwait(false);
}
await taskContext.SwitchToMainThreadAsync();
if (profilePicture.ProfilePictureId is not 0U)
{
userGameRole.ProfilePictureIcon = context.ProfilePictures

View File

@@ -300,8 +300,8 @@ internal sealed partial class UserViewModel : ObservableObject
}
[Command("RefreshProfilePictureCommand")]
private void RefreshProfilePicture(UserGameRole userGameRole)
private async Task RefreshProfilePictureAsync(UserGameRole userGameRole)
{
userService.RefreshProfilePictureAsync(userGameRole).SafeForget();
await userService.RefreshProfilePictureAsync(userGameRole).ConfigureAwait(false);
}
}

View File

@@ -1,14 +1,19 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using CommunityToolkit.Mvvm.ComponentModel;
using Snap.Hutao.Model.Metadata.Converter;
namespace Snap.Hutao.Web.Hoyolab.Takumi.Binding;
/// <summary>
/// 用户游戏角色
/// </summary>
[HighQuality]
internal sealed class UserGameRole
internal sealed class UserGameRole : ObservableObject
{
private string? profilePictureIcon;
/// <summary>
/// hk4e_cn for Genshin Impact
/// </summary>
@@ -57,8 +62,6 @@ internal sealed class UserGameRole
[JsonPropertyName("is_official")]
public bool IsOfficial { get; set; } = default!;
public string ProfilePictureIcon { get; set; } = default!;
/// <summary>
/// 玩家服务器与等级简述
/// </summary>
@@ -67,6 +70,13 @@ internal sealed class UserGameRole
get => $"{RegionName} | Lv.{Level}";
}
[JsonIgnore]
public string? ProfilePictureIcon
{
get => profilePictureIcon;
set => SetProperty(ref profilePictureIcon, value);
}
public static implicit operator PlayerUid(UserGameRole userGameRole)
{
return new PlayerUid(userGameRole.GameUid, userGameRole.Region);