From 3739a1504975d7548cb17ed410753ab5afadc22a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Rynning-T=C3=B8nnesen?= Date: Wed, 31 Jul 2019 13:02:41 +0200 Subject: [PATCH] Closes #520 --- server/handlers/list_change.js | 128 ++++++++++++++------------------- 1 file changed, 55 insertions(+), 73 deletions(-) diff --git a/server/handlers/list_change.js b/server/handlers/list_change.js index 31a00817..f2ca0f09 100644 --- a/server/handlers/list_change.js +++ b/server/handlers/list_change.js @@ -200,88 +200,70 @@ function addFromOtherList(arr, guid, offline, socket) { frontpage: true, accessed: Functions.get_time() }; + + to_change.id = + np[0].id; + to_change.title = + np[0].title; db.collection( - channel + "frontpage_lists" ).find( { - now_playing: true + _id: new_channel }, - function( - e, - np_docs - ) { - to_change.id = - np_docs[0].id; - to_change.title = - np_docs[0].title; + function(e, doc) { + if ( + doc.length > + 0 && + ((doc[0] + .thumbnail != + "" && + doc[0] + .thumbnail != + undefined && + (doc[0].thumbnail.indexOf( + "https://i1.sndcdn.com" + ) > -1 || + doc[0].thumbnail.indexOf( + "https://w1.sndcdn.com" + ) > -1)) || + (doc[0] + .thumbnail == + "" || + doc[0] + .thumbnail == + undefined)) + ) { + to_change.thumbnail = + np[0].thumbnail; + } + db.collection( "frontpage_lists" - ).find( + ).update( { - _id: new_channel + _id: channel }, - function( - e, - doc - ) { - if ( - doc.length > - 0 && - ((doc[0] - .thumbnail != - "" && - doc[0] - .thumbnail != - undefined && - (doc[0].thumbnail.indexOf( - "https://i1.sndcdn.com" - ) > -1 || - doc[0].thumbnail.indexOf( - "https://w1.sndcdn.com" - ) > - -1)) || - (doc[0] - .thumbnail == - "" || - doc[0] - .thumbnail == - undefined)) - ) { - to_change.thumbnail = - np_docs[0].thumbnail; - } - - db.collection( - "frontpage_lists" - ).update( - { - _id: channel - }, - { - $set: to_change - }, - function( - e, - d - ) { - List.send_list( - channel, - undefined, - false, - true, - false - ); - List.send_play( - channel, - undefined - ); - socket.emit( - "toast", - "addedplaylist" - ); - _db.close(); - } + { + $set: to_change + }, + function(e, d) { + List.send_list( + channel, + undefined, + false, + true, + false ); + List.send_play( + channel, + undefined + ); + socket.emit( + "toast", + "addedplaylist" + ); + _db.close(); } ); }