Manually Unsubscribe User from Topic

I’m building an administrated Multi-User Chat with Phoenix Channels. Now I’m facing some problems I’d really appreciate help and insights with.

Each topic will have an admin user, and I’m building administrative rights for them to administrate the channel.

1. How to unsubscribe (=kick) a user from a topic manually from server-side?
The admin has to be able to kick and ban any user from their own topic. From what I can tell, the terminate callback is only invoked when the user leaves the channel (invokes channel.leave() or closes the browser tab at the client side). I need to be able to manually unsubscribe any user from any topic (but not disconnect from channels overall) server-side. So far I have not found a way to do this.

2. How to change socket.assigns outside of callbacks?
Currently, I’m storing each user’s topic specific privilege (VIP / ADMIN etc.) in the user’s socket.assigns. I need to be able to have an admin user change any subscribed user’s privilege, basically being able to promote them to VIP, revoke their ADMIN rights etc… So basically, I need to find a way to manually adjust any subscribed user’s socket.assigns server-side.

3. Any ideas on implementing some primitive form of spam prevention?
Phoenix Channels have no built-in spam prevention configurations. I need to build something simple, I’m thinking some form of tracking stored in socket.assigns and then always updated upon a message sent. Anyone faced a similar problem yet?

I don’t understand Phoenix’s Channels implementation well enough yet to tackle these issues on my own. I hope you could share some advice or ideas regarding these issues!

1 Like

Just send a message to that room channel to kick a specific user and handle that broadcast or so. :slight_smile:

Nope, gotta have some kind of callback, even if it is just receiving and handling a message sent from another process. :slight_smile:

A simple throttle is easy to make, plus libraries prebuilt as well if you don’t mind them going through a proxy process.

They are just a process like any other, they send and receive messages. :slight_smile:
If any specific questions, feel free to ask!

1 Like

Thank you for your input!

Yes, I’m finally starting to understand Phoenix’s Channels / PubSub implementation better. I’ve been very happy to get help here as well as on Elixir’s Slack channel whenever I’ve voiced out my problems.

I’m broadcasting events, intercepting them as needed and handling things at each user’s/socket’s callback.

Spam protection is something I’m still not quite sure about how to handle, it’ll be the next problem to tackle.

1 Like