feat(ads): VK post-move interstitial + retire deprecated hint_balance/paid_account
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 10s
CI / integration (pull_request) Successful in 23s
CI / ui (pull_request) Successful in 1m12s
CI / conformance (pull_request) Successful in 9s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m53s

Interstitial video after a confirmed play or a hint, VK-only, offline
banner-only. The gate is client-mirrored: the backend puts the config
cooldowns (global 5m / vs_ai 30m / hint 1m) and a suppressed flag (the
no-ads / no_banner gate, same as the banner) on Profile.ads via adsFor;
the client self-gates on a per-kind last-shown time in localStorage, with
the VITE_ADS_STUB contour "ad fired" toast. Never fires after a pass,
exchange or resign. maybeShowInterstitial + vkShowInterstitial; the codec
and gateway transcode carry the ads block.

Also retires the deprecated accounts.hint_balance / paid_account domain
usage (expand-contract, code only — the columns stay for a later DROP so
image rollback stays DB-safe): drop the Account fields and their scan, the
dead account.SpendHint, account.GrantHints and the admin grant-hints
action; the in-game hint display now comes wholly from the payments hint
benefit. Banner eligibility and account merge no longer read the legacy
flags.

Tests: ads.test.ts (the client-mirrored gate), the codec ads round-trip,
the gateway ads transcode test, and a profile ads-config integration test
(cooldowns + suppressed under no-ads / no_banner). Docs: PAYMENTS §10 (+ru)
interstitial, the decision amends, backend README, the plan.
This commit is contained in:
Ilia Denisov
2026-07-10 02:48:10 +02:00
parent e08d3301bd
commit 13be7c3d9a
33 changed files with 805 additions and 220 deletions
+13
View File
@@ -184,6 +184,16 @@ func encodeProfile(p backendclient.ProfileResp) []byte {
}
prefs := buildStringVector(b, p.VariantPreferences, fb.ProfileStartVariantPreferencesVector)
dictVersions := encodeDictVersions(b, p.DictVersions)
// The interstitial-ad config table (scalars only), built before Profile is opened.
var ads flatbuffers.UOffsetT
if p.Ads != nil {
fb.AdsInfoStart(b)
fb.AdsInfoAddCooldownGlobalS(b, int32(p.Ads.CooldownGlobalS))
fb.AdsInfoAddCooldownVsAiS(b, int32(p.Ads.CooldownVsAiS))
fb.AdsInfoAddCooldownHintS(b, int32(p.Ads.CooldownHintS))
fb.AdsInfoAddSuppressed(b, p.Ads.Suppressed)
ads = fb.AdsInfoEnd(b)
}
fb.ProfileStart(b)
fb.ProfileAddUserId(b, uid)
fb.ProfileAddDisplayName(b, name)
@@ -206,6 +216,9 @@ func encodeProfile(p backendclient.ProfileResp) []byte {
if p.Banner != nil {
fb.ProfileAddBanner(b, banner)
}
if p.Ads != nil {
fb.ProfileAddAds(b, ads)
}
b.Finish(fb.ProfileEnd(b))
return b.FinishedBytes()
}
@@ -0,0 +1,65 @@
package transcode_test
import (
"context"
"net/http"
"testing"
"scrabble/gateway/internal/transcode"
fb "scrabble/pkg/fbs/scrabblefb"
)
// TestProfileGetEncodesAds verifies the gateway forwards the backend's interstitial-ad block
// into the Profile payload: the three cooldowns and the suppressed flag the client-mirrored gate
// reads. The encode is not exercised by the mock e2e (it bypasses the codec), so a dropped field
// would only surface here.
func TestProfileGetEncodesAds(t *testing.T) {
backend, cleanup := fakeBackend(t, func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet || r.URL.Path != "/api/v1/user/profile" {
t.Errorf("unexpected %s %q", r.Method, r.URL.Path)
}
_, _ = w.Write([]byte(`{"user_id":"u-1","display_name":"Kaya","preferred_language":"en",` +
`"ads":{"cooldown_global_s":300,"cooldown_vs_ai_s":1800,"cooldown_hint_s":60,"suppressed":true}}`))
})
defer cleanup()
reg := transcode.NewRegistry(backend, nil)
op, ok := reg.Lookup(transcode.MsgProfileGet)
if !ok {
t.Fatal("profile.get not registered")
}
payload, err := op.Handler(context.Background(), transcode.Request{UserID: "u-1"})
if err != nil {
t.Fatalf("handler: %v", err)
}
ads := fb.GetRootAsProfile(payload, 0).Ads(nil)
if ads == nil {
t.Fatal("profile carries no ads block")
}
if ads.CooldownGlobalS() != 300 || ads.CooldownVsAiS() != 1800 || ads.CooldownHintS() != 60 {
t.Errorf("cooldowns = %d/%d/%d, want 300/1800/60", ads.CooldownGlobalS(), ads.CooldownVsAiS(), ads.CooldownHintS())
}
if !ads.Suppressed() {
t.Error("suppressed = false, want true")
}
}
// TestProfileGetNoAds verifies a profile without an ads block encodes none (the backend omits it
// only on an internal failure; normally the block is always present).
func TestProfileGetNoAds(t *testing.T) {
backend, cleanup := fakeBackend(t, func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(`{"user_id":"u-1","display_name":"Kaya","preferred_language":"en"}`))
})
defer cleanup()
reg := transcode.NewRegistry(backend, nil)
op, _ := reg.Lookup(transcode.MsgProfileGet)
payload, err := op.Handler(context.Background(), transcode.Request{UserID: "u-1"})
if err != nil {
t.Fatalf("handler: %v", err)
}
if p := fb.GetRootAsProfile(payload, 0); p.Ads(nil) != nil {
t.Error("profile without an ads block unexpectedly carries one")
}
}