Skip to content

Commit c67aaa6

Browse files
committed
Completed part 7
1 parent 8c578e9 commit c67aaa6

File tree

9 files changed

+141
-69
lines changed

9 files changed

+141
-69
lines changed

chat/channels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
class BroadCastWebSocketChannel(BaseNotificationChannel):
11-
"""Fanout notification for RabbitMQ."""
11+
"""Fanout notification channel with RabbitMQ."""
1212

1313
def _connect(self):
1414
"""Connect to the RabbitMQ server."""

chat/views.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
from django.http import Http404
44
from django.contrib.auth import get_user_model
55

6-
from .models import (
7-
ChatSession, ChatSessionMember, ChatSessionMessage, deserialize_user
8-
)
9-
106
from rest_framework import permissions
117
from rest_framework.views import APIView
128
from rest_framework.response import Response
13-
from notifications.signals import notify
9+
10+
from notifications.utils import notify
11+
from notifications import default_settings as notifs_settings
12+
13+
from .models import ChatSession, ChatSessionMessage, deserialize_user
1414

1515

1616
class ChatSessionView(APIView):
@@ -47,17 +47,17 @@ def patch(self, request, *args, **kwargs):
4747

4848
owner = deserialize_user(owner)
4949
members = [
50-
deserialize_user(chat_session.user)
50+
deserialize_user(chat_session.user)
5151
for chat_session in chat_session.members.all()
5252
]
5353
members.insert(0, owner) # Make the owner the first member
5454

55-
return Response ({
55+
return Response({
5656
'status': 'SUCCESS', 'members': members,
57-
'message': '%s joined that chat' % user.username,
57+
'message': '%s joined the chat' % user.username,
5858
'user': deserialize_user(user)
5959
})
60-
60+
6161

6262
class ChatSessionMessageView(APIView):
6363
"""Create/Get Chat session messages."""
@@ -69,8 +69,8 @@ def get(self, request, *args, **kwargs):
6969
uri = kwargs['uri']
7070

7171
chat_session = ChatSession.objects.get(uri=uri)
72-
messages = [chat_session_message.to_json()
73-
for chat_session_message in chat_session.messages.all()]
72+
messages = [chat_session_message.to_json()
73+
for chat_session_message in chat_session.messages.all()]
7474

7575
return Response({
7676
'id': chat_session.id, 'uri': chat_session.uri,
@@ -96,20 +96,19 @@ def post(self, request, *args, **kwargs):
9696
'obj': chat_session_message.id,
9797
'short_description': 'You a new message', 'silent': True,
9898
'extra_data': {
99-
'uri': chat_session.uri,
99+
notifs_settings.NOTIFICATIONS_WEBSOCKET_URL_PARAM:
100+
chat_session.uri,
100101
'message': chat_session_message.to_json()
101102
}
102103
}
103-
notify.send(
104-
sender=self.__class__,**notif_args, channels=['websocket']
105-
)
104+
notify(**notif_args, channels=['websocket'])
106105

107-
return Response ({
106+
return Response({
108107
'status': 'SUCCESS', 'uri': chat_session.uri, 'message': message,
109108
'user': deserialize_user(user)
110109
})
111110

112111

113112
def raise_404(request):
114113
"""Raise a 404 Error."""
115-
raise Http404
114+
raise Http404

0 commit comments

Comments
 (0)