Started functionality for strict-skipping

This commit is contained in:
Kasper Rynning-Tønnesen
2019-01-17 21:52:17 +01:00
parent b9b71ff7db
commit 21988a2883
7 changed files with 104 additions and 24 deletions

View File

@@ -11,6 +11,8 @@ var toShowConfig = {
"userpass": 1,
"vote": 1,
"toggleChat": { $ifNull: [ "$toggleChat", true ] },
"strictSkip": { $ifNull: [ "$strictSkip", false ] },
"strictSkipNumber": { $ifNull: [ "$strictSkipNumber", 10 ] },
"description": { $ifNull: [ "$description", "" ] },
"thumbnail": { $ifNull: [ "$thumbnail", "" ] },
"rules": { $ifNull: [ "$rules", "" ] },

View File

@@ -198,15 +198,20 @@ function skip(list, guid, coll, offline, socket) {
hash = adminpass;
//db.collection(coll + "_settings").find(function(err, docs){
var strictSkip = false;
var strictSkipNumber = 10;
if(docs[0].strictSkip) strictSkip = docs[0].strictSkip;
if(docs[0].strictSkipNumber) strictSkipNumber = docs[0].strictSkipNumber;
if(docs !== null && docs.length !== 0)
{
if(!docs[0].skip || (docs[0].adminpass == hash && docs[0].adminpass !== "") || error)
{
db.collection("frontpage_lists").find({"_id": coll}, function(err, frontpage_viewers){
if((frontpage_viewers[0].viewers/2 <= docs[0].skips.length+1 && !Functions.contains(docs[0].skips, guid) && frontpage_viewers[0].viewers != 2) ||
if(
(strictSkip && ((docs[0].adminpass == hash && docs[0].adminpass !== "") || (docs[0].skips.length+1 >= strictSkipNumber))) ||
(!strictSkip && ((frontpage_viewers[0].viewers/2 <= docs[0].skips.length+1 && !Functions.contains(docs[0].skips, guid) && frontpage_viewers[0].viewers != 2) ||
(frontpage_viewers[0].viewers == 2 && docs[0].skips.length+1 == 2 && !Functions.contains(docs[0].skips, guid)) ||
(docs[0].adminpass == hash && docs[0].adminpass !== "" && docs[0].skip))
(docs[0].adminpass == hash && docs[0].adminpass !== "" && docs[0].skip))))
{
Functions.checkTimeout("skip", 1, coll, coll, error, true, socket, function() {
change_song(coll, error, video_id, docs);
@@ -225,12 +230,25 @@ function skip(list, guid, coll, offline, socket) {
}, "The channel is skipping too often, please wait ");
}else if(!Functions.contains(docs[0].skips, guid)){
db.collection(coll + "_settings").update({ id: "config" }, {$push:{skips:guid}}, function(err, d){
if(frontpage_viewers[0].viewers == 2)
if(frontpage_viewers[0].viewers == 2 && !strictSkip) {
to_skip = 1;
else
} else if(strictSkip) {
to_skip = (strictSkipNumber) - docs[0].skips.length-1;
} else {
to_skip = (Math.ceil(frontpage_viewers[0].viewers/2) - docs[0].skips.length-1);
}
socket.emit("toast", to_skip + " more are needed to skip!");
socket.to(coll).emit('chat', {from: name, msg: " voted to skip"});
db.collection("user_names").find({"guid": guid}, function(err, docs) {
if(docs.length == 1) {
db.collection("registered_users").find({"_id": docs[0].name}, function(err, n) {
var icon = false;
if(n.length > 0 && n[0].icon) {
icon = n[0].icon;
}
socket.to(coll).emit('chat', {from: docs[0].name, msg: " voted to skip"});
})
}
});
});
}else{
socket.emit("toast", "alreadyskip");

View File

@@ -222,6 +222,14 @@ function conf_function(params, coll, guid, offline, socket) {
if(params.hasOwnProperty("toggleChat") && docs[0].adminpass != "" && docs[0].adminpass != undefined && docs[0].adminpass == hash) {
obj.toggleChat = params.toggleChat;
}
if(params.hasOwnProperty("strictSkip") && docs[0].adminpass != "" && docs[0].adminpass != undefined && docs[0].adminpass == hash) {
obj.strictSkip = params.strictSkip;
}
if(params.hasOwnProperty("strictSkipNumber") && docs[0].adminpass != "" && docs[0].adminpass != undefined && docs[0].adminpass == hash) {
try {
obj.strictSkipNumber = parseInt(params.strictSkipNumber);
} catch(e) {}
}
if(params.userpass_changed) {
obj["userpass"] = userpass;
} else if (frontpage) {

View File

@@ -824,12 +824,16 @@ input[type=text]:focus:not([readonly]) + label, input[type=password]:focus:not([
width: 100%;
}
#password{
#password, #strict-input-number{
width: 84%;
margin-left: 30px;
margin-bottom: 0;
}
#strict-input-number {
border-bottom: transparent;
}
span.badge.new,
.progress .determinate,
.progress .indeterminate,
@@ -2412,7 +2416,7 @@ nav ul li:hover, nav ul li.active {
color: lightgrey;
}
#admin-lock
#admin-lock, #strict-skip-lock
{
position:absolute;
display: flex;

View File

@@ -3,6 +3,11 @@ var Admin = {
beginning:true,
logged_in: false,
update_strict_skip: function(value) {
var form = document.getElementById("adminSettingsForm");
form.strictSkipNumber = value;
Admin.submitAdmin(form, false);
},
pw: function(msg) {
Admin.logged_in = msg;
@@ -16,12 +21,16 @@ var Admin = {
if(Helper.html(".suggested-badge") != "0" && Helper.html(".suggested-badge") != "") {
Helper.removeClass(".suggested-badge", "hide");
}
if(conf != undefined && conf.strictSkip) {
Helper.removeClass(".strict-skip-input", "hide");
}
} else {
Admin.hideUserSuggested();
Helper.addClass(".strict-skip-input", "hide");
}
Helper.removeClass(".delete-context-menu", "context-menu-disabled");
names = ["vote","addsongs","longsongs","frontpage", "allvideos",
"removeplay", "skip", "shuffle", "userpass", "toggleChat"];
"removeplay", "skip", "shuffle", "userpass", "toggleChat", "strictSkip"];
//Crypt.set_pass(chan.toLowerCase(), Crypt.tmp_pass);
for (var i = 0; i < names.length; i++) {
@@ -105,7 +114,7 @@ var Admin = {
w_p = true;
adminpass = "";
names = ["vote","addsongs","longsongs","frontpage", "allvideos",
"removeplay", "skip", "shuffle", "toggleChat"];
"removeplay", "skip", "shuffle", "toggleChat", "strictSkip"];
document.getElementById("password").value = "";
Helper.addClass(".info_change_li", "hide");
for (i = 0; i < names.length; i++) {
@@ -120,7 +129,7 @@ var Admin = {
document.getElementById("admin-lock").innerHTML = "lock";
}
Helper.addClass(".strict-skip-input", "hide");
Helper.addClass(".user-password-li", "hide");
Helper.addClass(".chat-toggle-li", "hide");
Helper.addClass(".delete-all", "hide");
@@ -138,7 +147,7 @@ var Admin = {
},
save: function(userpass) {
Admin.submitAdmin(document.getElementById("adminForm").elements, userpass);
Admin.submitAdmin(document.getElementById("adminSettingsForm").elements, userpass);
},
set_conf: function(conf_array) {
@@ -146,7 +155,7 @@ var Admin = {
music = conf_array.allvideos;
longsongs = conf_array.longsongs;
names = ["vote","addsongs","longsongs","frontpage", "allvideos",
"removeplay", "skip", "shuffle", "userpass", "toggleChat"];
"removeplay", "skip", "shuffle", "userpass", "toggleChat", "strictSkip"];
if(!conf.hasOwnProperty("toggleChat")) conf.toggleChat = true;
toggleChat = conf.toggleChat;
hasadmin = conf_array.adminpass != "";
@@ -163,6 +172,7 @@ var Admin = {
document.getElementsByName(names[i])[0].removeAttribute("disabled");
}
}
document.getElementById("strict-input-number").value = conf.strictSkipNumber;
if((hasadmin) && !Admin.logged_in) {
if(Helper.html("#admin-lock") != "lock") Admin.display_logged_out();
} else if(!hasadmin) {
@@ -172,7 +182,14 @@ var Admin = {
Helper.removeClass(".change_user_pass", "hide");
}
}
if(Admin.logged_in) {
if(conf != undefined && conf.strictSkip) {
Helper.removeClass(".strict-skip-input", "hide");
}
}
if(conf != undefined && !conf.strictSkip) {
Helper.addClass(".strict-skip-input", "hide");
}
if(!document.getElementsByClassName("password_protected")[0].checked) {
Helper.addClass(".change_user_pass", "hide");
//Crypt.remove_userpass(chan.toLowerCase());
@@ -217,6 +234,13 @@ var Admin = {
skipping = form.skip.checked;
shuffling = form.shuffle.checked;
toggleChat = form.toggleChat.checked;
strictSkip = form.strictSkip.checked;
if(form.strictSkipNumber) {
strictSkipNumber = form.strictSkipNumber;
} else {
strictSkipNumber = conf.strictSkipNumber;
}
var pass_send = userpass_changed && !form.userpass.checked ? "" : userpass;
configs = {
@@ -231,8 +255,10 @@ var Admin = {
skipping: skipping,
shuffling: shuffling,
toggleChat: toggleChat,
strictSkip: strictSkip,
userpass: Crypt.crypt_pass(pass_send),
userpass_changed: userpass_changed
userpass_changed: userpass_changed,
strictSkipNumber: strictSkipNumber
};
emit("conf", configs);

View File

@@ -1267,6 +1267,11 @@ function addDynamicListeners() {
Admin.pass_save();
});
addListener("submit", "#strictSkipForm", function(event){
this.preventDefault();
Admin.update_strict_skip(document.getElementById("strict-input-number").value);
});
addListener("click", "#channel-share-modal", function(){
M.Modal.getInstance(document.getElementById("channel-share-modal")).close();
});

View File

@@ -5,14 +5,16 @@
</div>
<div class="collapsible-body">
<ul>
<form action="#" id="adminForm" onsubmit="return false;">
<form action="#" id="adminForm" onsubmit="return false;">
<li class="white-bg">
<div class="input-field field-settings">
<i id="admin-lock" class="material-icons">lock</i>
<input placeholder="Enter admin password" id="password" type="password" class="validate" />
</div>
</li>
</form>
<form action="#" id="adminSettingsForm" onsubmit="return false;">
<li>
<span class="switch-text">
Add songs
@@ -25,7 +27,6 @@
</label>
</div>
</li>
<li>
<span class="switch-text">
Vote
@@ -51,7 +52,6 @@
</label>
</div>
</li>
<li>
<span class="switch-text">
Skip
@@ -64,7 +64,6 @@
</label>
</div>
</li>
<li>
<span class="switch-text">
Song length
@@ -77,7 +76,6 @@
</label>
</div>
</li>
<li>
<span class="switch-text">
Type
@@ -114,6 +112,18 @@
</label>
</div>
</li>
<li>
<span class="switch-text">
Strict skip
</span>
<div class="switch">
<label>
<span class="left-span">Off</span>
<input name="strictSkip" type="checkbox" class="conf" /><span class="lever"></span>
<span class="right-span">On</span>
</label>
</div>
</li>
<li class="chat-toggle-li hide">
<span class="switch-text">
Chat
@@ -139,7 +149,14 @@
</div>
</li>
</form>
<form action="#" id="strictSkipForm" onsubmit="return false;">
<li class="white-bg strict-skip-input hide">
<div class="input-field field-settings">
<i id="strict-skip-lock" class="material-icons">queue_play_next</i>
<input placeholder="Strict skip number" id="strict-input-number" type="number" class="validate" />
</div>
</li>
</form>
<li class="change_user_pass hide">
<a href="#!" class="change_user_pass_btn btn waves-effect blue">Change password</a>
</li>