feat(ui): per-kind active-game limit lock on the New Game screen
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 12s
CI / integration (pull_request) Successful in 28s
CI / ui (pull_request) Successful in 1m11s
CI / conformance (pull_request) Successful in 10s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m46s
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 12s
CI / integration (pull_request) Successful in 28s
CI / ui (pull_request) Successful in 1m11s
CI / conformance (pull_request) Successful in 10s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m46s
Carry the caller's per-tier active-game caps and each game's kind on the wire (Profile.game_limits + GameView.kind, additive FBS + gateway transcode + client codec, committed regen). The New Game screen counts the player's active games per kind from the lobby and locks a capped start: an outline button with a lock that opens a funnel modal instead of a game -- a sign-in prompt for a guest, a "finish a current game first" notice for a signed-in account (native Telegram popup, in-app modal elsewhere). The lock lifts via the existing profile refetch after a guest->durable upgrade. Remove the lobby's old at_game_limit New-Game tab disable + notice: the flag (now the random-kind cap) conflicted with the per-kind lock -- it hid the screen where the lock lives and wrongly blocked an unfulfilled kind. The New Game tab is always enabled; the per-kind start lock is the only gate. The at_game_limit wire field stays (unused by the client) for a later cleanup. Tests: client lock logic + codec kind/game_limits roundtrip + gateway transcode encode + native popup builders (unit); a mock e2e for the lock badge and the modal.
This commit is contained in:
@@ -47,6 +47,16 @@ type ProfileResp struct {
|
||||
// DictVersions is the current dictionary version per game variant, forwarded verbatim
|
||||
// into the Profile payload so an offline-capable client preloads the matching dawg.
|
||||
DictVersions []DictVersion `json:"dict_versions,omitempty"`
|
||||
// GameLimits is the caller's tier active-game caps per kind (-1 = unlimited), forwarded verbatim
|
||||
// into the Profile payload for the client's per-kind New-Game lock.
|
||||
GameLimits *GameLimitsResp `json:"game_limits,omitempty"`
|
||||
}
|
||||
|
||||
// GameLimitsResp is the caller's tier active-game caps per kind (-1 = unlimited) in the profile.
|
||||
type GameLimitsResp struct {
|
||||
VsAI int `json:"vs_ai"`
|
||||
Random int `json:"random"`
|
||||
Friends int `json:"friends"`
|
||||
}
|
||||
|
||||
// AdsResp is the post-move interstitial config in the profile: the client-mirrored cooldowns
|
||||
@@ -170,6 +180,7 @@ type GameResp struct {
|
||||
Seats []SeatResp `json:"seats"`
|
||||
UnreadChat bool `json:"unread_chat"`
|
||||
UnreadMessages bool `json:"unread_messages"`
|
||||
Kind int `json:"kind"`
|
||||
}
|
||||
|
||||
// MoveResultResp is the outcome of a committed move. Rack carries the actor's refilled rack as
|
||||
|
||||
@@ -194,6 +194,15 @@ func encodeProfile(p backendclient.ProfileResp) []byte {
|
||||
fb.AdsInfoAddSuppressed(b, p.Ads.Suppressed)
|
||||
ads = fb.AdsInfoEnd(b)
|
||||
}
|
||||
// The active-game limits table (scalars only), built before Profile is opened.
|
||||
var gameLimits flatbuffers.UOffsetT
|
||||
if p.GameLimits != nil {
|
||||
fb.GameLimitsStart(b)
|
||||
fb.GameLimitsAddVsAi(b, int32(p.GameLimits.VsAI))
|
||||
fb.GameLimitsAddRandom(b, int32(p.GameLimits.Random))
|
||||
fb.GameLimitsAddFriends(b, int32(p.GameLimits.Friends))
|
||||
gameLimits = fb.GameLimitsEnd(b)
|
||||
}
|
||||
fb.ProfileStart(b)
|
||||
fb.ProfileAddUserId(b, uid)
|
||||
fb.ProfileAddDisplayName(b, name)
|
||||
@@ -219,6 +228,9 @@ func encodeProfile(p backendclient.ProfileResp) []byte {
|
||||
if p.Ads != nil {
|
||||
fb.ProfileAddAds(b, ads)
|
||||
}
|
||||
if p.GameLimits != nil {
|
||||
fb.ProfileAddGameLimits(b, gameLimits)
|
||||
}
|
||||
b.Finish(fb.ProfileEnd(b))
|
||||
return b.FinishedBytes()
|
||||
}
|
||||
@@ -624,6 +636,7 @@ func toWireGame(g backendclient.GameResp) wire.GameView {
|
||||
LastActivityUnix: g.LastActivityUnix,
|
||||
UnreadChat: g.UnreadChat,
|
||||
UnreadMessages: g.UnreadMessages,
|
||||
Kind: g.Kind,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package transcode_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"scrabble/gateway/internal/transcode"
|
||||
fb "scrabble/pkg/fbs/scrabblefb"
|
||||
)
|
||||
|
||||
// TestProfileGetEncodesGameLimits verifies the gateway forwards the backend's per-kind active-game
|
||||
// caps into the Profile payload — the caps the client's New-Game lock reads. The encode is not
|
||||
// exercised by the mock e2e (it bypasses the codec), so a dropped field would only surface here.
|
||||
func TestProfileGetEncodesGameLimits(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",` +
|
||||
`"game_limits":{"vs_ai":1,"random":1,"friends":0}}`))
|
||||
})
|
||||
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)
|
||||
}
|
||||
|
||||
gl := fb.GetRootAsProfile(payload, 0).GameLimits(nil)
|
||||
if gl == nil {
|
||||
t.Fatal("profile carries no game_limits block")
|
||||
}
|
||||
if gl.VsAi() != 1 || gl.Random() != 1 || gl.Friends() != 0 {
|
||||
t.Errorf("game limits = %d/%d/%d, want 1/1/0", gl.VsAi(), gl.Random(), gl.Friends())
|
||||
}
|
||||
}
|
||||
|
||||
// TestProfileGetNoGameLimits verifies a profile without a game_limits block encodes none (the
|
||||
// backend omits it only when the limits config is unwired; normally the block is present).
|
||||
func TestProfileGetNoGameLimits(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.GameLimits(nil) != nil {
|
||||
t.Error("profile without a game_limits block unexpectedly carries one")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user