Skip to content

Commit

Permalink
Add id field to websocket response when chat message is created. (#12)
Browse files Browse the repository at this point in the history
* Add test to check if id field comes through websocket when chat message is created.

* Add id field to chat-message response.

* Version number bump.
  • Loading branch information
gibsonbailey authored Aug 30, 2022
1 parent c65cb74 commit 2a42b88
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions chit_chat/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ async def receive(self, text_data=None, bytes_data=None):
'room': message.room.pk,
'text': message.text,
'time': message.created_when.isoformat(),
'id': message.id,
}
)

Expand Down Expand Up @@ -105,6 +106,7 @@ async def chat(self, event):
'text': event.get('text'),
'room': event.get('room'),
'time': event.get('time'),
'id': event.get('id'),
})
)

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ name = django-chit-chat
author = Bailey Trefts
author_email = [email protected]
description = chat for projects we help maintain @ ckc
version = 0.0.8
version = 0.0.9
url = https://github.com/ckc-org/django-chit-chat
keywords =
django
Expand Down
9 changes: 8 additions & 1 deletion tests/integration/test_chat_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ async def test_user_is_able_to_connect_and_send_message_after_disconnecting():

assert resp['text'] == messages[0].text
assert resp['time']
assert resp['id'] == messages[0].id

await communicator.disconnect()

Expand Down Expand Up @@ -149,7 +150,13 @@ async def test_serializer_hook():

resp = await communicator.receive_json_from()
resp.pop('time')
assert resp == {'room': room.pk, 'text': 'hello', 'type': 'chat', 'user': user.pk}
assert resp == {
'room': room.pk,
'text': 'hello',
'type': 'chat',
'user': user.pk,
'id': (await get_messages_from_room(room))[-1].id
}

ckc_chat_settings = {
'MESSAGE': ChatTestSerializer,
Expand Down

0 comments on commit 2a42b88

Please sign in to comment.