Wednesday, April 26, 2017

Re: Multiplex results from (Django-Channels)

Thanks Andrew. I took your advice. I cloned and looking into the example, and tried what you suggested. 

In my case, the chat is persistent.

I will not be doing it via URL, instead I'm doing a queryset to get all the rooms a user belongs to.

However, it still isn't working. Could you please advise?

@channel_session
def ws_connect(message):
    listrooms
= User.objects.filter(chat__isnull=False).values('chat')
    # `listrooms` gives the PK fields of the chat rooms
    chathistory = room.messages.all().order_by('timestamp')
   
Group('chat-' + listrooms).add(message.reply_channel)
    message.channel_session['listrooms'] = list(set(message.channel_session['listrooms']).union([room.id]))
    message
.reply_channel.send({'text': json.dumps([msg.as_dict() for msg in chathistory.all()])})




@channel_session
def ws_receive(message):
    listrooms
= User.objects.filter(chat__isnull=False).values('chat')
    data
= json.loads(message['text'])
    m
= listrooms.messages.create(handle=data['handle'], message=data['message'])
   
Group('chat-'+ listrooms).send({'text': json.dumps([m.as_dict()])})

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/529472b1-9323-45d8-951e-f5729472bb66%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment