stop passing quest_id in socket events
This commit is contained in:
parent
1fbc398a9a
commit
5eb19761bd
|
@ -24,9 +24,9 @@ def message(socket, data):
|
||||||
"""
|
"""
|
||||||
# TODO: validation
|
# TODO: validation
|
||||||
message = data.get('message')
|
message = data.get('message')
|
||||||
quest_id = data.get('quest_id')
|
|
||||||
|
|
||||||
# cleaning
|
# cleaning
|
||||||
|
message = message[:512]
|
||||||
message = message.strip()
|
message = message.strip()
|
||||||
if not message:
|
if not message:
|
||||||
return
|
return
|
||||||
|
@ -82,7 +82,7 @@ def message(socket, data):
|
||||||
user = socket.scope['user']
|
user = socket.scope['user']
|
||||||
|
|
||||||
m = Message(
|
m = Message(
|
||||||
quest=Quest.objects.get(id=quest_id),
|
quest=Quest.objects.get(id=socket.quest_id),
|
||||||
message=message)
|
message=message)
|
||||||
if user.username:
|
if user.username:
|
||||||
m.user = user
|
m.user = user
|
||||||
|
@ -98,7 +98,10 @@ def message(socket, data):
|
||||||
# append rolls to dicecall
|
# append rolls to dicecall
|
||||||
if any(map(message.startswith, ["/dice", "/roll"])):
|
if any(map(message.startswith, ["/dice", "/roll"])):
|
||||||
try:
|
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:
|
except DiceCall.DoesNotExist:
|
||||||
return
|
return
|
||||||
dice_roll = f"{dice_num}d{dice_sides}"
|
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.
|
Called when the QM creates a new text post.
|
||||||
"""
|
"""
|
||||||
# TODO: security
|
# TODO: security
|
||||||
quest_id = data.get('quest_id')
|
|
||||||
post_text = data.get('text')
|
post_text = data.get('text')
|
||||||
page_num = data.get('page_num')
|
page_num = data.get('page_num')
|
||||||
|
|
||||||
|
@ -152,7 +154,7 @@ def text_post(socket, data):
|
||||||
# handle image
|
# handle image
|
||||||
|
|
||||||
p = Post(
|
p = Post(
|
||||||
quest=Quest.objects.get(id=quest_id),
|
quest=Quest.objects.get(id=socket.quest_id),
|
||||||
page_num=page_num,
|
page_num=page_num,
|
||||||
post_type='text',
|
post_type='text',
|
||||||
post_text=post_text)
|
post_text=post_text)
|
||||||
|
@ -170,7 +172,6 @@ def dice_post(socket, data):
|
||||||
"""
|
"""
|
||||||
Called when the QM makes a new dice post.
|
Called when the QM makes a new dice post.
|
||||||
"""
|
"""
|
||||||
quest_id = data.get('quest_id')
|
|
||||||
page_num = data.get('page_num')
|
page_num = data.get('page_num')
|
||||||
form = DiceCallForm(data)
|
form = DiceCallForm(data)
|
||||||
if not form.is_valid():
|
if not form.is_valid():
|
||||||
|
@ -178,7 +179,7 @@ def dice_post(socket, data):
|
||||||
form = form.cleaned_data
|
form = form.cleaned_data
|
||||||
|
|
||||||
posts = Post.objects.filter(
|
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:
|
for post in posts:
|
||||||
post.dicecall.open = False
|
post.dicecall.open = False
|
||||||
post.dicecall.save()
|
post.dicecall.save()
|
||||||
|
@ -196,7 +197,7 @@ def dice_post(socket, data):
|
||||||
post_text += " vs DC" + str(form['diceChal'])
|
post_text += " vs DC" + str(form['diceChal'])
|
||||||
|
|
||||||
p = Post(
|
p = Post(
|
||||||
quest=Quest.objects.get(id=quest_id),
|
quest=Quest.objects.get(id=socket.quest_id),
|
||||||
page_num=page_num,
|
page_num=page_num,
|
||||||
post_type='dice',
|
post_type='dice',
|
||||||
post_text=post_text
|
post_text=post_text
|
||||||
|
@ -224,7 +225,6 @@ def poll_post(socket, data):
|
||||||
"""
|
"""
|
||||||
Called when the QM makes a new dice post.
|
Called when the QM makes a new dice post.
|
||||||
"""
|
"""
|
||||||
quest_id = data.get('quest_id')
|
|
||||||
page_num = data.get('page_num')
|
page_num = data.get('page_num')
|
||||||
form = PollForm(data)
|
form = PollForm(data)
|
||||||
if not form.is_valid():
|
if not form.is_valid():
|
||||||
|
@ -232,7 +232,7 @@ def poll_post(socket, data):
|
||||||
form = form.cleaned_data
|
form = form.cleaned_data
|
||||||
|
|
||||||
p = Post(
|
p = Post(
|
||||||
quest=Quest.objects.get(id=quest_id),
|
quest=Quest.objects.get(id=socket.quest_id),
|
||||||
page_num=page_num,
|
page_num=page_num,
|
||||||
post_type='poll',
|
post_type='poll',
|
||||||
post_text="Poll"
|
post_text="Poll"
|
||||||
|
@ -292,7 +292,6 @@ def close_post(socket, data):
|
||||||
Called when the QM closes an open post.
|
Called when the QM closes an open post.
|
||||||
"""
|
"""
|
||||||
post_id = data.get('post_id')
|
post_id = data.get('post_id')
|
||||||
quest_id = data.get('quest_id')
|
|
||||||
p = Post.objects.get(id=post_id)
|
p = Post.objects.get(id=post_id)
|
||||||
if data.get('post_type') == 'dice':
|
if data.get('post_type') == 'dice':
|
||||||
p.dicecall.open = False
|
p.dicecall.open = False
|
||||||
|
@ -312,11 +311,10 @@ def open_post(socket, data):
|
||||||
"""
|
"""
|
||||||
# TODO: only posts on last page can be opened
|
# TODO: only posts on last page can be opened
|
||||||
post_id = data.get('post_id')
|
post_id = data.get('post_id')
|
||||||
quest_id = data.get('quest_id')
|
|
||||||
p = Post.objects.get(id=post_id)
|
p = Post.objects.get(id=post_id)
|
||||||
if data.get('post_type') == 'dice':
|
if data.get('post_type') == 'dice':
|
||||||
posts = Post.objects.filter(
|
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:
|
for post in posts:
|
||||||
post.dicecall.open = False
|
post.dicecall.open = False
|
||||||
post.dicecall.save()
|
post.dicecall.save()
|
||||||
|
@ -337,7 +335,6 @@ def vote(socket, data):
|
||||||
"""
|
"""
|
||||||
Called when a player votes in a poll.
|
Called when a player votes in a poll.
|
||||||
"""
|
"""
|
||||||
quest_id = data.get('quest_id')
|
|
||||||
post_id = data.get('post_id')
|
post_id = data.get('post_id')
|
||||||
option_id = data.get('option_id')
|
option_id = data.get('option_id')
|
||||||
polarity = data.get('polarity')
|
polarity = data.get('polarity')
|
||||||
|
|
|
@ -41,8 +41,7 @@ function load() {
|
||||||
let text = mtarea.value.trim();
|
let text = mtarea.value.trim();
|
||||||
mtarea.value = '';
|
mtarea.value = '';
|
||||||
if (text === '') { return; }
|
if (text === '') { return; }
|
||||||
document.getElementById('chatWindow').scrollTop = document.getElementById('chatWindow').scrollHeight;
|
socket.send('message', {message: text});
|
||||||
socket.send('message', {message: text, quest_id: quest_id});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -57,7 +56,7 @@ socket.events['message'] = function(data) {
|
||||||
|
|
||||||
let mbox = document.getElementById('chatWindow');
|
let mbox = document.getElementById('chatWindow');
|
||||||
mbox.innerHTML = mbox.innerHTML + msg_str;
|
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;
|
mbox.scrollTop = mbox.scrollHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,7 +81,7 @@ socket.events['new_post'] = function(data) {
|
||||||
post_str += '<table class="poll" id="poll-' + data.post_id + '">';
|
post_str += '<table class="poll" id="poll-' + data.post_id + '">';
|
||||||
for (let i = 0; i < data.options.length; i++) {
|
for (let i = 0; i < data.options.length; i++) {
|
||||||
post_str += '<tr id="optionRow-' + data.options[i] + '">';
|
post_str += '<tr id="optionRow-' + data.options[i] + '">';
|
||||||
post_str += '<td class="pollCheckBox"><input type="checkbox" id="pollInput-' + data.options[i][0] + '" onchange="vote(' + data.post_id + ',' + data.options[i][0] + ')"/>';
|
post_str += '<td class="pollCheckBox"><input type="checkbox" id="pollInput-' + data.options[i][0] + '" onchange="vote(' + data.post_id + ',' + data.options[i][0] + ')">';
|
||||||
post_str += '<label for="pollInput-' + data.options[i][0] + '"></label></td>';
|
post_str += '<label for="pollInput-' + data.options[i][0] + '"></label></td>';
|
||||||
post_str += '<td class="option_text">' + data.options[i][1] + '</td>';
|
post_str += '<td class="option_text">' + data.options[i][1] + '</td>';
|
||||||
post_str += '<td class="optionVotes">0</td></tr>';
|
post_str += '<td class="optionVotes">0</td></tr>';
|
||||||
|
@ -159,7 +158,7 @@ socket.events['set_option_box'] = function(data) {
|
||||||
/* Websocket send */
|
/* Websocket send */
|
||||||
function vote(post_id, option_id) {
|
function vote(post_id, option_id) {
|
||||||
let polarity = document.getElementById('pollInput-' + option_id).checked;
|
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) {
|
function submitWritein(post_id) {
|
||||||
let writeinInput = document.getElementById('writeinInput-' + post_id);
|
let writeinInput = document.getElementById('writeinInput-' + post_id);
|
||||||
|
|
|
@ -51,7 +51,7 @@ function makePost() {
|
||||||
let text = qparea.value.trim();
|
let text = qparea.value.trim();
|
||||||
qparea.value = '';
|
qparea.value = '';
|
||||||
if (text === '') { return; }
|
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) {
|
function save_post(post_id) {
|
||||||
let post = document.getElementById('questPostData-' + post_id);
|
let post = document.getElementById('questPostData-' + post_id);
|
||||||
|
@ -68,13 +68,12 @@ function form_post(form_id, event) {
|
||||||
formData.forEach(function(value, key) {
|
formData.forEach(function(value, key) {
|
||||||
obj[key] = value;
|
obj[key] = value;
|
||||||
});
|
});
|
||||||
obj.quest_id = quest_id;
|
|
||||||
obj.page_num = page_num;
|
obj.page_num = page_num;
|
||||||
socket.send(event, obj);
|
socket.send(event, obj);
|
||||||
document.getElementById(form_id).reset();
|
document.getElementById(form_id).reset();
|
||||||
}
|
}
|
||||||
function close_post_send(post_id) {
|
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);
|
let post = document.getElementById('questPostData-' + post_id);
|
||||||
if (post.parentElement.classList.contains('dicePost')) {
|
if (post.parentElement.classList.contains('dicePost')) {
|
||||||
data.post_type = 'dice';
|
data.post_type = 'dice';
|
||||||
|
@ -84,7 +83,7 @@ function close_post_send(post_id) {
|
||||||
socket.send('close_post', data);
|
socket.send('close_post', data);
|
||||||
}
|
}
|
||||||
function open_post_send(post_id) {
|
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);
|
let post = document.getElementById('questPostData-' + post_id);
|
||||||
if (post.parentElement.classList.contains('dicePost')) {
|
if (post.parentElement.classList.contains('dicePost')) {
|
||||||
data.post_type = 'dice';
|
data.post_type = 'dice';
|
||||||
|
|
Loading…
Reference in New Issue
Block a user