fix(social): robot blocks
CI / changes (pull_request) Successful in 3s
CI / unit (pull_request) Successful in 9s
CI / integration (pull_request) Successful in 17s
CI / ui (pull_request) Successful in 52s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m21s
CI / changes (pull_request) Successful in 3s
CI / unit (pull_request) Successful in 9s
CI / integration (pull_request) Successful in 17s
CI / ui (pull_request) Successful in 52s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m21s
Blocking an auto-match opponent who is secretly a pooled robot is recorded instead in a separate `robot_blocks` table. Now blocking behaves the same in that game (struck name, hidden composer) and lists the blocked opponent under the name you saw, but is recorded only against that game — the disguise holds, the shared robot is never globally blocked, and the matchmaker keeps pairing you with robots (so you can never block yourself out of opponents). - the shared robot account is never put in `blocks` - the matchmaker keeps it free and it is not blocked under its other per-game names - the blocked list and the in-game card still show it by joining that table; an unblock deletes the row
This commit is contained in:
@@ -2,6 +2,7 @@ package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
@@ -13,9 +14,21 @@ import (
|
||||
// not delete — any friendship (an unblock restores it). They reuse the friend handlers'
|
||||
// targetIDRequest and account-ref resolution.
|
||||
|
||||
// blockListDTO is the accounts the caller has blocked.
|
||||
// blockListDTO is the accounts the caller has blocked, plus the per-game disguised-robot
|
||||
// blocks (not real accounts), which the blocked list shows as distinct personalities.
|
||||
type blockListDTO struct {
|
||||
Blocked []accountRefDTO `json:"blocked"`
|
||||
Robots []robotBlockDTO `json:"robots"`
|
||||
}
|
||||
|
||||
// robotBlockDTO is one per-game disguised-robot block: the row id (used to unblock it), the
|
||||
// game name the player saw, and the game + seat it was blocked in (so the in-game card can
|
||||
// re-mark that seat).
|
||||
type robotBlockDTO struct {
|
||||
ID string `json:"id"`
|
||||
DisplayName string `json:"display_name"`
|
||||
GameID string `json:"game_id"`
|
||||
Seat int `json:"seat"`
|
||||
}
|
||||
|
||||
// handleBlock blocks the body-supplied account.
|
||||
@@ -35,7 +48,18 @@ func (s *Server) handleBlock(c *gin.Context) {
|
||||
abortBadRequest(c, "invalid account id")
|
||||
return
|
||||
}
|
||||
if err := s.social.Block(c.Request.Context(), uid, target); err != nil {
|
||||
// An in-game block carries the game id, so a disguised-robot opponent is recorded as a
|
||||
// per-game block (BlockInGame); a settings-screen block (no game) blocks a human directly.
|
||||
var err error
|
||||
if strings.TrimSpace(req.GameID) == "" {
|
||||
err = s.social.Block(c.Request.Context(), uid, target)
|
||||
} else if gameID, ok := parseUUIDField(req.GameID); !ok {
|
||||
abortBadRequest(c, "invalid game id")
|
||||
return
|
||||
} else {
|
||||
err = s.social.BlockInGame(c.Request.Context(), uid, target, gameID)
|
||||
}
|
||||
if err != nil {
|
||||
s.abortErr(c, err)
|
||||
return
|
||||
}
|
||||
@@ -68,10 +92,20 @@ func (s *Server) handleListBlocks(c *gin.Context) {
|
||||
abortBadRequest(c, "missing identity")
|
||||
return
|
||||
}
|
||||
ids, err := s.social.ListBlocks(c.Request.Context(), uid)
|
||||
ctx := c.Request.Context()
|
||||
ids, err := s.social.ListBlocks(ctx, uid)
|
||||
if err != nil {
|
||||
s.abortErr(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, blockListDTO{Blocked: s.accountRefs(c.Request.Context(), ids)})
|
||||
robots, err := s.social.ListRobotBlocks(ctx, uid)
|
||||
if err != nil {
|
||||
s.abortErr(c, err)
|
||||
return
|
||||
}
|
||||
dto := blockListDTO{Blocked: s.accountRefs(ctx, ids)}
|
||||
for _, r := range robots {
|
||||
dto.Robots = append(dto.Robots, robotBlockDTO{ID: r.ID.String(), DisplayName: r.DisplayName, GameID: r.GameID.String(), Seat: r.Seat})
|
||||
}
|
||||
c.JSON(http.StatusOK, dto)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user