add icons and chatbox

This commit is contained in:
cuom1999 2020-03-18 23:13:55 -06:00
parent 9e95fd21a7
commit cb8eb2689c
43 changed files with 254 additions and 46 deletions

View file

@ -19,17 +19,11 @@ class Message(models.Model):
body = models.TextField(verbose_name=_('body of comment'), max_length=8192)
def notify_ws_clients(self):
# inform client that there is a new message
notification = {
'type': 'recieve_group_message',
'message': '{}'.format(self.id)
}
channel_layer = get_channel_layer()
# print("user.id {}".format(self.user.id))
# print("user.id {}".format(self.recipient.id))
async_to_sync(channel_layer.group_send)("{}".format(self.user.id), notification)
async_to_sync(channel_layer.group_send)("{}".format(self.recipient.id), notification)
def save(self, *args, **kwargs):
new_message = self.id

View file

@ -1,11 +1,31 @@
from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.utils.translation import gettext as _
from django.views.generic import ListView
from django.urls import reverse
from django.utils import timezone
from .models import Message
class ChatView(ListView):
model = Message
title = _('Chat Box')
context_object_name = 'messages'
template_name = 'chat/chat.html'
title = _('Chat Box')
def get_context_data(self, **kwargs):
context = super(ChatView, self).get_context_data(**kwargs)
context['title'] = self.title
return context
def get_queryset(self):
return None
def send(request):
new_message = Message(body=request.POST['message'],
author=request.profile,
time=timezone.now())
new_message.save()
return HttpResponseRedirect(reverse('chat'))