fix silly bug

This commit is contained in:
cuom1999 2020-03-21 16:49:54 -06:00
parent 92d94af520
commit ba5128aa8d
2 changed files with 4 additions and 4 deletions

View file

@ -33,6 +33,8 @@ class ChatConsumer(AsyncWebsocketConsumer):
async def receive(self, text_data): async def receive(self, text_data):
text_data_json = json.loads(text_data) text_data_json = json.loads(text_data)
message = text_data_json['message'] message = text_data_json['message']
time = save_data_and_get_time(message)
message['time'] = format_time(time)
# Send message to room group # Send message to room group
await self.channel_layer.group_send( await self.channel_layer.group_send(
@ -46,8 +48,6 @@ class ChatConsumer(AsyncWebsocketConsumer):
# Receive message from room group # Receive message from room group
async def chat_message(self, event): async def chat_message(self, event):
message = event['message'] message = event['message']
time = save_data_and_get_time(message)
message['time'] = format_time(time)
# Send message to WebSocket # Send message to WebSocket
await self.send(text_data=json.dumps({ await self.send(text_data=json.dumps({
'message': message, 'message': message,
@ -58,8 +58,7 @@ class ChatConsumer(AsyncWebsocketConsumer):
def save_data_and_get_time(message): def save_data_and_get_time(message):
new_message = Message(body=message['body'], new_message = Message(body=message['body'],
author=Profile.objects author=Profile.objects
.get(id=message['author_id']), .get(pk=message['author_id']),
) )
new_message.save() new_message.save()
HttpResponseRedirect(reverse('chat'))
return new_message.time return new_message.time

View file

@ -115,6 +115,7 @@ body {
font-family: "Segoe UI", "Lucida Grande", Arial, sans-serif; font-family: "Segoe UI", "Lucida Grande", Arial, sans-serif;
color: #000; color: #000;
height: 100%; height: 100%;
overflow-x: hidden;
} }
.unselectable { .unselectable {