Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #33: message formating #47

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion chat/consumers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Set

import bleach
from channels.generic.websocket import AsyncJsonWebsocketConsumer
from django.conf import settings

Expand Down Expand Up @@ -182,6 +183,6 @@ async def chat_message(self, event: dict):
"msg_type": settings.MSG_TYPE_MESSAGE,
"room": event["room_id"],
"username": event["username"],
"message": event["message"],
"message": bleach.linkify(event["message"]),
},
)
11 changes: 11 additions & 0 deletions chat/tests/test_chat_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ async def test_chat_consumer() -> None:
'username': user.username,
'message': message}

# Testing message formatting
# First making urls into links
message: str = 'My website is gonevis.com'
expected_message: str = 'My website is <a href="http://gonevis.com" rel="nofollow">gonevis.com</a>'
await communicator.send_json_to({"command": "send", "room": room.id, 'message': message})
response = await communicator.receive_json_from()
assert response == {'msg_type': settings.MSG_TYPE_MESSAGE,
'room': room.id,
'username': user.username,
'message': expected_message}

# Getting list of users in the room
await communicator.send_json_to({'command': 'room_users', 'room': room.id})
response = await communicator.receive_json_from()
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ whitenoise==3.3.1
Twisted[tls,http2]==18.4.0
psycopg2-binary==2.7.4
Fabric3==1.14.post1
bleach==2.1.3