Skip to content

Commit 067bfcf

Browse files
committed
send user_id and username back to frontend
1 parent 866fa80 commit 067bfcf

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

classroom/consumers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ async def receive(self, text_data):
6161
data = {
6262
"type": 'chat_message',
6363
"id": message.id,
64-
"user": message.user.username,
64+
"user_id": message.user.id,
65+
"username": message.user.username,
6566
"date": message.date.strftime("%Y-%m-%d"),
6667
"avatar": 'https://static.vecteezy.com/system/resources/previews/024/983/914/non_2x/simple-user-default-icon-free-png.png',
6768
"text": message.text,
@@ -75,7 +76,8 @@ async def receive(self, text_data):
7576
async def chat_message(self, event):
7677
response = {
7778
'type': 'websocket.send',
78-
'user': event['user'],
79+
'user_id': event['user_id'],
80+
'username': event['username'],
7981
'text': event['text']
8082
}
8183
await self.send(json.dumps(event))

classroom/serializers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Meta:
2727

2828
def to_representation(self, instance):
2929
ret = super().to_representation(instance)
30-
ret['user'] = instance.user.id
30+
ret['user_id'] = instance.user.id
31+
ret['username'] = instance.user.username
3132
ret['avatar'] = 'https://static.vecteezy.com/system/resources/previews/024/983/914/non_2x/simple-user-default-icon-free-png.png'
3233
return ret

0 commit comments

Comments
 (0)