Joseph-N / chatty

Chatty is a Gmail like instant chat application implemented in rails using private_pub gem
http://goo.gl/l3e8zN
93 stars 85 forks source link

Duplicate appending of message .... #7

Open aldrienht opened 9 years ago

aldrienht commented 9 years ago

I found some issue about duplication of message once you go to other page like user edit page then go back to index page, then try to make a chat message. First try, message will be doubled then try again [>> going to user edit page >> back to index page] message will be tripled and so on... double_append

aldrienht commented 9 years ago

I tried to make a simple javascript function for this. But I'm sure that it's not the best way to solve it. By console.log in this part _*publish_to @path do _* in create.js.erb I found out that it calls multiple times. Please help to fix this issue!

I tried by updating:

messages/_message.html.erb I added a unique id using message info(created_at & id).

messages/create.js.erb Finally ADD an IF statement that checks the last message via old and new ID: if( last_li_id != new_li_id ){ remaining of the code}

message_html_erb create_js_erb

aldrienht commented 9 years ago

Using the javascript code above cause delay in updating realtime message. Please help about this issue. Thank you very much.

aldrienht commented 9 years ago

After adding message ID to li tag in message.html.erb if( $("li#messageID<%= @message.id %>").length == 0 ){ chatbox.append("<%= j render( partial: @message ) %>"); chatbox.scrollTop(chatbox[0].scrollHeight); }

Just to prevent duplication of message.

ryleto commented 8 years ago

This is an issue with the private_pub gem allowing multiple channel subscriptions. The issue has been addressed by other users but has not yet been accepted and merged into the master.

Until it has been merged, you can substitute a forked version of the gem like the one I've created here and it should resolve the issue.