diff --git a/jinja2/base.html b/jinja2/base.html index 38f2c57..b69d4fa 100644 --- a/jinja2/base.html +++ b/jinja2/base.html @@ -1,6 +1,7 @@ + {% block title %}{% endblock %} - Titivillus {% if request.user == quest.owner %} @@ -34,9 +34,9 @@ {% if post.post_type == "text" %}
{% elif post.post_type == "dice" %} -
+
{% elif post.post_type == "poll" %} -
+
{% endif %}
{{ post.timestamp.strftime('%Y-%m-%d %H:%M') }} @@ -44,9 +44,9 @@ {% if post.post_type == "text" %}
Edit - {% elif (post.post_type == "dice" or post.post_type == "poll") and post == posts|last %} -
- + {% elif post.post_type in ("dice", "poll") and post == posts|last %} +
+ {% endif %} {% endif %}
diff --git a/quest/static/quest.js b/quest/static/quest.js index 9e8a6cb..cebc831 100644 --- a/quest/static/quest.js +++ b/quest/static/quest.js @@ -1 +1,19 @@ var socket = new WebSocket('wss://' + document.domain + SCRIPT_NAME + '/ws/quest/' + quest_id + '/'); +socket.oldSend = socket.send; +socket.send = function(event_title, data) { + data = JSON.stringify({event: event_title, data: data}); + socket.oldSend.apply(this, [data]); +} +socket.events = {}; +socket.onmessage = function(e) { + let data = JSON.parse(e.data); + let event = data.event; + data = data.data; + if (socket.events[event] === undefined) { return; } + socket.events[event](data); +} + +socket.events['message'] = function(data) { + let message = data.message; + console.log(message); +} diff --git a/titivillus/asgi.py b/titivillus/asgi.py index 7e6c91f..9b4d2e7 100644 --- a/titivillus/asgi.py +++ b/titivillus/asgi.py @@ -4,6 +4,7 @@ ASGI entrypoint. Configures Django and then runs the application defined in the ASGI_APPLICATION setting. """ import os + import django from channels.routing import get_default_application