From 56eaea3adb9fd25d7b03a194e4fcea3308c2f38b Mon Sep 17 00:00:00 2001
From: Eliot Berriot <contact@eliotberriot.com>
Date: Sat, 17 Jun 2017 19:36:23 +0200
Subject: [PATCH] Fixed #10: now record track listens

---
 src/audio/queue.js | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/audio/queue.js b/src/audio/queue.js
index 975f35c..ba0af48 100644
--- a/src/audio/queue.js
+++ b/src/audio/queue.js
@@ -1,8 +1,10 @@
 import logger from '@/logging'
 import cache from '@/cache'
+import config from '@/config'
 import Audio from '@/audio'
 import backend from '@/audio/backend'
 import radios from '@/radios'
+import Vue from 'vue'
 
 class Queue {
   constructor (options = {}) {
@@ -176,6 +178,7 @@ class Queue {
   }
 
   handleAudioEnded (e) {
+    this.recordListen(this.currentTrack)
     if (this.currentIndex < this.tracks.length - 1) {
       logger.default.info('Audio track ended, playing next one')
       this.next()
@@ -185,6 +188,14 @@ class Queue {
     }
   }
 
+  recordListen (track) {
+    let url = config.API_URL + 'history/listenings/'
+    let resource = Vue.resource(url)
+    resource.save({}, {'track': track.id}).then((response) => {}, (response) => {
+      logger.default.error('Could not record track in history')
+    })
+  }
+
   previous () {
     if (this.currentIndex > 0) {
       this.play(this.currentIndex - 1)
-- 
GitLab