From 056948a1ba240fba9ddd8d1f45728aa5489621af Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Wed, 25 Mar 2020 19:19:29 +0100 Subject: [PATCH 1/2] See #1060: register listening earlier, instead of at the end of the track --- front/src/components/audio/Player.vue | 9 +++++++++ front/src/store/player.js | 1 - 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/front/src/components/audio/Player.vue b/front/src/components/audio/Player.vue index 58f76ad07..1c720d952 100644 --- a/front/src/components/audio/Player.vue +++ b/front/src/components/audio/Player.vue @@ -251,6 +251,8 @@ export default { progressInterval: null, maxPreloaded: 3, preloadDelay: 15, + listenDelay: 15, + listeningRecorded: null, soundsCache: [], soundId: null, playTimeout: null, @@ -477,6 +479,13 @@ export default { this.getSound(toPreload) this.nextTrackPreloaded = true } + if (t > this.listenDelay || d - t < 30) { + let onlyTrack = this.$store.state.queue.tracks.length === 1 + if (this.listeningRecorded != this.currentTrack) { + this.listeningRecorded = this.currentTrack + this.$store.dispatch('player/trackListened', this.currentTrack) + } + } } }, seek (step) { diff --git a/front/src/store/player.js b/front/src/store/player.js index 14affce90..f3dbbb8b7 100644 --- a/front/src/store/player.js +++ b/front/src/store/player.js @@ -127,7 +127,6 @@ export default { }) }, trackEnded ({dispatch, rootState}, track) { - dispatch('trackListened', track) let queueState = rootState.queue if (queueState.currentIndex === queueState.tracks.length - 1) { // we've reached last track of queue, trigger a reload From cd63646f391030d083c6ce6de250dcbf177d1e9b Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Wed, 25 Mar 2020 22:24:31 +0100 Subject: [PATCH 2/2] Fix #1060: Added a new radio based on another user listenings --- changes/changelog.d/1060.feature | 1 + front/src/App.vue | 18 ++++++++ front/src/components/audio/track/Widget.vue | 2 +- front/src/components/radios/Button.vue | 11 ++++- front/src/radios.js | 51 +++++++++++++++++++++ front/src/store/radios.js | 20 ++++++-- front/src/store/ui.js | 1 + front/src/views/auth/ProfileBase.vue | 7 +++ front/tests/unit/specs/store/player.spec.js | 2 - front/tests/unit/specs/store/radios.spec.js | 1 + 10 files changed, 106 insertions(+), 8 deletions(-) create mode 100644 changes/changelog.d/1060.feature create mode 100644 front/src/radios.js diff --git a/changes/changelog.d/1060.feature b/changes/changelog.d/1060.feature new file mode 100644 index 000000000..245a6be0c --- /dev/null +++ b/changes/changelog.d/1060.feature @@ -0,0 +1 @@ +Added a new radio based on another user listenings (#1060) diff --git a/front/src/App.vue b/front/src/App.vue index b572b1bcd..6252198e2 100644 --- a/front/src/App.vue +++ b/front/src/App.vue @@ -42,6 +42,7 @@ import { WebSocketBridge } from 'django-channels' import GlobalEvents from '@/components/utils/global-events' import moment from 'moment' import locales from './locales' +import {getClientOnlyRadio} from '@/radios' export default { name: 'app', @@ -138,6 +139,11 @@ export default { id: 'sidebarPendingReviewRequestCount', handler: this.incrementPendingReviewRequestsCountInSidebar }) + this.$store.commit('ui/addWebsocketEventHandler', { + eventName: 'Listen', + id: 'handleListen', + handler: this.handleListen + }) }, mounted () { let self = this @@ -175,6 +181,10 @@ export default { eventName: 'user_request.created', id: 'sidebarPendingReviewRequestCount', }) + this.$store.commit('ui/removeWebsocketEventHandler', { + eventName: 'Listen', + id: 'handleListen', + }) this.disconnect() }, methods: { @@ -190,6 +200,14 @@ export default { incrementPendingReviewRequestsCountInSidebar (event) { this.$store.commit('ui/incrementNotifications', {type: 'pendingReviewRequests', value: event.pending_count}) }, + handleListen (event) { + if (this.$store.state.radios.current && this.$store.state.radios.running) { + let current = this.$store.state.radios.current + if (current.clientOnly && current.type === 'account') { + getClientOnlyRadio(current).handleListen(current, event, this.$store) + } + } + }, async fetchNodeInfo () { let response = await axios.get('instance/nodeinfo/2.0/') this.$store.commit('instance/nodeinfo', response.data) diff --git a/front/src/components/audio/track/Widget.vue b/front/src/components/audio/track/Widget.vue index 6895a8712..945db6a16 100644 --- a/front/src/components/audio/track/Widget.vue +++ b/front/src/components/audio/track/Widget.vue @@ -29,7 +29,7 @@
- @{{ object.user.username }} + @{{ object.user.username }}
diff --git a/front/src/components/radios/Button.vue b/front/src/components/radios/Button.vue index f335a6596..7e1ff40c5 100644 --- a/front/src/components/radios/Button.vue +++ b/front/src/components/radios/Button.vue @@ -8,10 +8,12 @@