diff --git a/quest/events.py b/quest/events.py index 9e9f367..8ca51e1 100644 --- a/quest/events.py +++ b/quest/events.py @@ -24,9 +24,9 @@ def message(socket, data): """ # TODO: validation message = data.get('message') - quest_id = data.get('quest_id') # cleaning + message = message[:512] message = message.strip() if not message: return @@ -82,7 +82,7 @@ def message(socket, data): user = socket.scope['user'] m = Message( - quest=Quest.objects.get(id=quest_id), + quest=Quest.objects.get(id=socket.quest_id), message=message) if user.username: m.user = user @@ -98,7 +98,10 @@ def message(socket, data): # append rolls to dicecall if any(map(message.startswith, ["/dice", "/roll"])): try: - dc = DiceCall.objects.get(post__quest__id=quest_id, open=True) + dc = DiceCall.objects.get( + post__quest__id=socket.quest_id, + open=True + ) except DiceCall.DoesNotExist: return dice_roll = f"{dice_num}d{dice_sides}" @@ -141,7 +144,6 @@ def text_post(socket, data): Called when the QM creates a new text post. """ # TODO: security - quest_id = data.get('quest_id') post_text = data.get('text') page_num = data.get('page_num') @@ -152,7 +154,7 @@ def text_post(socket, data): # handle image p = Post( - quest=Quest.objects.get(id=quest_id), + quest=Quest.objects.get(id=socket.quest_id), page_num=page_num, post_type='text', post_text=post_text) @@ -170,7 +172,6 @@ def dice_post(socket, data): """ Called when the QM makes a new dice post. """ - quest_id = data.get('quest_id') page_num = data.get('page_num') form = DiceCallForm(data) if not form.is_valid(): @@ -178,7 +179,7 @@ def dice_post(socket, data): form = form.cleaned_data posts = Post.objects.filter( - quest__id=quest_id, post_type='dice', dicecall__open=True) + quest__id=socket.quest_id, post_type='dice', dicecall__open=True) for post in posts: post.dicecall.open = False post.dicecall.save() @@ -196,7 +197,7 @@ def dice_post(socket, data): post_text += " vs DC" + str(form['diceChal']) p = Post( - quest=Quest.objects.get(id=quest_id), + quest=Quest.objects.get(id=socket.quest_id), page_num=page_num, post_type='dice', post_text=post_text @@ -224,7 +225,6 @@ def poll_post(socket, data): """ Called when the QM makes a new dice post. """ - quest_id = data.get('quest_id') page_num = data.get('page_num') form = PollForm(data) if not form.is_valid(): @@ -232,7 +232,7 @@ def poll_post(socket, data): form = form.cleaned_data p = Post( - quest=Quest.objects.get(id=quest_id), + quest=Quest.objects.get(id=socket.quest_id), page_num=page_num, post_type='poll', post_text="Poll" @@ -292,7 +292,6 @@ def close_post(socket, data): Called when the QM closes an open post. """ post_id = data.get('post_id') - quest_id = data.get('quest_id') p = Post.objects.get(id=post_id) if data.get('post_type') == 'dice': p.dicecall.open = False @@ -312,11 +311,10 @@ def open_post(socket, data): """ # TODO: only posts on last page can be opened post_id = data.get('post_id') - quest_id = data.get('quest_id') p = Post.objects.get(id=post_id) if data.get('post_type') == 'dice': posts = Post.objects.filter( - quest__id=quest_id, post_type='dice', dicecall__open=True) + quest__id=socket.quest_id, post_type='dice', dicecall__open=True) for post in posts: post.dicecall.open = False post.dicecall.save() @@ -337,7 +335,6 @@ def vote(socket, data): """ Called when a player votes in a poll. """ - quest_id = data.get('quest_id') post_id = data.get('post_id') option_id = data.get('option_id') polarity = data.get('polarity') diff --git a/quest/static/quest.js b/quest/static/quest.js index 479fdc3..d559d17 100644 --- a/quest/static/quest.js +++ b/quest/static/quest.js @@ -41,8 +41,7 @@ function load() { let text = mtarea.value.trim(); mtarea.value = ''; if (text === '') { return; } - document.getElementById('chatWindow').scrollTop = document.getElementById('chatWindow').scrollHeight; - socket.send('message', {message: text, quest_id: quest_id}); + socket.send('message', {message: text}); } }); } @@ -57,7 +56,7 @@ socket.events['message'] = function(data) { let mbox = document.getElementById('chatWindow'); mbox.innerHTML = mbox.innerHTML + msg_str; - if ((mbox.scrollTop + mbox.offsetHeight) >= (mbox.scrollHeight - mbox.clientHeight / 2)) { + if ((mbox.scrollTop + mbox.offsetHeight) >= (mbox.scrollHeight - mbox.clientHeight)) { mbox.scrollTop = mbox.scrollHeight; } } @@ -82,7 +81,7 @@ socket.events['new_post'] = function(data) { post_str += ''; for (let i = 0; i < data.options.length; i++) { post_str += ''; - post_str += ''; post_str += ''; post_str += ''; @@ -159,7 +158,7 @@ socket.events['set_option_box'] = function(data) { /* Websocket send */ function vote(post_id, option_id) { let polarity = document.getElementById('pollInput-' + option_id).checked; - socket.send('vote', {post_id: post_id, option_id: option_id, polarity: polarity, quest_id: quest_id}); + socket.send('vote', {post_id: post_id, option_id: option_id, polarity: polarity}); } function submitWritein(post_id) { let writeinInput = document.getElementById('writeinInput-' + post_id); diff --git a/quest/static/questQM.js b/quest/static/questQM.js index e017228..f2e360d 100644 --- a/quest/static/questQM.js +++ b/quest/static/questQM.js @@ -51,7 +51,7 @@ function makePost() { let text = qparea.value.trim(); qparea.value = ''; if (text === '') { return; } - socket.send('text_post', {text: text, page_num: page_num, quest_id: quest_id}); + socket.send('text_post', {text: text, page_num: page_num}); } function save_post(post_id) { let post = document.getElementById('questPostData-' + post_id); @@ -68,13 +68,12 @@ function form_post(form_id, event) { formData.forEach(function(value, key) { obj[key] = value; }); - obj.quest_id = quest_id; obj.page_num = page_num; socket.send(event, obj); document.getElementById(form_id).reset(); } function close_post_send(post_id) { - data = {post_id: post_id, quest_id: quest_id} + data = {post_id: post_id} let post = document.getElementById('questPostData-' + post_id); if (post.parentElement.classList.contains('dicePost')) { data.post_type = 'dice'; @@ -84,7 +83,7 @@ function close_post_send(post_id) { socket.send('close_post', data); } function open_post_send(post_id) { - data = {post_id: post_id, quest_id: quest_id} + data = {post_id: post_id} let post = document.getElementById('questPostData-' + post_id); if (post.parentElement.classList.contains('dicePost')) { data.post_type = 'dice';
'; + post_str += ''; post_str += '' + data.options[i][1] + '0