From: Daniel Karbach Date: Thu, 15 Feb 2024 09:57:04 +0000 (+0100) Subject: handle multi-channel episodes somewhat X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=c130314b819122a9223130277f283584917e58cd;hp=532dea7c62f3619a04cd8d7aa895f8db1f3f98d2;p=alttp.git handle multi-channel episodes somewhat --- 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) {