Story leader fixes
This commit is contained in:
@@ -250,33 +250,31 @@ public class StoryService : IStoryService
|
||||
}
|
||||
public async Task<LeaderSelectResponse> GetLeaderSelectAsync(StoryApiType apiType, int sectionId, long viewerId)
|
||||
{
|
||||
// For section's chara list we use a fixed 1-8 enumeration for leader-select sections.
|
||||
// Non-leader-select sections are not expected to call this endpoint; returning leader_count=8
|
||||
// matches the client's default sentinel.
|
||||
var resp = new LeaderSelectResponse { LeaderCount = 8 };
|
||||
var charaIds = new[] { 1, 2, 3, 4, 5, 6, 7, 8 };
|
||||
// Leader list comes from whatever chara_ids the section's chapter catalog actually contains —
|
||||
// NOT a fixed 1..8 enumeration. Sections in prod range from standard class subsets
|
||||
// (e.g. section 5: charas 3,5,6,8) to custom-leader sections (e.g. section 17: chara_ids
|
||||
// 500901-500904). Order is by ascending min(story_id) per chara, which reproduces prod's
|
||||
// ordering for every captured section (including section 17's 500901,500903,500904,500902
|
||||
// and section 15's 500701,500732,500704). Verified against traffic_prod_626_story.ndjson.
|
||||
var chapters = await _master.GetChaptersBySectionsAsync(new[] { sectionId });
|
||||
var charaGroups = chapters
|
||||
.GroupBy(c => c.CharaId)
|
||||
.Select(g => (CharaId: g.Key, Chapters: g.ToList(), MinStoryId: g.Min(c => c.StoryId)))
|
||||
.OrderBy(g => g.MinStoryId)
|
||||
.ToList();
|
||||
|
||||
// Pre-collect all story_ids across charas in this section to do one progress query.
|
||||
var perCharaChapters = new Dictionary<int, List<StoryChapter>>();
|
||||
foreach (var c in charaIds)
|
||||
{
|
||||
perCharaChapters[c] = await _master.GetChaptersBySectionCharaAsync(sectionId, c);
|
||||
}
|
||||
var allStoryIds = perCharaChapters.SelectMany(kv => kv.Value).Select(c => c.StoryId).ToList();
|
||||
var resp = new LeaderSelectResponse { LeaderCount = charaGroups.Count };
|
||||
if (charaGroups.Count == 0) return resp;
|
||||
|
||||
var allStoryIds = chapters.Select(c => c.StoryId).ToList();
|
||||
var progress = await _viewer.GetProgressForChaptersAsync(viewerId, allStoryIds);
|
||||
|
||||
foreach (var c in charaIds)
|
||||
foreach (var (charaId, chaps, _) in charaGroups)
|
||||
{
|
||||
var chapters = perCharaChapters[c];
|
||||
if (chapters.Count == 0)
|
||||
{
|
||||
resp.LeaderList.Add(new LeaderEntry { CharaId = c, CurrentChapter = 1 });
|
||||
continue;
|
||||
}
|
||||
int highest = 0;
|
||||
bool anySkipped = false;
|
||||
int clearedCount = 0;
|
||||
foreach (var ch in chapters)
|
||||
foreach (var ch in chaps)
|
||||
{
|
||||
if (progress.TryGetValue(ch.StoryId, out var p) && (p.IsFinish || p.IsSkipped))
|
||||
{
|
||||
@@ -288,9 +286,9 @@ public class StoryService : IStoryService
|
||||
}
|
||||
resp.LeaderList.Add(new LeaderEntry
|
||||
{
|
||||
CharaId = c,
|
||||
CharaId = charaId,
|
||||
IsSkipped = anySkipped,
|
||||
IsFinished = clearedCount == chapters.Count,
|
||||
IsFinished = clearedCount == chaps.Count,
|
||||
CurrentChapter = (highest == 0) ? 1 : highest + 1,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user