From 01b7a3c96be045309eff7de3c7c1925e45ded2d0 Mon Sep 17 00:00:00 2001 From: Emiliano Frascaro Date: Tue, 9 Jun 2026 21:58:01 +0200 Subject: [PATCH] Fix hub diretta: considera solo l'ultima sessione, non idle orfane. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../controllers/api/v1/matches_controller.rb | 4 +--- .../controllers/public/matches_controller.rb | 4 +--- backend/app/models/match.rb | 6 ++++-- backend/spec/models/match_scheduling_spec.rb | 21 +++++++++++++++++++ .../match_live_tv/ui/matches/MatchesScreen.kt | 5 ++++- 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/backend/app/controllers/api/v1/matches_controller.rb b/backend/app/controllers/api/v1/matches_controller.rb index 30da598..7779bd1 100644 --- a/backend/app/controllers/api/v1/matches_controller.rb +++ b/backend/app/controllers/api/v1/matches_controller.rb @@ -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 diff --git a/backend/app/controllers/public/matches_controller.rb b/backend/app/controllers/public/matches_controller.rb index c271085..7fa2396 100644 --- a/backend/app/controllers/public/matches_controller.rb +++ b/backend/app/controllers/public/matches_controller.rb @@ -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 diff --git a/backend/app/models/match.rb b/backend/app/models/match.rb index b089e08..da5abfe 100644 --- a/backend/app/models/match.rb +++ b/backend/app/models/match.rb @@ -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? diff --git a/backend/spec/models/match_scheduling_spec.rb b/backend/spec/models/match_scheduling_spec.rb index 58ae7b3..df8c502 100644 --- a/backend/spec/models/match_scheduling_spec.rb +++ b/backend/spec/models/match_scheduling_spec.rb @@ -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", diff --git a/native/android/app/src/main/kotlin/com/matchlivetv/match_live_tv/ui/matches/MatchesScreen.kt b/native/android/app/src/main/kotlin/com/matchlivetv/match_live_tv/ui/matches/MatchesScreen.kt index 6652d96..76ff2e8 100644 --- a/native/android/app/src/main/kotlin/com/matchlivetv/match_live_tv/ui/matches/MatchesScreen.kt +++ b/native/android/app/src/main/kotlin/com/matchlivetv/match_live_tv/ui/matches/MatchesScreen.kt @@ -140,7 +140,10 @@ fun MatchesScreen( 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 -> !match.hasActiveSession && parseApiInstant(match.scheduledAt)?.isScheduledFuture() == true }