Skip to content

Commit 8f27615

Browse files
committed
[Twitch] Workaround for API bug where Kraken returns randomly sorted subscribers (when direction=desc)
1 parent d425d61 commit 8f27615

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

app/Http/Controllers/TwitchController.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,7 +1312,7 @@ public function subList(Request $request, $channel = null)
13121312
]));
13131313
}
13141314

1315-
if ($request->exists('logout')) {
1315+
if ($request->exists('logout')) {
13161316
return redirect()->route('auth.twitch.logout');
13171317
}
13181318

@@ -1406,6 +1406,24 @@ public function subList(Request $request, $channel = null)
14061406
}
14071407

14081408
$subscriptions = $data['subscriptions'];
1409+
1410+
/**
1411+
* Hotfix for Twitch API (Kraken V5) bug.
1412+
*
1413+
* Seems Kraken has an issue with sorting when direction=desc and limit > 1, though I'm not sure about exact params.
1414+
* The result seems to be completely randomized, which is just silly.
1415+
* We try to avoid that by sorting by `created_at`, but only for `latest`.
1416+
* It kinda 'helps' making the "random sub" even more random, ironically.
1417+
*/
1418+
if ($action === 'latest') {
1419+
usort($subscriptions, function($a, $b) {
1420+
$first = strtotime($a['created_at']);
1421+
$second = strtotime($b['created_at']);
1422+
1423+
return $first < $second;
1424+
});
1425+
}
1426+
14091427
$output = [];
14101428

14111429
if ($action == 'random') {

0 commit comments

Comments
 (0)