private_pub icon indicating copy to clipboard operation
private_pub copied to clipboard

Differentiate between sender and recipient

Open willc0de4food opened this issue 9 years ago • 1 comments

I just got private chat working with private pub, but am having trouble differentiating between the sender and recipient of a message. When the message is published to the recipient, the sender class is applied to the message (the same problem that this user is having: http://stackoverflow.com/questions/35989728/differentiate-users-with-private-pub )

Is there a solution to this problem that I missed?

Thanks

willc0de4food avatar Apr 19 '16 22:04 willc0de4food

Hey :)

Well, I found a clean solution to this problem: Somewhere in the wrapper, add an input including your current_user id

<input type="hidden" value="<%= current_user.id %>" name="sender-id" id="senderid">

Then, in your js publish, retrieve it, and voila :)

<% publish_to whatever_you_want  do %>
sender = $('#senderid').val();
  if (sender == "<%= current_user.id %>") {
// do your stuff
  }
<% end %>

Sashkan avatar Jul 20 '16 12:07 Sashkan