From bf3670aa88179ced61822444119d1320f839e33c Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Sun, 24 Jul 2011 16:14:12 +0100 Subject: [PATCH] hopefully fix addChunk / 2 --- server/djrandom/frontend/static/player.js | 27 ++++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/server/djrandom/frontend/static/player.js b/server/djrandom/frontend/static/player.js index e17f31f..84b0160 100644 --- a/server/djrandom/frontend/static/player.js +++ b/server/djrandom/frontend/static/player.js @@ -109,22 +109,27 @@ djr.Playlist.prototype.allSongs = function() { }; // Add a new chunk (only adds unique songs). -// Returns the chunk ID. +// Returns the chunk ID, or -1 if no songs were added. djr.Playlist.prototype.addChunk = function(playlist_chunk) { djr.debug('adding chunk to playlist ' + this.uuid); chunk_id = this.next_chunk_id++; + var songs = []; - var playlist = this; - $.each(playlist_chunk.songs, function(idx, song) { - if (playlist.song_map[song]) { - return; + for (i = 0; i < playlist_chunk.songs.length; i++) { + if (this.song_map[song]) { + continue; } - songs.push(song); - playlist.song_map[song] = chunk_id; - }); - this.chunk_map[chunk_id] = new djr.PlaylistChunk(songs); - this.chunks.push(chunk_id); - return chunk_id; + songs.push(playlist_chunk.songs[i]); + this.song_map[playlist_chunk.songs[i]] = chunk_id; + } + + if (songs.length == 0) { + return -1; + } else { + this.chunk_map[chunk_id] = new djr.PlaylistChunk(songs); + this.chunks.push(chunk_id); + return chunk_id; + } }; // Remove a chunk (by ID). -- GitLab