close active dicecalls upon new posts being made
This commit is contained in:
parent
3a42f8dcc9
commit
06583bb346
|
@ -4,7 +4,7 @@ By popular demand, I'm building a better anonkun. It doesn't do much right now t
|
|||
## Requirements
|
||||
Python 3.6+
|
||||
MariaDB 10.2+
|
||||
Python packages: `flask flask_socketio flask-paranoid passlib argon2_cffi bleach flask-session requests python-magic`
|
||||
Python packages: `flask flask_socketio flask-paranoid passlib argon2_cffi bleach flask-session requests python-magic gunicorn eventlet`
|
||||
|
||||
## Install
|
||||
```
|
||||
|
|
|
@ -132,6 +132,7 @@ def new_post(data, internal=False):
|
|||
data["post_type"] = "text"
|
||||
data["date"] = int(time.time())
|
||||
post_id = db.insert_quest_post(room, "text", post, data["date"])
|
||||
db.set_dice_call_closed(room);
|
||||
data["post_id"] = post_id
|
||||
|
||||
emit("new_post", data, room=room)
|
||||
|
@ -248,6 +249,7 @@ def open_dice_call(data):
|
|||
if session.get("user_id") != res[3]:
|
||||
return
|
||||
|
||||
# TODO: enforce only open if last post
|
||||
post_id = data.get("post_id")
|
||||
db.set_dice_call_open(post_id, room)
|
||||
|
||||
|
|
|
@ -24,14 +24,20 @@
|
|||
mbox.scrollTop = mbox.scrollHeight;
|
||||
});
|
||||
socket.on('new_post', function(data) {
|
||||
deactivate_post();
|
||||
let qposts = document.getElementById('questPosts');
|
||||
let post_str = '<div class="questPost"><div class="questPostMeta">' + strftime(data.date);
|
||||
let post_str = '<div class="questPost ';
|
||||
if (data.post_type == 'text') {
|
||||
post_str += 'textPost">';
|
||||
} else if (data.post_type == 'dice') {
|
||||
post_str += 'dicePost active_post">';
|
||||
}
|
||||
post_str += '<div class="questPostMeta">' + strftime(data.date);
|
||||
{% if session.get("user_id") == owner_id %}
|
||||
if (data.post_type == 'text') {
|
||||
post_str += '<br /><a href="javascript:void(0);" onclick="edit_post(\'' + data.post_id + '\')">Edit</a>';
|
||||
post_str += '<a href="javascript:void(0);" id="savePost-' + data.post_id + '" onclick="save_post(\'' + data.post_id + '\')" style="display:none;">Save</a>';
|
||||
}
|
||||
else if (data.post_type == 'dice') {
|
||||
} else if (data.post_type == 'dice') {
|
||||
post_str += '<br /><a href="javascript:void(0);" id="close_dc-' + data.post_id + '" onclick="close_dice_call(' + data.post_id + ')">Close</a>';
|
||||
post_str += '<a href="javascript:void(0);" id="open_dc-' + data.post_id + '" onclick="open_dice_call(' + data.post_id + ')" style="display:none;">Open</a>'
|
||||
}
|
||||
|
@ -39,8 +45,7 @@
|
|||
post_str += '</div><div class="questPostData" id="questPostData-' + data.post_id + '">';
|
||||
if (data.post_type == 'text') {
|
||||
post_str += data.post;
|
||||
}
|
||||
else if (data.post_type == 'dice') {
|
||||
} else if (data.post_type == 'dice') {
|
||||
post_str += '<h3>' + data.post + ' - Open</h3>';
|
||||
}
|
||||
post_str += '</div></div><br />';
|
||||
|
@ -58,7 +63,7 @@
|
|||
});
|
||||
socket.on('close_dice_call', function(data) {
|
||||
let post = document.getElementById('questPostData-' + data.post_id);
|
||||
post.firstElementChild.textContent = post.firstElementChild.textContent.replace('Open', 'Closed');
|
||||
post.children[0].textContent = post.children[0].textContent.replace('Open', 'Closed');
|
||||
});
|
||||
socket.on('open_dice_call', function(data) {
|
||||
let post = document.getElementById('questPostData-' + data.post_id);
|
||||
|
@ -131,6 +136,17 @@
|
|||
document.getElementById('open_dc-' + post_id).style.display = 'none';
|
||||
socket.emit('open_dice_call', {post_id: post_id, room: {{ room_id }}});
|
||||
}
|
||||
function deactivate_post() {
|
||||
let post = document.getElementsByClassName('active_post');
|
||||
if (post.length == 0) { return; }
|
||||
post = post[0];
|
||||
if (post.classList.contains('dicePost')) {
|
||||
post.children[1].children[0].textContent = post.children[1].children[0].textContent.replace('Open', 'Closed');
|
||||
post.classList.remove("active_post");
|
||||
post.children[0].children[2].outerHTML = "";
|
||||
post.children[0].children[1].outerHTML = "";
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
function openPostTab(event, modeName) {
|
||||
|
@ -163,7 +179,11 @@
|
|||
<center><h1>{{ quest_title }}</h1></center>
|
||||
<div id="questPosts">
|
||||
{% for quest_post in quest_posts %}
|
||||
<div class="questPost">
|
||||
{% if quest_post[2] == "text" %}
|
||||
<div class="questPost textPost">
|
||||
{% elif quest_post[2] == "dice" %}
|
||||
<div class="questPost dicePost{% if quest_post == quest_posts|last %} active_post{% endif %}">
|
||||
{% endif %}
|
||||
<div class="questPostMeta">
|
||||
{{ quest_post[4] | strftime }}
|
||||
{% if session.get("user_id") == owner_id %}
|
||||
|
|
Loading…
Reference in New Issue
Block a user