004aca4e97
CI / changes (pull_request) Successful in 3s
CI / unit (pull_request) Successful in 10s
CI / integration (pull_request) Successful in 15s
CI / ui (pull_request) Successful in 55s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m20s
The account time zone defaults to UTC until a player saves a profile, so a report's Filed time could only render in UTC even for a player clearly in another zone. Capture the client's detected "±HH:MM" offset (browser_tz) with each submission and show the Filed time in three zones in the operator console — UTC, the browser offset detected at submit, and the sender's saved profile zone — each shown "N/A" when not known, so the operator can tell what is certainly known from what is merely defaulted. - Thread browser_tz through the fbs envelope (+ Go/TS codegen), the gateway transcode + backend client, and the backend feedback service/store; add the column via migration 00004 (additive, image-rollback-safe). - Fix fmtTimeIn to resolve "±HH:MM" offsets via account.ResolveZone; time.LoadLocation alone silently fell back to UTC for offset zones, which is the second reason a "+02:00" sender showed only UTC. - Update ARCHITECTURE/FUNCTIONAL(+ru) docs and the feedback integration test.
112 lines
3.7 KiB
Go
112 lines
3.7 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// feedbackSubmitRequest is the player's feedback submission. Attachment is the
|
|
// base64-encoded file bytes (empty for none); AttachmentName carries the original
|
|
// file name (its extension is the allow-list key); Channel is the submitting
|
|
// platform (telegram/ios/android/web).
|
|
type feedbackSubmitRequest struct {
|
|
Body string `json:"body"`
|
|
Attachment string `json:"attachment"`
|
|
AttachmentName string `json:"attachment_name"`
|
|
Channel string `json:"channel"`
|
|
// Version is the client's app version (pkg/version / the SPA build), snapshotted so the
|
|
// operator sees which build a report came from.
|
|
Version string `json:"version"`
|
|
// BrowserTZ is the client's detected UTC offset ("±HH:MM") at submit, so the operator can
|
|
// see the filed time in the sender's local zone even before they save a profile.
|
|
BrowserTZ string `json:"browser_tz"`
|
|
}
|
|
|
|
// feedbackReplyDTO is the operator's reply shown back to the player.
|
|
type feedbackReplyDTO struct {
|
|
Body string `json:"body"`
|
|
RepliedAtUnix int64 `json:"replied_at_unix"`
|
|
}
|
|
|
|
// feedbackStateResponse is the player's feedback screen state. BlockedReason is
|
|
// "" (can send), "pending" or "banned"; Reply is omitted when there is none.
|
|
type feedbackStateResponse struct {
|
|
CanSend bool `json:"can_send"`
|
|
BlockedReason string `json:"blocked_reason"`
|
|
Reply *feedbackReplyDTO `json:"reply,omitempty"`
|
|
}
|
|
|
|
// feedbackUnreadResponse reports whether the player has an undelivered reply, for
|
|
// the lobby/Info badge.
|
|
type feedbackUnreadResponse struct {
|
|
ReplyUnread bool `json:"reply_unread"`
|
|
}
|
|
|
|
// handleFeedbackSubmit stores a feedback message from the authenticated player.
|
|
// The sender IP comes from the gateway-forwarded X-Forwarded-For header. Guests
|
|
// and feedback-banned accounts are refused (also gated at the gateway).
|
|
func (s *Server) handleFeedbackSubmit(c *gin.Context) {
|
|
uid, ok := userID(c)
|
|
if !ok {
|
|
abortBadRequest(c, "missing identity")
|
|
return
|
|
}
|
|
var req feedbackSubmitRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
abortBadRequest(c, "invalid request body")
|
|
return
|
|
}
|
|
var attachment []byte
|
|
if req.Attachment != "" {
|
|
data, err := base64.StdEncoding.DecodeString(req.Attachment)
|
|
if err != nil {
|
|
abortBadRequest(c, "invalid attachment encoding")
|
|
return
|
|
}
|
|
attachment = data
|
|
}
|
|
if err := s.feedback.Submit(c.Request.Context(), uid, req.Body, attachment, req.AttachmentName, req.Channel, req.Version, req.BrowserTZ, clientIP(c)); err != nil {
|
|
s.abortErr(c, err)
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, okResponse{OK: true})
|
|
}
|
|
|
|
// handleFeedbackState returns the player's feedback screen state and marks any
|
|
// pending operator replies delivered (clearing the badge).
|
|
func (s *Server) handleFeedbackState(c *gin.Context) {
|
|
uid, ok := userID(c)
|
|
if !ok {
|
|
abortBadRequest(c, "missing identity")
|
|
return
|
|
}
|
|
st, err := s.feedback.State(c.Request.Context(), uid)
|
|
if err != nil {
|
|
s.abortErr(c, err)
|
|
return
|
|
}
|
|
resp := feedbackStateResponse{CanSend: st.CanSend, BlockedReason: st.BlockedReason}
|
|
if st.Reply != nil {
|
|
resp.Reply = &feedbackReplyDTO{Body: st.Reply.Body, RepliedAtUnix: st.Reply.RepliedAt.Unix()}
|
|
}
|
|
c.JSON(http.StatusOK, resp)
|
|
}
|
|
|
|
// handleFeedbackUnread reports whether the player has an undelivered operator
|
|
// reply, for the lobby/Info badge. It has no side effect.
|
|
func (s *Server) handleFeedbackUnread(c *gin.Context) {
|
|
uid, ok := userID(c)
|
|
if !ok {
|
|
abortBadRequest(c, "missing identity")
|
|
return
|
|
}
|
|
unread, err := s.feedback.ReplyUnread(c.Request.Context(), uid)
|
|
if err != nil {
|
|
s.abortErr(c, err)
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, feedbackUnreadResponse{ReplyUnread: unread})
|
|
}
|