Show name of who added something (Issue #50)

Hovering over a queue item will now show the name of the person who added it.
If it was added by a guest, or if it was added while the server was running a previous version, it will show up as "unknown".
This commit is contained in:
calzoneman 2013-04-24 13:10:08 -05:00
parent 19d778e8ba
commit 57475d5d3d
5 changed files with 29 additions and 11 deletions

View File

@ -81,7 +81,10 @@ Channel.prototype.loadDump = function() {
data = JSON.parse(data); data = JSON.parse(data);
for(var i = 0; i < data.queue.length; i++) { for(var i = 0; i < data.queue.length; i++) {
var e = data.queue[i]; var e = data.queue[i];
this.queue.push(new Media(e.id, e.title, e.seconds, e.type)); var m = new Media(e.id, e.title, e.seconds, e.type);
m.queueby = data.queue[i].queueby ? data.queue[i].queueby
: "";
this.queue.push(m);
} }
this.sendAll("playlist", { this.sendAll("playlist", {
pl: this.queue pl: this.queue
@ -572,14 +575,16 @@ function mediaUpdate(chan, id) {
setTimeout(function() { mediaUpdate(chan, id); }, 1000); setTimeout(function() { mediaUpdate(chan, id); }, 1000);
} }
Channel.prototype.enqueue = function(data) { Channel.prototype.enqueue = function(data, user) {
var idx = data.pos == "next" ? this.position + 1 : this.queue.length; var idx = data.pos == "next" ? this.position + 1 : this.queue.length;
// Prefer cache over looking up new data // Prefer cache over looking up new data
if(data.id in this.library) { if(data.id in this.library) {
this.queue.splice(idx, 0, this.library[data.id]); var media = this.library[data.id];
media.queueby = user ? user.name : "";
this.queue.splice(idx, 0, media);
this.sendAll("queue", { this.sendAll("queue", {
media: this.library[data.id].pack(), media: media.pack(),
pos: idx pos: idx
}); });
this.logger.log("*** Queued from cache: id=" + data.id); this.logger.log("*** Queued from cache: id=" + data.id);
@ -592,6 +597,7 @@ Channel.prototype.enqueue = function(data) {
case "dm": case "dm":
case "sc": case "sc":
InfoGetter.getMedia(data.id, data.type, function(media) { InfoGetter.getMedia(data.id, data.type, function(media) {
media.queueby = user ? user.name : "";
this.queue.splice(idx, 0, media); this.queue.splice(idx, 0, media);
this.sendAll("queue", { this.sendAll("queue", {
media: media.pack(), media: media.pack(),
@ -603,7 +609,8 @@ Channel.prototype.enqueue = function(data) {
}.bind(this)); }.bind(this));
break; break;
case "li": case "li":
var media = new Media(data.id, "Livestream ~ " + data.id, "--:--", "li"); var media = new Media(data.id, "Livestream - " + data.id, "--:--", "li");
media.queueby = user ? user.name : "";
this.queue.splice(idx, 0, media); this.queue.splice(idx, 0, media);
this.sendAll("queue", { this.sendAll("queue", {
media: media.pack(), media: media.pack(),
@ -611,7 +618,8 @@ Channel.prototype.enqueue = function(data) {
}); });
break; break;
case "tw": case "tw":
var media = new Media(data.id, "Twitch ~ " + data.id, "--:--", "tw"); var media = new Media(data.id, "Twitch - " + data.id, "--:--", "tw");
media.queueby = user ? user.name : "";
this.queue.splice(idx, 0, media); this.queue.splice(idx, 0, media);
this.sendAll("queue", { this.sendAll("queue", {
media: media.pack(), media: media.pack(),
@ -620,6 +628,7 @@ Channel.prototype.enqueue = function(data) {
break; break;
case "rt": case "rt":
var media = new Media(data.id, "Livestream", "--:--", "rt"); var media = new Media(data.id, "Livestream", "--:--", "rt");
media.queueby = user ? user.name : "";
this.queue.splice(idx, 0, media); this.queue.splice(idx, 0, media);
this.sendAll("queue", { this.sendAll("queue", {
media: media.pack(), media: media.pack(),
@ -656,7 +665,7 @@ Channel.prototype.tryQueue = function(user, data) {
return; return;
} }
this.enqueue(data); this.enqueue(data, user);
} }
Channel.prototype.dequeue = function(data) { Channel.prototype.dequeue = function(data) {

View File

@ -46,6 +46,7 @@ var Media = function(id, title, seconds, type) {
this.seconds = seconds; this.seconds = seconds;
this.duration = formatTime(this.seconds); this.duration = formatTime(this.seconds);
this.type = type; this.type = type;
this.queueby = "";
} }
// Returns an object containing the data in this Media but not the // Returns an object containing the data in this Media but not the
@ -56,7 +57,8 @@ Media.prototype.pack = function() {
title: this.title, title: this.title,
seconds: this.seconds, seconds: this.seconds,
duration: this.duration, duration: this.duration,
type: this.type type: this.type,
queueby: this.queueby
}; };
} }
@ -69,7 +71,8 @@ Media.prototype.packupdate = function() {
seconds: this.seconds, seconds: this.seconds,
duration: this.duration, duration: this.duration,
type: this.type, type: this.type,
currentTime: this.currentTime currentTime: this.currentTime,
queueby: this.queueby
}; };
} }

View File

@ -2,7 +2,7 @@
"author": "Calvin Montgomery", "author": "Calvin Montgomery",
"name": "CyTube", "name": "CyTube",
"description": "Online media synchronizer and chat", "description": "Online media synchronizer and chat",
"version": "1.2.5", "version": "1.2.6",
"repository": { "repository": {
"url": "http://github.com/calzoneman/sync" "url": "http://github.com/calzoneman/sync"
}, },

View File

@ -9,7 +9,7 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
const VERSION = "1.2.5"; const VERSION = "1.2.6";
var fs = require("fs"); var fs = require("fs");
var Logger = require("./logger.js"); var Logger = require("./logger.js");

View File

@ -246,6 +246,9 @@ function initCallbacks() {
var li = makeQueueEntry(data.pl[i]); var li = makeQueueEntry(data.pl[i]);
if(RANK >= Rank.Moderator || OPENQUEUE || LEADER) if(RANK >= Rank.Moderator || OPENQUEUE || LEADER)
addQueueButtons(li); addQueueButtons(li);
$(li).attr("title", data.pl[i].queueby
? ("Added by: " + data.pl[i].queueby)
: "Added by: Unknown");
$(li).appendTo(ul); $(li).appendTo(ul);
} }
}); });
@ -257,6 +260,9 @@ function initCallbacks() {
$(li).css("display", "none"); $(li).css("display", "none");
var idx = data.pos; var idx = data.pos;
var ul = $("#queue")[0]; var ul = $("#queue")[0];
$(li).attr("title", data.media.queueby
? ("Added by: " + data.media.queueby)
: "Added by: Unknown");
$(li).appendTo(ul); $(li).appendTo(ul);
if(idx < ul.children.length - 1) if(idx < ul.children.length - 1)
moveVideo(ul.children.length - 1, idx); moveVideo(ul.children.length - 1, idx);