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 end
def active_session_for(match) def active_session_for(match)
match.stream_sessions match.active_stream_session
.order(created_at: :desc)
.find { |s| !%w[ended error].include?(s.status) }
end end
end end
end end

View File

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

View File

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

View File

@@ -53,6 +53,27 @@ RSpec.describe Match, "scheduling scopes" do
expect(match.coach_hub_visible?).to be(false) expect(match.coach_hub_visible?).to be(false)
end 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 it "nasconde partita programmata nel passato mai trasmessa" do
match = team.matches.create!( match = team.matches.create!(
opponent_name: "Missed", opponent_name: "Missed",

View File

@@ -140,7 +140,10 @@ fun MatchesScreen(
val pullRefreshState = rememberPullToRefreshState() val pullRefreshState = rememberPullToRefreshState()
val activeMatch = matches.firstOrNull { it.canResumeCamera || it.hasActiveSession } val activeMatch = matches.firstOrNull { match ->
match.canResumeCamera ||
(match.hasActiveSession && match.activeSessionStatus == "idle")
}
val scheduledMatches = matches.filter { match -> val scheduledMatches = matches.filter { match ->
!match.hasActiveSession && parseApiInstant(match.scheduledAt)?.isScheduledFuture() == true !match.hasActiveSession && parseApiInstant(match.scheduledAt)?.isScheduledFuture() == true
} }