From a543bf30911aed3ddbf1fd4fe84807acc19efb21 Mon Sep 17 00:00:00 2001 From: Xhichn Date: Wed, 15 Mar 2023 22:39:42 +0800 Subject: [PATCH] Fix dailynote notification for hoyoverse account, block some unsupported operations --- .../Snap.Hutao/Model/Binding/User/User.cs | 4 +-- .../Service/DailyNote/DailyNoteNotifier.cs | 32 +++++++++++++++---- .../GachaLogQueryStokenProvider.cs | 2 +- .../ViewModel/DailyNoteViewModel.cs | 14 ++++++-- .../Takumi/Event/Calculate/CalculateClient.cs | 2 +- 5 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Binding/User/User.cs b/src/Snap.Hutao/Snap.Hutao/Model/Binding/User/User.cs index 274137ec..b82c61fc 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Binding/User/User.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/Binding/User/User.cs @@ -106,8 +106,8 @@ internal sealed class User : ObservableObject User user = new(inner); bool isOk = false; - // TODO: 这里暂时使用是否存在 stoken 来判断是否为国际服,需要改进 - if (user.Entity.Stoken != null) + // TODO: need a flag to indentify hoyoverse account + if (user.Entity.Stoken != null) { isOk = await user.InitializeCoreAsync(token).ConfigureAwait(false); } diff --git a/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteNotifier.cs b/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteNotifier.cs index 8bf52e47..69f168ce 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteNotifier.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteNotifier.cs @@ -60,16 +60,15 @@ internal sealed class DailyNoteNotifier BindingClient bindingClient = scope.ServiceProvider.GetRequiredService(); AuthClient authClient = scope.ServiceProvider.GetRequiredService(); - Response actionTicketResponse = await authClient - .GetActionTicketByStokenAsync("game_role", entry.User) - .ConfigureAwait(false); - string? attribution = SH.ServiceDailyNoteNotifierAttribution; - if (actionTicketResponse.IsOk()) + + // TODO: need a flag to indentify hoyoverse account + // For global server, stoken is null + if (entry.User.Stoken == null) { Response> rolesResponse = await scope.ServiceProvider .GetRequiredService() - .GetUserGameRolesByActionTicketAsync(actionTicketResponse.Data.Ticket, entry.User) + .GetOsUserGameRolesByCookieAsync(entry.User) .ConfigureAwait(false); if (rolesResponse.IsOk()) @@ -77,6 +76,27 @@ internal sealed class DailyNoteNotifier List roles = rolesResponse.Data.List; attribution = roles.SingleOrDefault(r => r.GameUid == entry.Uid)?.ToString() ?? "Unkonwn"; } + + } + else + { + Response actionTicketResponse = await authClient + .GetActionTicketByStokenAsync("game_role", entry.User) + .ConfigureAwait(false); + + if (actionTicketResponse.IsOk()) + { + Response> rolesResponse = await scope.ServiceProvider + .GetRequiredService() + .GetUserGameRolesByActionTicketAsync(actionTicketResponse.Data.Ticket, entry.User) + .ConfigureAwait(false); + + if (rolesResponse.IsOk()) + { + List roles = rolesResponse.Data.List; + attribution = roles.SingleOrDefault(r => r.GameUid == entry.Uid)?.ToString() ?? "Unkonwn"; + } + } } ToastContentBuilder builder = new ToastContentBuilder() diff --git a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/QueryProvider/GachaLogQueryStokenProvider.cs b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/QueryProvider/GachaLogQueryStokenProvider.cs index 32b4fe45..701129c8 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/QueryProvider/GachaLogQueryStokenProvider.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/QueryProvider/GachaLogQueryStokenProvider.cs @@ -40,7 +40,7 @@ internal sealed class GachaLogQueryStokenProvider : IGachaLogQueryProvider { if (userAndUid.Uid.Region != "cn_gf01" && userAndUid.Uid.Region != "cn_qd01") { - return new(false, "Global server player is unsupported currently"); + return new(false, "Unsupported for hoyoverse account"); } GenAuthKeyData data = GenAuthKeyData.CreateForWebViewGacha(userAndUid.Uid); diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/DailyNoteViewModel.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/DailyNoteViewModel.cs index dace233f..e6740d4e 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/DailyNoteViewModel.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/DailyNoteViewModel.cs @@ -247,9 +247,17 @@ internal sealed class DailyNoteViewModel : Abstraction.ViewModel { if (UserAndUid.TryFromUser(userService.Current, out UserAndUid? userAndUid)) { - // ContentDialog must be created by main thread. - await ThreadHelper.SwitchToMainThreadAsync(); - await new DailyNoteVerificationDialog(userAndUid).ShowAsync(); + // TODO: Add verify support for oversea user + if (userAndUid.Uid.Region != "cn_gf01" || userAndUid.Uid.Region != "cn_qd01") + { + serviceProvider.GetRequiredService().Warning("Unsupported for hoyoverse account"); + } + else + { + // ContentDialog must be created by main thread. + await ThreadHelper.SwitchToMainThreadAsync(); + await new DailyNoteVerificationDialog(userAndUid).ShowAsync(); + } } else { diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/Calculate/CalculateClient.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/Calculate/CalculateClient.cs index 7c7bea40..940ee413 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/Calculate/CalculateClient.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/Calculate/CalculateClient.cs @@ -44,7 +44,7 @@ internal sealed class CalculateClient public async Task> ComputeAsync(Model.Entity.User user, AvatarPromotionDelta delta, CancellationToken token = default) { Response? resp; - // TODO 添加用于判断国际服用户的 flag + // TODO: need a flag to indentify hoyoverse account if (user.Stoken == null) { resp = await httpClient