new post sends chat message
This commit is contained in:
parent
5f5591736f
commit
377f20439e
|
@ -25,6 +25,7 @@ titivillus=# \q
|
|||
2. Walk the dinosaur
|
||||
3. Set `STATIC_ROOT` under `settings.py` appropriately
|
||||
4. Run `python manage.py collectstatic`
|
||||
5. Create \[super\]user named `Server` and set id in settings.py
|
||||
|
||||
## Usage
|
||||
`gunicorn -b localhost:5100 -e SCRIPT_NAME=/titivillus titivillus.wsgi`
|
||||
|
|
|
@ -11,6 +11,7 @@ import types
|
|||
import random
|
||||
|
||||
import bleach
|
||||
from django.conf import settings
|
||||
from django.db import IntegrityError
|
||||
from django.utils.timezone import localtime
|
||||
from django.urls import reverse
|
||||
|
@ -18,6 +19,7 @@ from django.urls import reverse
|
|||
from quest.models import *
|
||||
from quest.tools import handle_img
|
||||
from quest.forms import DiceCallForm, PollForm
|
||||
from user.models import User
|
||||
|
||||
def message(socket, data):
|
||||
"""
|
||||
|
@ -172,6 +174,21 @@ def text_post(socket, data):
|
|||
data['post_id'] = p.id
|
||||
socket.send('new_post', data)
|
||||
|
||||
server = User.objects.get(id=settings.SERVER_USER_ID)
|
||||
m = Message(
|
||||
quest=quest,
|
||||
user=server,
|
||||
message=f"{quest.owner.username} made a new post!",
|
||||
)
|
||||
m.save()
|
||||
data = {}
|
||||
data['message_id'] = m.id
|
||||
data['message'] = m.message
|
||||
data['date'] = int(time.time())
|
||||
data['name'] = server.username
|
||||
data['anonymize'] = False
|
||||
socket.send('message', data)
|
||||
|
||||
|
||||
def dice_post(socket, data):
|
||||
"""
|
||||
|
@ -226,6 +243,21 @@ def dice_post(socket, data):
|
|||
data['date'] = localtime(p.timestamp).strftime('%Y-%m-%d %H:%M')
|
||||
socket.send('new_post', data)
|
||||
|
||||
server = User.objects.get(id=settings.SERVER_USER_ID)
|
||||
m = Message(
|
||||
quest=quest,
|
||||
user=server,
|
||||
message=f"{quest.owner.username} made a new dice call!",
|
||||
)
|
||||
m.save()
|
||||
data = {}
|
||||
data['message_id'] = m.id
|
||||
data['message'] = m.message
|
||||
data['date'] = int(time.time())
|
||||
data['name'] = server.username
|
||||
data['anonymize'] = False
|
||||
socket.send('message', data)
|
||||
|
||||
|
||||
def poll_post(socket, data):
|
||||
"""
|
||||
|
@ -269,6 +301,21 @@ def poll_post(socket, data):
|
|||
data['options'] = [(o.id, o.text) for o in options]
|
||||
socket.send('new_post', data)
|
||||
|
||||
server = User.objects.get(id=settings.SERVER_USER_ID)
|
||||
m = Message(
|
||||
quest=quest,
|
||||
user=server,
|
||||
message=f"{quest.owner.username} made a new poll!",
|
||||
)
|
||||
m.save()
|
||||
data = {}
|
||||
data['message_id'] = m.id
|
||||
data['message'] = m.message
|
||||
data['date'] = int(time.time())
|
||||
data['name'] = server.username
|
||||
data['anonymize'] = False
|
||||
socket.send('message', data)
|
||||
|
||||
|
||||
def edit_post(socket, data):
|
||||
"""
|
||||
|
@ -454,6 +501,21 @@ def new_page(socket, data):
|
|||
data['url'] = reverse('quest:quest', args=[socket.quest_id, p.page_num])
|
||||
socket.send('new_page', data)
|
||||
|
||||
server = User.objects.get(id=settings.SERVER_USER_ID)
|
||||
m = Message(
|
||||
quest=quest,
|
||||
user=server,
|
||||
message=f"{quest.owner.username} started a new page!",
|
||||
)
|
||||
m.save()
|
||||
data = {}
|
||||
data['message_id'] = m.id
|
||||
data['message'] = m.message
|
||||
data['date'] = int(time.time())
|
||||
data['name'] = server.username
|
||||
data['anonymize'] = False
|
||||
socket.send('message', data)
|
||||
|
||||
|
||||
events = {}
|
||||
for obj in dir():
|
||||
|
|
|
@ -5,10 +5,11 @@
|
|||
{% for message in chat_messages %}
|
||||
<div id="msg-{{ message.id }}" class="message">
|
||||
<div class="messageHeader">
|
||||
<span class="messageName">{% if quest.owner.username == message.user.username or not quest.anonymize %}{{ message.user.username or quest.anon_name }}{% else %}{{ quest.anon_name }}{% endif %}</span>
|
||||
<span class="messageName">{% if quest.owner == message.user or message.user.id == server_user_id or not quest.anonymize %}{{ message.user.username or quest.anon_name }}{% else %}{{ quest.anon_name }}{% endif %}</span>
|
||||
<span class="messageDate">{{ localtime(message.timestamp).strftime('%Y-%m-%d %H:%M:%S') }}</span>
|
||||
<span class="messageID">No.<a href="javascript:quote('{{ message.id }}')">{{ message.id }}</a></span>
|
||||
</div>
|
||||
<hr class="msgHeaderHr">
|
||||
<div class="messageContent">{{ message.message }}</div>
|
||||
</div>
|
||||
<hr>
|
||||
|
|
|
@ -142,8 +142,17 @@ h3 {
|
|||
width: 100%;
|
||||
}
|
||||
|
||||
.msgHeaderHr {
|
||||
margin-top: 0.2em;
|
||||
margin-bottom: 0.2em;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
border: 0;
|
||||
border-bottom: 1px solid #ccc;
|
||||
}
|
||||
|
||||
.msgSrvHr {
|
||||
width: 95%;
|
||||
width: 50%;
|
||||
margin-top: 0.2em;
|
||||
margin-bottom: 0.2em;
|
||||
margin-left: auto;
|
||||
|
|
|
@ -52,7 +52,7 @@ socket.events['message'] = function(data) {
|
|||
let msg_str = '<div id="message-' + data.message_id + '" class="message">';
|
||||
msg_str = '<div class="messageHeader"><span class="messageName">' + ((data.name && !data.anonymize) ? data.name : anon_name) + '</span> ';
|
||||
msg_str += '<span class="messageDate">' + strftime(data.date) + '</span> ';
|
||||
msg_str += '<span class="messageID">No.<a href="javascript:quote(' + data.message_id + ')">' + data.message_id + '</a></span></div>';
|
||||
msg_str += '<span class="messageID">No.<a href="javascript:quote(' + data.message_id + ')">' + data.message_id + '</a></span><hr class="msgHeaderHr"></div>';
|
||||
msg_str += '<div class="messageContent">' + data.message + '</div></div><hr>';
|
||||
|
||||
let mbox = document.getElementById('chatWindow');
|
||||
|
|
|
@ -9,6 +9,7 @@ from django.views.decorators.http import require_POST
|
|||
from django.contrib import messages
|
||||
from django.shortcuts import render, redirect
|
||||
from django.db.models import F
|
||||
from django.conf import settings
|
||||
|
||||
from .models import Quest, DiceRoll, PollOption, PollVote, Page, Post
|
||||
from .forms import EditQuestForm, QuestForm, PostForm
|
||||
|
@ -70,6 +71,7 @@ def quest(request, quest_id, page_num='0'):
|
|||
poll_options = PollOption.objects.filter(poll__post__quest=quest)
|
||||
poll_votes = PollVote.objects.filter(option__poll__post__quest=quest)
|
||||
ip_address = request.META['REMOTE_ADDR']
|
||||
server_user_id = settings.SERVER_USER_ID
|
||||
context = locals()
|
||||
if page_num == '0':
|
||||
return render(request, 'quest/quest_homepage.html', context)
|
||||
|
|
|
@ -163,3 +163,6 @@ IMG_SVR_URL = "https://img.steelbea.me/"
|
|||
|
||||
# Taggit
|
||||
TAGGIT_CASE_INSENSITIVE = True
|
||||
|
||||
# Server user id
|
||||
SERVER_USER_ID = 3
|
||||
|
|
Loading…
Reference in New Issue
Block a user