I have a Ruby on Rails application for which I am implementing ActionCable. (For full disclosure, I'm an advanced beginner at RoR and a complete noob with ActionCable. I'm using this app to learn about it.) I'm trying to figure out if I can do something like the following:
Imagine your standard chat room (like in all the ActionCable tutorials), with the twist being that:
- users can edit their messages after they are sent, and
- some of the people in the room have special permissions (you can think of them as admin users). These admin users have the ability to edit messages sent by other people after they have been sent.
When rendering the page, I have a partial for each message that looks something like this:
# View:
<%= render :partial=>"message_line", :collection=>@messages, :locals=>{:current_user=>@user}%>
# _message_line.html.erb partial
<div><%= message_line %></div>
<div>
<% if current_user.admin or current_user.id==message_line.user.id %>
<%= Link to edit post... %>
<% end %>
</div>
I have successfully set up the ActionCable such that when a user enters a message that message gets broadcast and displayed on the screens of all users in that room. But I can't figure out how tell, when receiving a message, if the user receiving it is an admin user and therefore should be shown the "link to edit post" link. The user that's invoking the controller action to push the message to everyone else is not the user receiving the message, and so therefore the controller doesn't know if the receiving user is an admin (especially given that there are multiple recipients).
As a concrete example, consider the following setup:
There are three users, UserA, UserB, UserC in the chat room. UserA is an admin, UserB and UserC are not.
Here's what should happen:
- UserA enters a new message. It is broadcast to all 3 users and all 3 see it displayed on their screen. UserA sees the link to edit the message, UserB and UserC do not.
- UserB enters a new message. It is broadcast to all 3 users and all 3 see it displayed on their screen. UserB and UserA sees the link to edit the message, UserC does not.
Thanks in advance for any help!