Skip to content

Commit

Permalink
fix #1233
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightczx committed Feb 19, 2024
1 parent d169f35 commit 7dec875
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,6 @@ private async ValueTask<bool> 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;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Snap.Hutao/Snap.Hutao/ViewModel/User/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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<AppDbContext>().Users.UpdateAndSave(inner);
Expand Down
14 changes: 11 additions & 3 deletions src/Snap.Hutao/Snap.Hutao/ViewModel/User/UserViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 7dec875

Please sign in to comment.