Fix hub diretta: considera solo l'ultima sessione, non idle orfane.

Dopo «Termina trasmissione» la partita restava visibile se esisteva una vecchia sessione idle precedente a quella ended; l'hub e l'app usano ora lo stato dell'ultima sessione.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-09 21:58:01 +02:00
parent ad9d67ddb6
commit 01b7a3c96b
5 changed files with 31 additions and 9 deletions

View File

@@ -130,9 +130,7 @@ module Api
end
def active_session_for(match)
match.stream_sessions
.order(created_at: :desc)
.find { |s| !%w[ended error].include?(s.status) }
match.active_stream_session
end
end
end

View File

@@ -94,9 +94,7 @@ module Public
end
def active_session_for(match)
match.stream_sessions
.order(created_at: :desc)
.find { |s| !%w[ended error].include?(s.status) }
match.active_stream_session
end
end
end

View File

@@ -34,8 +34,10 @@ class Match < ApplicationRecord
end
def active_stream_session
stream_sessions.sort_by { |s| s.created_at }.reverse
.find { |s| !%w[ended error].include?(s.status) }
latest = stream_sessions.max_by(&:created_at)
return nil if latest.nil? || latest.status.in?(%w[ended error])
latest
end
def deletable?

View File

@@ -53,6 +53,27 @@ RSpec.describe Match, "scheduling scopes" do
expect(match.coach_hub_visible?).to be(false)
end
it "nasconde partita con diretta terminata anche se resta una sessione idle vecchia" do
match = team.matches.create!(opponent_name: "Avversario", sets_to_win: 3)
StreamSession.create!(
match: match,
user: user,
platform: "matchlivetv",
status: "idle",
created_at: 3.days.ago
)
StreamSession.create!(
match: match,
user: user,
platform: "matchlivetv",
status: "ended",
created_at: 1.hour.ago
)
expect(match.active_stream_session).to be_nil
expect(match.coach_hub_visible?).to be(false)
end
it "nasconde partita programmata nel passato mai trasmessa" do
match = team.matches.create!(
opponent_name: "Missed",