feat(chat): limit in-game chat to one message per turn
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 9s
CI / integration (pull_request) Successful in 12s
CI / ui (pull_request) Successful in 45s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m8s
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 9s
CI / integration (pull_request) Successful in 12s
CI / ui (pull_request) Successful in 45s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m8s
Enforce one chat message per turn on both ends. The backend rejects a second message in the same turn (ErrChatAlreadySentThisTurn -> 409 chat_already_sent), keyed on the move-driven turn start (turn_started_at). The UI derives "already wrote this turn" from the message list against GameView.lastActivityUnix (no counter, survives reopening, resets on turn change), hides the field behind a short caption once the limit is reached, and now reloads the game state on turn/game-state events so the toggle and the limit follow the live game. Enter is gated on !busy to avoid a double-send in the in-flight window. Backend: new game.TurnStartedAt; social GameReader gains it; PostMessage enforces the limit reusing lastMessageAt. UI: new lib/chatlimit.ts pure logic + unit tests; Chat/ChatScreen wiring; chat.sentThisTurn and error.chat_already_sent i18n (en/ru); extended chat e2e. Docs: FUNCTIONAL (+ru), ARCHITECTURE, UI_DESIGN.
This commit is contained in:
@@ -333,6 +333,29 @@ func TestChatOnlyOnYourTurn(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestChatOnePerTurn checks the one-message-per-turn limit: a second message on the same
|
||||
// turn is refused, and a fresh turn (turn_started_at advancing past the sent message)
|
||||
// reopens chat for the player.
|
||||
func TestChatOnePerTurn(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
svc := newSocialService()
|
||||
gameID, seats := newGameWithSeats(t, 2) // seat 0 is to move at the opening
|
||||
if _, err := svc.PostMessage(ctx, gameID, seats[0], "first", ""); err != nil {
|
||||
t.Fatalf("first message: %v", err)
|
||||
}
|
||||
if _, err := svc.PostMessage(ctx, gameID, seats[0], "second", ""); !errors.Is(err, social.ErrChatAlreadySentThisTurn) {
|
||||
t.Fatalf("second message = %v, want ErrChatAlreadySentThisTurn", err)
|
||||
}
|
||||
// Advancing the turn start past the sent message (as a real move does) reopens chat.
|
||||
if _, err := testDB.ExecContext(ctx,
|
||||
`UPDATE backend.games SET turn_started_at = now() WHERE game_id = $1`, gameID); err != nil {
|
||||
t.Fatalf("advance turn: %v", err)
|
||||
}
|
||||
if _, err := svc.PostMessage(ctx, gameID, seats[0], "next turn", ""); err != nil {
|
||||
t.Fatalf("message on the new turn: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNudgeRulesAndRateLimit(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
svc := newSocialService()
|
||||
|
||||
Reference in New Issue
Block a user