From 7dec87586be7977823962c2a3e5aa00865ae9578 Mon Sep 17 00:00:00 2001 From: Lightczx <1686188646@qq.com> Date: Mon, 19 Feb 2024 11:33:27 +0800 Subject: [PATCH] fix #1233 --- .../Service/User/UserInitializationService.cs | 11 ----------- src/Snap.Hutao/Snap.Hutao/ViewModel/User/User.cs | 6 +++--- .../Snap.Hutao/ViewModel/User/UserViewModel.cs | 14 +++++++++++--- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/Snap.Hutao/Snap.Hutao/Service/User/UserInitializationService.cs b/src/Snap.Hutao/Snap.Hutao/Service/User/UserInitializationService.cs index 3c599f99d2..3f551ae76f 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/User/UserInitializationService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/User/UserInitializationService.cs @@ -90,17 +90,6 @@ private async ValueTask InitializeUserAsync(ViewModel.User.User user, Canc await userFingerprintService.TryInitializeAsync(user, token).ConfigureAwait(false); - // Should not raise propery changed event below - if (user.PerferredUid is not null) - { - user.SetSelectedUserGameRole(user.UserGameRoles.FirstOrDefault(role => role.GameUid == user.PerferredUid), false); - } - - if (user.SelectedUserGameRole is null) - { - user.SetSelectedUserGameRole(user.UserGameRoles.FirstOrFirstOrDefault(role => role.IsChosen), false); - } - return user.IsInitialized = true; } diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/User/User.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/User/User.cs index d36096cb1b..99c420953b 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/User/User.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/User/User.cs @@ -96,7 +96,7 @@ public Cookie? SToken public bool NeedDbUpdateAfterResume { get; set; } - public string? PerferredUid { get => inner.PreferredUid; } + public string? PreferredUid { get => inner.PreferredUid; } public static User From(EntityUser user, IServiceProvider provider) { @@ -107,9 +107,9 @@ public void SetSelectedUserGameRole(UserGameRole? value, bool raiseMessage = tru { if (SetProperty(ref selectedUserGameRole, value, nameof(SelectedUserGameRole))) { - if (inner.PreferredUid != value?.GameUid) + if (value is not null && inner.PreferredUid != value.GameUid) { - inner.PreferredUid = value?.GameUid; + inner.PreferredUid = value.GameUid; using (IServiceScope scope = serviceProvider.CreateScope()) { scope.ServiceProvider.GetRequiredService().Users.UpdateAndSave(inner); diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/User/UserViewModel.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/User/UserViewModel.cs index 8459a6ed81..6b853216b6 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/User/UserViewModel.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/User/UserViewModel.cs @@ -53,10 +53,18 @@ public User? SelectedUser get => selectedUser ??= userService.Current; set { - if (value is { SelectedUserGameRole: null }) + if (value is not null) { - // Pre select the chosen role to avoid multiple UserChangedMessage - value.SetSelectedUserGameRole(value.UserGameRoles.FirstOrFirstOrDefault(role => role.IsChosen), false); + // Should not raise propery changed event below + if (value.PreferredUid is not null) + { + value.SetSelectedUserGameRole(value.UserGameRoles.FirstOrDefault(role => role.GameUid == value.PreferredUid), false); + } + + if (value.SelectedUserGameRole is null) + { + value.SetSelectedUserGameRole(value.UserGameRoles.FirstOrFirstOrDefault(role => role.IsChosen), false); + } } if (SetProperty(ref selectedUser, value))