fix(feedback): show the operator reply only on the player's latest message
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 9s
CI / integration (pull_request) Successful in 13s
CI / ui (pull_request) Successful in 47s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m8s

A reply was bound to 'the latest message that has a reply', so after the player
read a reply and sent a new (unanswered) message, the old reply kept showing as
'Ответ на ваше последнее сообщение'. Bind it to the single most-recent message
instead: sending any new message immediately drops the previous reply (the new
message has no reply yet), well before the one-week window. Client clears the
reply optimistically on submit; the mock mirrors it; inttest covers the case.
This commit is contained in:
Ilia Denisov
2026-06-15 12:59:18 +02:00
parent 5287794a72
commit 1ae43080ec
5 changed files with 64 additions and 14 deletions
+13 -13
View File
@@ -86,25 +86,25 @@ func (s *Store) HasUnreadReply(ctx context.Context, accountID uuid.UUID) (bool,
// VisibleReply is the operator reply shown back to the player: the reply on their
// most recent replied message still inside the visibility window.
type VisibleReply struct {
MessageID uuid.UUID
Body string
RepliedAt time.Time
ReplyReadAt sql.NullTime
Body string
RepliedAt time.Time
}
// LatestVisibleReply returns the account's most recent message that carries a reply
// still visible to the player — not yet delivered, or delivered after cutoff (one
// week ago). Reports false when there is none.
// LatestVisibleReply returns the reply on the account's **most recent** message, if
// that message carries one still visible to the player — not yet delivered, or
// delivered after cutoff (one week ago). Binding it to the single latest message
// means that the moment the player sends a newer message the previous reply stops
// showing (the new message has no reply yet). Reports false when there is none.
func (s *Store) LatestVisibleReply(ctx context.Context, accountID uuid.UUID, cutoff time.Time) (VisibleReply, bool, error) {
var vr VisibleReply
var repliedAt sql.NullTime
err := s.db.QueryRowContext(ctx,
`SELECT message_id, COALESCE(reply_body, ''), replied_at, reply_read_at
FROM backend.feedback_messages
WHERE account_id = $1 AND reply_body IS NOT NULL
AND (reply_read_at IS NULL OR reply_read_at > $2)
ORDER BY created_at DESC LIMIT 1`,
accountID, cutoff).Scan(&vr.MessageID, &vr.Body, &repliedAt, &vr.ReplyReadAt)
`SELECT COALESCE(reply_body, ''), replied_at FROM (
SELECT reply_body, replied_at, reply_read_at FROM backend.feedback_messages
WHERE account_id = $1 ORDER BY created_at DESC LIMIT 1
) latest
WHERE reply_body IS NOT NULL AND (reply_read_at IS NULL OR reply_read_at > $2)`,
accountID, cutoff).Scan(&vr.Body, &repliedAt)
if errors.Is(err, sql.ErrNoRows) {
return VisibleReply{}, false, nil
}