]> git.localhorst.tv Git - alttp.git/commitdiff
handle multi-channel episodes somewhat
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 15 Feb 2024 09:57:04 +0000 (10:57 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 15 Feb 2024 09:57:04 +0000 (10:57 +0100)
app/Models/Episode.php
app/TwitchBot/CrewCommand.php
resources/js/helpers/Crew.js

index 7d3175c4778e19b72d9f9558610d9518a7103410..4b8a96a53e2061f527db4d88d089ac411f90e1d9 100644 (file)
@@ -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);
        }
index 85edfb29ea7976529b04f9392e54617f5f4aeb03..2c162e93abb08552dff4d1da09f9070b1a7d09f6 100644 (file)
@@ -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();
index e60210fd799d8f28b85d44c0947da4c74d103499..205c0e8b5ebd1786dc24fcc0a314b3745a2514e8 100644 (file)
@@ -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) {