Answer the question
In order to leave comments, you need to log in
Private chat on django chanels how to do it right?
Good day to all. Fell into a stupor. I'm making a real-time chat on django for my project using channels. I was able to make (according to the guide) only one chat room where all users can chat. But I need to implement private messages.
The main suspicions fall on the change in this part of the consumer
def connect(self):
self.room_name = self.scope['url_route']['kwargs']['room_name']
self.room_group_name = 'chat_%s' % self.room_name
async_to_sync(self.channel_layer.group_add)(
self.room_group_name,
self.channel_name
)
self.accept()
Answer the question
In order to leave comments, you need to log in
private messages are made with a room in the name of which there is a user id. That's all there is to it. When entering the chat, enter the common room (if necessary) + personal
self.room_name = f'{self.room_name}_{self.scope["user"].id}'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question