DEV Community

Leonard Percival
Leonard Percival

Posted on

How to approach user specific rendering with turbo streams

So I have an issue, I want to render current_user specific partials to my turbo stream. In my use case I have an instant messaging app, and when a user writes a new message I would like to broadcast that message to all the users within that chat. My issue is that message partial has user specific buttons with user specific permissions in it, aka edit and delete, which should only be accessible to the message creator and admin users. The issue I run into is that when broadcasting a partial to a stream I don't know how to attribute the current_user variable (using devise) within that partial to the user being broadcast to. At the moment I have a hacked solution using a stimulus connect() callback, but it is my no means ideal. Can anyone help me out? I am sure there must be a more sophisticated and simpler way of doing this that doesn't involve every user receiving the message to trigger there own request.

Any help would be greatly appreciated,

Thanks, Lenny

Top comments (2)

Collapse
 
Collapse
 
superails profile image
Yaroslav Shmarov

@secretpray has it all figured out 💯