diff --git a/app/Http/Controllers/API/ScrobbleController.php b/app/Http/Controllers/API/ScrobbleController.php index 6dba8e4c..9ff26ec8 100644 --- a/app/Http/Controllers/API/ScrobbleController.php +++ b/app/Http/Controllers/API/ScrobbleController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\API; +use App\Http\Requests\API\Request; use App\Models\Song; class ScrobbleController extends Controller @@ -9,13 +10,14 @@ class ScrobbleController extends Controller /** * Create a Last.fm scrobble entry for a song. * - * @param Song $song - * @param string $timestamp The UNIX timestamp when the song started playing. + * @param Request $request + * @param Song $song + * @param string $timestamp The UNIX timestamp when the song started playing. * * @return \Illuminate\Http\JsonResponse */ - public function store(Song $song, $timestamp) + public function store(Request $request, Song $song, $timestamp) { - return response()->json($song->scrobble($timestamp)); + return response()->json($song->scrobble($request->user(), $timestamp)); } } diff --git a/app/Models/Song.php b/app/Models/Song.php index ec08012e..ab1453a5 100644 --- a/app/Models/Song.php +++ b/app/Models/Song.php @@ -74,11 +74,12 @@ class Song extends Model /** * Scrobble the song using Last.fm service. * + * @param User $user * @param string $timestamp The UNIX timestamp in which the song started playing. * * @return mixed */ - public function scrobble($timestamp) + public function scrobble(User $user, $timestamp) { // Don't scrobble the unknown guys. No one knows them. if ($this->artist->isUnknown()) { @@ -86,7 +87,7 @@ class Song extends Model } // If the current user hasn't connected to Last.fm, don't do shit. - if (!$sessionKey = auth()->user()->lastfm_session_key) { + if (!$user->lastfm_session_key) { return false; } @@ -95,7 +96,7 @@ class Song extends Model $this->title, $timestamp, $this->album->name === Album::UNKNOWN_NAME ? '' : $this->album->name, - $sessionKey + $user->lastfm_session_key ); }