Work on chat filters, UI stuff

This commit is contained in:
calzoneman 2014-01-18 20:18:00 -06:00
parent 7b18caa51c
commit 9c989f7ed7
12 changed files with 204 additions and 35 deletions

View File

@ -2128,22 +2128,30 @@ Channel.prototype.handleToggleLock = function (user) {
* Updates a chat filter, or adds a new one if the filter does not exist * Updates a chat filter, or adds a new one if the filter does not exist
*/ */
Channel.prototype.updateFilter = function (filter) { Channel.prototype.updateFilter = function (filter) {
var self = this;
if (!filter.name) { if (!filter.name) {
filter.name = filter.source; filter.name = filter.source;
} }
var found = false; var found = false;
for (var i = 0; i < this.filters.length; i++) { for (var i = 0; i < self.filters.length; i++) {
if (this.filters[i].name === filter.name) { if (self.filters[i].name === filter.name) {
found = true; found = true;
this.filters[i] = filter; self.filters[i] = filter;
break; break;
} }
} }
if (!found) { if (!found) {
this.filters.push(filter); self.filters.push(filter);
} }
self.users.forEach(function (u) {
if (self.hasPermission(u, "filteredit")) {
u.socket.emit("updateChatFilter", filter);
}
});
}; };
/** /**
@ -2186,9 +2194,16 @@ Channel.prototype.handleUpdateFilter = function (user, f) {
* Removes a chat filter * Removes a chat filter
*/ */
Channel.prototype.removeFilter = function (filter) { Channel.prototype.removeFilter = function (filter) {
for (var i = 0; i < this.filters.length; i++) { var self = this;
if (this.filters[i].name === filter.name) {
this.filters.splice(i, 1); for (var i = 0; i < self.filters.length; i++) {
if (self.filters[i].name === filter.name) {
self.filters.splice(i, 1);
self.users.forEach(function (u) {
if (self.hasPermission(u, "filteredit")) {
u.socket.emit("deleteChatFilter", filter);
}
});
break; break;
} }
} }

View File

@ -72,6 +72,7 @@ var handlers = {
/* commands that do not send chat messages */ /* commands that do not send chat messages */
"afk": function (chan, user, msg, meta) { "afk": function (chan, user, msg, meta) {
console.log("/afk => setAfk(!" + user.meta.afk + ")");
user.setAFK(!user.meta.afk); user.setAFK(!user.meta.afk);
return true; return true;
}, },

View File

@ -106,9 +106,12 @@ function handleConnection(sock) {
user.emit("login"); user.emit("login");
user.socket.emit("login", { user.socket.emit("login", {
success: true, success: true,
name: user.name name: user.name,
guest: false
}); });
user.socket.emit("rank", user.global_rank); user.socket.emit("rank", user.global_rank);
} else {
user.socket.emit("rank", -1);
} }
} }

View File

@ -78,6 +78,8 @@ User.prototype.setAFK = function (afk) {
return; return;
} }
this.meta.afk = afk;
var chan = this.channel; var chan = this.channel;
if (afk) { if (afk) {
if (chan.voteskip) { if (chan.voteskip) {
@ -475,7 +477,8 @@ User.prototype.guestLogin = function (name) {
self.loggedIn = true; self.loggedIn = true;
self.socket.emit("login", { self.socket.emit("login", {
success: true, success: true,
name: name name: name,
guest: true
}); });
// TODO you shouldn't be able to guest login without being in a channel // TODO you shouldn't be able to guest login without being in a channel

View File

@ -112,6 +112,17 @@ mixin chanranks
mixin chatfilters mixin chatfilters
#cs-chatfilters.tab-pane #cs-chatfilters.tab-pane
h4 Chat Filters h4 Chat Filters
form.form-horizontal(action="javascript:void(0)", role="form")
+textbox("cs-chatfilters-newname", "Filter name")
+textbox("cs-chatfilters-newregex", "Filter regex")
.form-group
label.control-label.col-sm-4(for="cs-chatfilters-newflags") Flags
.col-sm-8
input#cs-chatfilters-newflags.form-control.cs-textbox(type="text", value="g")
+textbox("cs-chatfilters-newreplace", "Replacement")
.form-group
.col-sm-8.col-sm-offset-4
button#cs-chatfilters-newsubmit.btn.btn-primary Create Filter
table.table.table-striped.table-condensed table.table.table-striped.table-condensed
thead thead
tr tr
@ -119,6 +130,10 @@ mixin chatfilters
th Name th Name
th Active th Active
button#cs-chatfilters-export.btn.btn-default Export filter list
button#cs-chatfilters-import.btn.btn-default Import filter list
textarea#cs-chatfilters-exporttext.form-control(rows="5")
mixin chanlog mixin chanlog
#cs-chanlog.tab-pane #cs-chanlog.tab-pane
h4 Channel Log h4 Channel Log

View File

@ -59,6 +59,17 @@ mixin us-playback
mixin rcheckbox("us-hidevideo", "Remove the video player") mixin rcheckbox("us-hidevideo", "Remove the video player")
mixin rcheckbox("us-playlistbuttons", "Hide playlist buttons by default") mixin rcheckbox("us-playlistbuttons", "Hide playlist buttons by default")
mixin rcheckbox("us-oldbtns", "Old style playlist buttons") mixin rcheckbox("us-oldbtns", "Old style playlist buttons")
.form-group
label.control-label.col-sm-4(for="#us-default-quality") Default YouTube quality
.col-sm-8
select#us-default-quality.form-control
option(value="auto") Auto
option(value="small") 240p
option(value="medium") 360p
option(value="large") 480p
option(value="hd720") 720p
option(value="hd1080") 1080p
option(value="highres") Highest Available
mixin us-chat mixin us-chat
#us-chat.tab-pane #us-chat.tab-pane

View File

@ -47,23 +47,17 @@ Callbacks = {
socket.emit("joinChannel", { socket.emit("joinChannel", {
name: CHANNEL.name name: CHANNEL.name
}); });
if (CHANNEL.opts.password) { if (CHANNEL.opts.password) {
socket.emit("channelPassword", CHANNEL.opts.password); socket.emit("channelPassword", CHANNEL.opts.password);
} }
/*
if(NAME && SESSION) { if (CLIENT.name && CLIENT.guest) {
socket.emit("login", {
name: NAME,
session: SESSION
});
}
// Guest auto-relogin
else if(CLIENT.name) {
socket.emit("login", { socket.emit("login", {
name: CLIENT.name name: CLIENT.name
}); });
} }
*/
$("<div/>").addClass("server-msg-reconnect") $("<div/>").addClass("server-msg-reconnect")
.text("Connected") .text("Connected")
.appendTo($("#messagebuffer")); .appendTo($("#messagebuffer"));
@ -240,6 +234,44 @@ Callbacks = {
formatCSChatFilterList(); formatCSChatFilterList();
}, },
updateChatFilter: function (f) {
var entries = $("#cs-chatfilters table").data("entries") || [];
var found = false;
for (var i = 0; i < entries.length; i++) {
if (entries[i].name === f.name) {
entries[i] = f;
found = true;
break;
}
}
if (!found) {
entries.push(f);
}
$("#cs-chatfilters table").data("entries", entries);
formatCSChatFilterList();
},
deleteChatFilter: function (f) {
var entries = $("#cs-chatfilters table").data("entries") || [];
var found = false;
for (var i = 0; i < entries.length; i++) {
if (entries[i].name === f.name) {
entries[i] = f;
found = i;
break;
}
}
if (found !== false) {
entries.splice(found, 1);
}
$("#cs-chatfilters table").data("entries", entries);
formatCSChatFilterList();
},
channelOpts: function(opts) { channelOpts: function(opts) {
document.title = opts.pagetitle; document.title = opts.pagetitle;
PAGETITLE = opts.pagetitle; PAGETITLE = opts.pagetitle;
@ -429,6 +461,7 @@ Callbacks = {
} }
else { else {
CLIENT.name = data.name; CLIENT.name = data.name;
CLIENT.guest = data.guest;
CLIENT.logged_in = true; CLIENT.logged_in = true;
} }
}, },
@ -478,6 +511,11 @@ Callbacks = {
div.data("profile", data.profile); div.data("profile", data.profile);
div.data("meta", data.meta); div.data("meta", data.meta);
div.data("afk", data.meta.afk); div.data("afk", data.meta.afk);
if (data.meta.muted || data.meta.smuted) {
div.data("icon", "glyphicon-volume-off");
} else {
div.data("icon", false);
}
formatUserlistItem(div, data); formatUserlistItem(div, data);
addUserDropdown(div, data); addUserDropdown(div, data);
div.appendTo($("#userlist")); div.appendTo($("#userlist"));

View File

@ -36,7 +36,6 @@ var CHANNEL = {
}; };
var PLAYER = false; var PLAYER = false;
var VIDEOQUALITY = false;
var FLUIDLAYOUT = false; var FLUIDLAYOUT = false;
var VWIDTH; var VWIDTH;
var VHEIGHT; var VHEIGHT;
@ -84,7 +83,7 @@ function setOpt(k, v) {
function getOrDefault(k, def) { function getOrDefault(k, def) {
var v = getOpt(k); var v = getOpt(k);
if(v === null) if(v === null || v === "null")
return def; return def;
if(v === "true") if(v === "true")
return true; return true;
@ -118,7 +117,7 @@ var USEROPTS = {
ignore_channeljs : getOrDefault("ignore_channeljs", false), ignore_channeljs : getOrDefault("ignore_channeljs", false),
sort_rank : getOrDefault("sort_rank", false), sort_rank : getOrDefault("sort_rank", false),
sort_afk : getOrDefault("sort_afk", false), sort_afk : getOrDefault("sort_afk", false),
default_quality : getOrDefault("default_quality", "#quality_auto"), default_quality : getOrDefault("default_quality", ""),
boop : getOrDefault("boop", false), boop : getOrDefault("boop", false),
secure_connection : getOrDefault("secure_connection", false) secure_connection : getOrDefault("secure_connection", false)
}; };

View File

@ -67,10 +67,10 @@ var YouTubePlayer = function (data) {
self.load = function (data) { self.load = function (data) {
if(self.player && self.player.loadVideoById) { if(self.player && self.player.loadVideoById) {
self.player.loadVideoById(data.id, data.currentTime); self.player.loadVideoById(data.id, data.currentTime);
if(VIDEOQUALITY) { if (USEROPTS.default_quality && USEROPTS.default_quality !== "auto") {
self.player.setPlaybackQuality(VIDEOQUALITY); self.player.setPlaybackQuality(USEROPTS.default_quality);
// What's that? Another stupid hack for the HTML5 player? // What's that? Another stupid hack for the HTML5 player?
self.player.setPlaybackQuality(VIDEOQUALITY); self.player.setPlaybackQuality(USEROPTS.default_quality);
} }
self.videoId = data.id; self.videoId = data.id;
self.videoLength = data.seconds; self.videoLength = data.seconds;

View File

@ -539,3 +539,73 @@ $("#cs-jssubmit").click(function () {
js: $("#cs-jstext").val() js: $("#cs-jstext").val()
}); });
}); });
$("#cs-chatfilters-newsubmit").click(function () {
var name = $("#cs-chatfilters-newname").val();
var regex = $("#cs-chatfilters-newregex").val();
var flags = $("#cs-chatfilters-newflags").val();
var replace = $("#cs-chatfilters-newreplace").val();
try {
new RegExp(regex, flags);
} catch (e) {
alert("Regex error: " + e);
return;
}
console.log(name, regex, flags, replace);
socket.emit("updateFilter", {
name: name,
source: regex,
flags: flags,
replace: replace,
active: true
});
$("#cs-chatfilters-newname").val("");
$("#cs-chatfilters-newregex").val("");
$("#cs-chatfilters-newflags").val("");
$("#cs-chatfilters-newreplace").val("");
});
$("#cs-chatfilters-export").click(function () {
var callback = function (data) {
socket.listeners("chatFilters").splice(
socket.listeners("chatFilters").indexOf(callback)
);
$("#cs-chatfilters-exporttext").val(JSON.stringify(data));
};
socket.on("chatFilters", callback);
socket.emit("requestChatFilters");
});
$("#cs-chatfilters-import").click(function () {
var text = $("#cs-chatfilters-exporttext").val();
var choose = confirm("You are about to import filters from the contents of the textbox below the import button. If this is empty, it will clear all of your filters. Are you sure you want to continue?");
if (!choose) {
return;
}
if (text.trim() === "") {
text = "[]";
}
var data;
try {
data = JSON.parse(text);
} catch (e) {
alert("Invalid import data: " + e);
return;
}
var entries = $("#cs-chatfilters table").data("entries") || [];
entries.forEach(function (f) {
socket.emit("removeFilter", f);
});
data.forEach(function (f) {
socket.emit("updateFilter", f);
});
});

View File

@ -139,7 +139,7 @@ function formatUserlistItem(div) {
$("<span/>").addClass("glyphicon glyphicon-time").appendTo(icon); $("<span/>").addClass("glyphicon glyphicon-time").appendTo(icon);
} }
if (data.icon) { if (data.icon) {
$("<span/>").addClass(data.icon).prependTo(icon); $("<span/>").addClass("glyphicon " + data.icon).prependTo(icon);
} }
} }
@ -506,7 +506,8 @@ function rebuildPlaylist() {
/* user settings menu */ /* user settings menu */
function showUserOptions() { function showUserOptions() {
hidePlayer(); hidePlayer();
$("#useroptions").on("hidden", function () { $("#useroptions").on("hidden.bs.modal", function () {
console.log("unhiding");
unhidePlayer(); unhidePlayer();
}); });
@ -528,6 +529,7 @@ function showUserOptions() {
$("#us-hidevideo").prop("checked", USEROPTS.hidevid); $("#us-hidevideo").prop("checked", USEROPTS.hidevid);
$("#us-playlistbuttons").prop("checked", USEROPTS.qbtn_hide); $("#us-playlistbuttons").prop("checked", USEROPTS.qbtn_hide);
$("#us-oldbtns").prop("checked", USEROPTS.qbtn_idontlikechange); $("#us-oldbtns").prop("checked", USEROPTS.qbtn_idontlikechange);
$("#us-default-quality").val(USEROPTS.default_quality || "auto");
$("#us-chat-timestamp").prop("checked", USEROPTS.show_timestamps); $("#us-chat-timestamp").prop("checked", USEROPTS.show_timestamps);
$("#us-sort-rank").prop("checked", USEROPTS.sort_rank); $("#us-sort-rank").prop("checked", USEROPTS.sort_rank);
@ -556,6 +558,7 @@ function saveUserOptions() {
USEROPTS.hidevid = $("#us-hidevideo").prop("checked"); USEROPTS.hidevid = $("#us-hidevideo").prop("checked");
USEROPTS.qbtn_hide = $("#us-playlistbuttons").prop("checked"); USEROPTS.qbtn_hide = $("#us-playlistbuttons").prop("checked");
USEROPTS.qbtn_idontlikechange = $("#us-oldbtns").prop("checked"); USEROPTS.qbtn_idontlikechange = $("#us-oldbtns").prop("checked");
USEROPTS.default_quality = $("#us-default-quality").val();
USEROPTS.show_timestamps = $("#us-chat-timestamp").prop("checked"); USEROPTS.show_timestamps = $("#us-chat-timestamp").prop("checked");
USEROPTS.sort_rank = $("#us-sort-rank").prop("checked"); USEROPTS.sort_rank = $("#us-sort-rank").prop("checked");
@ -839,6 +842,14 @@ function handlePermissionChange() {
setVisible("#clearplaylist", hasPermission("playlistclear")); setVisible("#clearplaylist", hasPermission("playlistclear"));
setVisible("#shuffleplaylist", hasPermission("playlistshuffle")); setVisible("#shuffleplaylist", hasPermission("playlistshuffle"));
// Weird things happen to the alignment in chromium when I toggle visibility
// of the above buttons
// This fixes it?
var wtf = $("#rightcontrols .pull-right").removeClass("pull-right")
setTimeout(function () {
wtf.addClass("pull-right");
}, 1);
setVisible("#newpollbtn", hasPermission("pollctl")); setVisible("#newpollbtn", hasPermission("pollctl"));
$("#voteskip").attr("disabled", !hasPermission("voteskip") || $("#voteskip").attr("disabled", !hasPermission("voteskip") ||
!CHANNEL.opts.allow_voteskip); !CHANNEL.opts.allow_voteskip);
@ -1444,9 +1455,10 @@ function hidePlayer() {
return; return;
PLAYER.size = { PLAYER.size = {
width: $("#ytapiplayer").attr("width"), width: $("#ytapiplayer").width(),
height: $("#ytapiplayer").attr("height") height: $("#ytapiplayer").height()
}; };
$("#ytapiplayer").attr("width", 1) $("#ytapiplayer").attr("width", 1)
.attr("height", 1); .attr("height", 1);
} }
@ -1458,8 +1470,8 @@ function unhidePlayer() {
if(!/(chrome|MSIE)/ig.test(navigator.userAgent)) if(!/(chrome|MSIE)/ig.test(navigator.userAgent))
return; return;
$("#ytapiplayer").attr("width", PLAYER.size.width) $("#ytapiplayer").width(PLAYER.size.width)
.attr("height", PLAYER.size.height); .height(PLAYER.size.height);
} }
function chatDialog(div) { function chatDialog(div) {
@ -1654,7 +1666,7 @@ function makeModal() {
.html("&times;") .html("&times;")
.appendTo(head); .appendTo(head);
wrap.on("hidden", function () { wrap.on("hidden.bs.modal", function () {
unhidePlayer(); unhidePlayer();
wrap.remove(); wrap.remove();
}); });
@ -1832,7 +1844,6 @@ function formatCSChatFilterList() {
$("<span/>").addClass("glyphicon glyphicon-trash").appendTo(del); $("<span/>").addClass("glyphicon glyphicon-trash").appendTo(del);
del.click(function () { del.click(function () {
socket.emit("removeFilter", f); socket.emit("removeFilter", f);
socket.emit("requestChatFilters");
}); });
var name = $("<code/>").text(f.name).appendTo($("<td/>").appendTo(tr)); var name = $("<code/>").text(f.name).appendTo($("<td/>").appendTo(tr));
var activetd = $("<td/>").appendTo(tr); var activetd = $("<td/>").appendTo(tr);
@ -1903,7 +1914,6 @@ function formatCSChatFilterList() {
socket.emit("updateFilter", f); socket.emit("updateFilter", f);
reset(); reset();
socket.emit("requestChatFilters");
}); });
control.data("editor", tr2); control.data("editor", tr2);

View File

@ -492,6 +492,10 @@
margin-top: 10px; margin-top: 10px;
} }
#cs-chatfilters input[type='text'] { #cs-chatfilters input[type='text'], #cs-chatfilters textarea {
font-family: Monospace; font-family: Monospace;
} }
#cs-chatfilters-exporttext {
margin-top: 5px;
}