From 06583bb3469018716b93222f6a5bd12f5917f402 Mon Sep 17 00:00:00 2001 From: iou1name Date: Sun, 8 Jul 2018 20:19:19 -0400 Subject: [PATCH] close active dicecalls upon new posts being made --- README.md | 2 +- events.py | 2 ++ templates/quest.html | 34 +++++++++++++++++++++++++++------- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4579c0f..75fc60d 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/events.py b/events.py index 651364e..8879417 100644 --- a/events.py +++ b/events.py @@ -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) diff --git a/templates/quest.html b/templates/quest.html index 7c8ff45..d312029 100644 --- a/templates/quest.html +++ b/templates/quest.html @@ -24,14 +24,20 @@ mbox.scrollTop = mbox.scrollHeight; }); socket.on('new_post', function(data) { + deactivate_post(); let qposts = document.getElementById('questPosts'); - let post_str = '
' + strftime(data.date); + let post_str = '
'; + } else if (data.post_type == 'dice') { + post_str += 'dicePost active_post">'; + } + post_str += '
' + strftime(data.date); {% if session.get("user_id") == owner_id %} if (data.post_type == 'text') { post_str += '
Edit'; post_str += ''; - } - else if (data.post_type == 'dice') { + } else if (data.post_type == 'dice') { post_str += '
Close'; post_str += '' } @@ -39,8 +45,7 @@ post_str += '
'; if (data.post_type == 'text') { post_str += data.post; - } - else if (data.post_type == 'dice') { + } else if (data.post_type == 'dice') { post_str += '

' + data.post + ' - Open

'; } post_str += '

'; @@ -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 = ""; + } + }