From c130314b819122a9223130277f283584917e58cd Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Thu, 15 Feb 2024 10:57:04 +0100 Subject: [PATCH 1/1] handle multi-channel episodes somewhat --- app/Models/Episode.php | 4 ++++ app/TwitchBot/CrewCommand.php | 2 +- resources/js/helpers/Crew.js | 19 ++++++++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/Models/Episode.php b/app/Models/Episode.php index 7d3175c..4b8a96a 100644 --- a/app/Models/Episode.php +++ b/app/Models/Episode.php @@ -24,6 +24,10 @@ class Episode extends Model return $this->crew()->where('confirmed', true); } + public function confirmedCrewOfChannel(Channel $channel) { + return $this->confirmedCrew()->where('channel_id', '=', $channel->id); + } + public function event() { return $this->belongsTo(Event::class); } diff --git a/app/TwitchBot/CrewCommand.php b/app/TwitchBot/CrewCommand.php index 85edfb2..2c162e9 100644 --- a/app/TwitchBot/CrewCommand.php +++ b/app/TwitchBot/CrewCommand.php @@ -8,7 +8,7 @@ class CrewCommand extends ChatCommand { $episode = $this->channel->getCurrentEpisode(); if (!$episode) return; $links = []; - foreach ($episode->confirmedCrew as $crew) { + foreach ($episode->confirmedCrewOfChannel($this->channel)->get() as $crew) { $link = $crew->getStreamLink(); if (empty($link)) { $link = $crew->getName(); diff --git a/resources/js/helpers/Crew.js b/resources/js/helpers/Crew.js index e60210f..205c0e8 100644 --- a/resources/js/helpers/Crew.js +++ b/resources/js/helpers/Crew.js @@ -1,12 +1,29 @@ export const compareCrew = (a, b) => { + return compareCrewConfirmed(a, b) || compareCrewChannel(a, b) || compareCrewName(a, b); +}; + +export const compareCrewChannel = (a, b) => { + const a_channel = (a && a.channel_id) || null; + const b_channel = (b && b.channel_id) || null; + if (a_channel === b_channel) return 0; + if (!a_channel) return -1; + if (!b_channel) return 1; + return a_channel - b_channel; +}; + +export const compareCrewConfirmed = (a, b) => { const a_confirmed = !!(a && a.confirmed); const b_confirmed = !!(b && b.confirmed); if (a_confirmed === b_confirmed) { - return getName(a).localeCompare(getName(b)); + return 0; } return a_confirmed ? -1 : 1; }; +export const compareCrewName = (a, b) => { + return getName(a).localeCompare(getName(b)); +}; + export const getName = crew => { if (!crew) return ''; if (crew.name_override) { -- 2.39.2