Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. var channel = pusher.subscribe('your-chat-room');
  3.  
  4.  
  5. channel.bind('new-message', function (data) {
  6.     // append message to chat UI. Here an item in unordered list.
  7.     var messageThread = document.getElementById("chat");
  8.     var newMessage = document.createElement("li");
  9.     newMessage.appendChild(document.createTextNode("data.message"));
  10.     newMessage.setAttribute("id",data.messageId)
  11.     messageThread.appendChild(newMessage)
  12. });
  13.  
  14.  
  15. channel.bind('new-reaction', function (data) {
  16.     // If you save the likeCount in your backend,
  17.     // you will trigger an event everytime a new like is sent by a user.
  18.     // Bind to an event on the same chatroom.
  19.     // In this example, we are storing that value on an attribute of the <li> object.
  20.     var message = document.querySelector("#"+data.messageId);
  21.     var likeCount = parseInt(message.getAttribute("likeCount"));
  22.     newMessage.setAttribute("likeCount",likeCount+1);
  23. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement