From 18f2399c0e23e7e932058100908e1fc82a085e5d Mon Sep 17 00:00:00 2001 From: Joshua Coles Date: Sun, 8 Oct 2023 16:24:31 +0100 Subject: [PATCH] Add better capacity for live lectures --- app/controllers/lecture_controller.rb | 4 ++++ app/models/lecture.rb | 9 +++++++++ app/views/lectures/_lecture.html.erb | 3 ++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/controllers/lecture_controller.rb b/app/controllers/lecture_controller.rb index 2413728..5cd3f2a 100644 --- a/app/controllers/lecture_controller.rb +++ b/app/controllers/lecture_controller.rb @@ -19,6 +19,10 @@ class LectureController < ApplicationController project_id: lecture.course.toggl_project, ) + if lecture.is_live? + redirect_to lecture.live_video_url, allow_other_host: true + end + if lecture.recording.present? redirect_to lecture.recording.recording_url, allow_other_host: true end diff --git a/app/models/lecture.rb b/app/models/lecture.rb index 9333015..82c1a28 100644 --- a/app/models/lecture.rb +++ b/app/models/lecture.rb @@ -38,4 +38,13 @@ class Lecture < ApplicationRecord def live_video_url nil end + + # NAIVE: Assumes that lectures are 50 minutes long, this is true currently but not assured. + def end_time + start_time + 50.hour + end + + def is_live? + live_video_url.present? && start_time.past? && end_time.future? + end end diff --git a/app/views/lectures/_lecture.html.erb b/app/views/lectures/_lecture.html.erb index b4926ed..ef5fbeb 100644 --- a/app/views/lectures/_lecture.html.erb +++ b/app/views/lectures/_lecture.html.erb @@ -60,7 +60,8 @@ class: 'action-button' %> <% elsif lecture.start_time.past? && !lecture.attended? %> - <%= button_to "Start", + <% start_label = if lecture.is_live? then "Join" else "Start" end %> + <%= button_to start_label, lectures_start_path(id: lecture.id), class: 'action-button' %>