Topics in Phoenix-Channels

So I got my first chatroom up and running. I just have one question I notice I can make a topic have sub topics on one channel i.e. room:* how would I go about making a new chat rooms for each new sub topic. I’m a bit confused, is this possible or can I only create one chatroom per channel ? Thanks for the help I am really excited about learning Elixir !

Also, I noticed my chat messages are visible in every subtopic, is there a way to ensure that messages only are visible in it’s own subtopic/chatroom.

If you use topic Room:SubTopic_ID for a subtopic, that’s just a new channel for just that one chatroom.

I usually use this to ensure that a message only gets sent to the appropriate channel topic.
broadcast!(socket, "topic:#{subtopic_id}:new_message", msg)

If you want to load older messages, you’ll need to do a bit of legwork. This would mean writing a query for loading older messages and running it in the :after_join channel event.

Also you’ll need to add them to the chat in the front end.

1 Like

Thanks a million, I will try this after I get back from work !!

2 Likes