fix(mypage): populate unread_present_count from ViewerPresents

The home-screen crate button reads this count via MyPageTask (parsed
into Data.MyPage.data.unread_mail_count) and MyPageItemHome.cs:148
routes it into SetUnreadGiftCount to render the "N" bubble on the
gift button. It was hardcoded 0, so tutorial gifts (5 presents sitting
in the viewer's inbox after signup) showed no badge until the crate
was opened.

Add IViewerRepository.CountUnclaimedPresentsAsync and call it from
MyPageController.Index. Regression test seeds a viewer with tutorial
presents and asserts unread_present_count > 0.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-07-04 14:44:52 -04:00
parent c087f9b08f
commit 05d143d2e8
4 changed files with 39 additions and 1 deletions

View File

@@ -104,4 +104,12 @@ public interface IViewerRepository
/// Batch-loads owned guild-emblem ids for a viewer. Used by <c>/guild/emblem_list</c>.
/// </summary>
Task<List<long>> GetEmblemListAsync(long viewerId, CancellationToken ct = default);
/// <summary>
/// Counts the viewer's unclaimed <see cref="Models.ViewerPresent"/> rows. Drives
/// <c>/mypage/index.unread_present_count</c>, which the client casts to
/// <c>Data.MyPage.data.unread_mail_count</c> to render the home-screen crate badge
/// (MyPageItemHome.cs:148 → SetUnreadGiftCount).
/// </summary>
Task<int> CountUnclaimedPresentsAsync(long viewerId, CancellationToken ct = default);
}

View File

@@ -396,6 +396,13 @@ public class ViewerRepository : IViewerRepository
return viewer?.Emblems.Select(e => (long)e.Id).ToList() ?? new List<long>();
}
public Task<int> CountUnclaimedPresentsAsync(long viewerId, CancellationToken ct = default)
{
return _dbContext.Set<ViewerPresent>()
.Where(p => p.ViewerId == viewerId && p.Status == PresentStatus.Unclaimed)
.CountAsync(ct);
}
private async Task<Models.Viewer> BuildDefaultViewer(string displayName, int initialTutorialState = 1)
{
Models.Viewer viewer = new Models.Viewer