Fix message unable to delete

This commit is contained in:
cuom1999 2020-05-22 20:59:19 -05:00
parent 47067d375e
commit 3b2d5dfce0
3 changed files with 34 additions and 6 deletions

View file

@ -4,7 +4,7 @@ from .models import Message
from .views import format_time
from django.urls import reverse
from django.http import HttpResponse, HttpResponseRedirect
from django.core import serializers
from judge.models.profile import Profile
@ -34,8 +34,10 @@ class ChatConsumer(AsyncWebsocketConsumer):
text_data_json = json.loads(text_data)
message = text_data_json['message']
time = save_data_and_get_time(message)
message['time'] = format_time(time)
message_saved = save_data_and_return(message)
message['time'] = message_saved[0]['fields']['time']
message['id'] = message_saved[0]['pk']
# Send message to room group
await self.channel_layer.group_send(
@ -56,10 +58,14 @@ class ChatConsumer(AsyncWebsocketConsumer):
# return time
def save_data_and_get_time(message):
def save_data_and_return(message):
new_message = Message(body=message['body'],
author=Profile.objects
.get(pk=message['author_id']),
)
new_message.save()
return new_message.time
json_data = serializers.serialize("json",
Message.objects
.filter(pk=new_message.id)
)
return json.loads(json_data)

File diff suppressed because one or more lines are too long

View file

@ -16,7 +16,6 @@
chatSocket.onmessage = function(e) {
let data = JSON.parse(e.data);
console.log(data);
data = data['message'];
loadMessage(data['body'],
data['author'],