diff --git a/anonkun.py b/anonkun.py index ab78cc1..e60eeb5 100644 --- a/anonkun.py +++ b/anonkun.py @@ -99,6 +99,19 @@ def get_dice_challenge(post_id): return db.get_dice_call(post_id)[3] +@app.template_filter("is_write_in") +def is_write_in(post_id): + """ + Returns true if the provided post_id is a poll write-in's are + allowed in it. + """ + poll = db.get_poll(post_id) + if poll and poll[3]: + return True + else: + return False + + @app.after_request def minify(res): """ diff --git a/database.py b/database.py index b2bb914..0c3a27f 100644 --- a/database.py +++ b/database.py @@ -295,6 +295,12 @@ def insert_poll_option(post_id, option_text): + "(`post_id`, `option_text`) VALUES (%s, %s)", (post_id, option_text)) + option_id = _DB.execute( + "SELECT `option_id` FROM `poll_options` WHERE `post_id` = %s " \ + + "ORDER BY `option_id` DESC", + (post_id,)).fetchone()[0] + return option_id + def get_poll_options(quest_id): """Gets all relevent poll options for a given quest or post.""" diff --git a/events.py b/events.py index 2591f90..f80dcbe 100644 --- a/events.py +++ b/events.py @@ -296,8 +296,10 @@ def poll_post(data): post_id = db.insert_quest_post(room, "poll", post, date) db.insert_poll(post_id, room, multi_choice, allow_writein) + new_options = [] for option in options: - db.insert_poll_option(post_id, option) + option_id = db.insert_poll_option(post_id, option) + new_options.append((option_id, option)) db.set_post_open(post_id, room) data = {} @@ -305,7 +307,7 @@ def poll_post(data): data["post_id"] = post_id data["post_type"] = "poll" data["date"] = int(time.time()) - data["options"] = options + data["options"] = new_options emit("new_post", data, room=room) @@ -336,6 +338,7 @@ def vote(data): data["option_id"] = vote[0] data["polarity"] = False emit("vote", data, room=room) + emit("toggle_option_box", data, room=request.sid) db.insert_poll_vote(option_id, ip_address) diff --git a/static/anonkun.css b/static/anonkun.css index 1437e3e..f1a4620 100644 --- a/static/anonkun.css +++ b/static/anonkun.css @@ -163,6 +163,10 @@ h3 { color: black; } +#writeinInput { + width: 100%; +} + #chatPane { height: 100%; width: 30%; diff --git a/static/anonkunQM.js b/static/anonkunQM.js new file mode 100644 index 0000000..231c720 --- /dev/null +++ b/static/anonkunQM.js @@ -0,0 +1,212 @@ +document.execCommand("defaultParagraphSeparator", false, "br"); +var socket; +var tid = setInterval( function () { + if ( document.readyState !== 'complete' ) return; + clearInterval( tid ); + + document.getElementById('chatWindow').scrollTop = document.getElementById('chatWindow').scrollHeight; + socket = io.connect('https://' + document.domain + ':' + location.port); + socket.on('connect', function() { + socket.emit('joined', {room: room_id}); + }); + socket.on('message', function(data) { + let msg_str = '
'; + msg_str += ''; + post_str += ' | '; + post_str += '' + data.options[i][1] + ' | '; + post_str += '0 |
'; + post_str += ' | '; + post_str += '' + data.options[i][1] + ' | '; + post_str += '0 |