Files
LlamaCasty/ViewModels/MainViewModel.Ypp.cs
T
gramps 0fade9702b feat(ypp): session report derived from YouTube — no ledger, money off by default (TASK 3·20)
The task asked for a `RewardEvents` table plus a backfill. That would have contradicted the published
promise that no viewer, member or donor information is retained after the session ends, and it would
have meant owning a ledger that YouTube already keeps.

So the report is DERIVED on demand instead:

- `Services/SuperChatEventService.cs` — `superChatEvents.list`, parsed for both event types (a sticker
  must not be dropped), authorised by the existing `auth/youtube` scope, so no re-consent.
- `Models/SessionRewardSummary.cs` — rolls events up for the session window with **per-currency totals
  that are never summed together** (a $5 and a €5 are not $10). Nothing is written down.
- The YPP drawer gains a **THIS SESSION** section: counts are neutral and always shown when there were
  events; money appears only when the creator asks for it. `Show monetary metrics` is a drawer toggle,
  persisted, **off by default** — a creator who never monetized is never shown a $0.00.

Also: money is labelled as estimates (removed/refunded events are excluded and totals can be restated
for weeks, not days).

Tests: `SessionRewardReportTests` — both reward types parse, the window makes it a session rather than
a channel report, currencies stay separate, an empty session shows nothing, a sticker-only session
still counts. `BackOnAirTests` moves into the serialised `MainViewModelLayoutPath` collection: it builds
a MainViewModel directly and was flaking against parallel tests that swap the static layout path.

FAST gate: 557 passed, 0 failed, 0 warnings.
2026-11-05 15:38:32 -08:00

69 lines
2.8 KiB
C#

using ytLive.Services;
namespace ytLive.ViewModels;
public partial class MainViewModel
{
/// <summary>Test seam (mirrors CameraEnumeratorOverride): tests inject a fake
/// stats service before constructing the VM so refresh never hits the network.</summary>
internal static Func<ChannelStatsService>? ChannelStatsFactoryOverride { get; set; }
/// <summary>The YPP pull-out backing VM — the drawer below Stream Settings
/// on the Live screen's right edge (TASK 39).</summary>
public Services.YppTrackerViewModel Ypp { get; private set; } = null!;
/// <summary>The Test Stream pull-out backing VM — the TEST drawer at the
/// bottom of the right rail (TASK 41): mock chat input (real insert →
/// poll round-trip) + locally-simulated member / SuperChat / subscriber rows.</summary>
public Services.TestSessionViewModel TestSession { get; private set; } = null!;
private void InitYpp()
{
Ypp = new YppTrackerViewModel(
() => _layoutStore,
() => ChannelStatsFactoryOverride?.Invoke() ?? new ChannelStatsService(_youtubeAuth),
() => IsConnected,
() => _youtubeAuth.CurrentChannel?.DisplayName,
rewardEvents: () => new SuperChatEventService(_youtubeAuth),
channelId: () => _youtubeAuth.CurrentChannel?.ChannelId,
sessionStartedAtUtc: () => _sessionStartedAtUtc);
TestSession = new TestSessionViewModel(
_youtubeStream,
_youtubeChat,
onEndStream: StopStream);
// One drawer at a time: the three pull-outs share the preview's right edge,
// so opening one collapses the other two (all directions).
BroadcastForm.PropertyChanged += (_, e) =>
{
if (e.PropertyName == nameof(LiveBroadcastFormViewModel.IsDrawerOpen) && BroadcastForm.IsDrawerOpen)
{
Ypp.IsDrawerOpen = false;
TestSession.IsDrawerOpen = false;
CloseSocialsDrawer();
CloseSettingsDrawerIfOpen();
}
};
Ypp.PropertyChanged += (_, e) =>
{
if (e.PropertyName == nameof(YppTrackerViewModel.IsDrawerOpen) && Ypp.IsDrawerOpen)
{
BroadcastForm.IsDrawerOpen = false;
TestSession.IsDrawerOpen = false;
CloseSocialsDrawer();
CloseSettingsDrawerIfOpen();
}
};
TestSession.PropertyChanged += (_, e) =>
{
if (e.PropertyName == nameof(TestSessionViewModel.IsDrawerOpen) && TestSession.IsDrawerOpen)
{
BroadcastForm.IsDrawerOpen = false;
Ypp.IsDrawerOpen = false;
CloseSocialsDrawer();
CloseSettingsDrawerIfOpen();
}
};
}
}