From 7e6f840fe86c7df2025e5beb7beb64bd72e2a901 Mon Sep 17 00:00:00 2001 From: Athul Raj Date: Fri, 14 Jun 2024 19:42:56 +0530 Subject: [PATCH] fix not getting all of users anime --- .../MyAnimeList/MyAnimeListTrackingService.cs | 50 +++++++++++++------ 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/Totoro.Core/Services/MyAnimeList/MyAnimeListTrackingService.cs b/Totoro.Core/Services/MyAnimeList/MyAnimeListTrackingService.cs index 4fe122d..ea96f4f 100644 --- a/Totoro.Core/Services/MyAnimeList/MyAnimeListTrackingService.cs +++ b/Totoro.Core/Services/MyAnimeList/MyAnimeListTrackingService.cs @@ -66,28 +66,46 @@ public async IAsyncEnumerable GetAnime() } var result = await _client.Anime() - .OfUser() - .IncludeNsfw() - .WithFields(_fieldNames) - .Find(); + .OfUser() + .IncludeNsfw() + .WithFields(_fieldNames) + .Find(); - foreach (var item in result.Data) + foreach (var item in ConvertAndFill(result.Data)) { - var model = ConvertModel(item); + yield return item; + } - if (model.Tracking.Status == AnimeStatus.Watching && model.AiringStatus == AiringStatus.CurrentlyAiring) + while (!string.IsNullOrEmpty(result.Paging?.Next)) + { + result = await _client.GetNextAnimePage(result); + + foreach (var item in ConvertAndFill(result.Data)) { - Observable - .FromAsync(_ => _anilistService.GetNextAiringEpisode(item.Id), RxApp.TaskpoolScheduler) - .ObserveOn(RxApp.MainThreadScheduler) - .Subscribe(x => - { - model.AiredEpisodes = x.Episode - 1 ?? 0; - model.NextEpisodeAt = x.Time; - }); + yield return item; } + } - yield return model; + IEnumerable ConvertAndFill(IEnumerable anime) + { + foreach (var item in anime) + { + var model = ConvertModel(item); + + if (model.Tracking.Status == AnimeStatus.Watching && model.AiringStatus == AiringStatus.CurrentlyAiring) + { + Observable + .FromAsync(_ => _anilistService.GetNextAiringEpisode(item.Id), RxApp.TaskpoolScheduler) + .ObserveOn(RxApp.MainThreadScheduler) + .Subscribe(x => + { + model.AiredEpisodes = x.Episode - 1 ?? 0; + model.NextEpisodeAt = x.Time; + }); + } + + yield return model; + } } }