I would like to make a chat application using django and channels. I have
two models to achieve a chat like application.

   1.

   Thread - A thread can have list of users. So, it can be used for chat
   between two users, or groups of user. If it's a group thread, it can have a
   subject for the group (eg. group name).
   2.

   Message - A message is the actual message sent from one user (sender) to
   a thread. And any users of thread's user list will have access to it.

class Thread(models.Model):
    subject = models.CharField(max_length=255, blank=True)
    user = models.ManyToManyField(User)
class Message(models.Model):
    thread = models.ForeignKey(Thread)
    sender = models.ForeignKey(User)
    sent_datetime = models.DateTimeField(default=timezone.now)
    body = models.TextField()

So, the chat app will have the basic features:

   1.

   Chat with a single user

   When a user sends a message to a user, django will check if a thread
   with both sender and recipient exists as the users. If it exist, then
   create a new message with that existing thread as the foreign key. If it
   doesn't exits, create a new thread, and create a new message with newly
   created thread as its foreign key to the thread.
   2.

   Chat with a group of users

   When a user creates a new group, a new thread will be created and that
   user will be added to the thread's user list. More users can be added to
   group later on. And any message sent will be available to all the users in
   the thread's user list.

After reading the docs I am not sure how to actually layout the
architecture for the websocket and routing of the channels. I have the
following confusions:

   1.

   From the docs on models
   <https://channels.readthedocs.io/en/stable/getting-started.html#models>,
   I will have to specify the room name in the url path, and on connect, the
   consumer will add the client (message.reply_channel) to that group of room
   (here thread), and then any messages sent will be broadcasted to all the
   users in the group. However, that is just for one room (thread). How can
   the user again chat with other threads (rooms). Will I have to make a new
   Websocket connection for each thread (room)?..
   2.

   This question is out of context of a chat app, but I need to know this
   to better understand how to make the architecture. In the docs, there's
   a section of live blogs
   <https://channels.readthedocs.io/en/stable/concepts.html#groups> where
   all the clients (message.reply_channel) are added to the "liveblog" group.
   However, in this scenario, we already know that we need to connect to
   "liveblog" groups. Suppose, there's a website where many authors write
   their blogs, and a user is subscribed to many authors (e.g.: "Adam",
   "Mary", "Robin", ...). And, if a author starts its blog, a connected user
   will get notified.

   So here, if the user connects to the websocket connection, on consumer,
   should we add the user to all blogs listed in his/her subscription list

e.g:

for sub in subscriptions:
    Group(sub).add(message.reply_channel)

Or is there some better way to handle these kinds of architecture? I really
like channels, and if anyone can help me understand and guide through these
concepts I will really appreciate the help.


Sincerely,

Robin

-- 
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+unsubscr...@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/CA%2B4-nGrMeAZGzmJAL95BsJAG5q%3D-NWw0_Yb-KNnyFNnV%2BCCz3w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to