Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate appending of message .... #7

Open
aldrienht opened this issue Sep 30, 2015 · 4 comments
Open

Duplicate appending of message .... #7

aldrienht opened this issue Sep 30, 2015 · 4 comments

Comments

@aldrienht
Copy link

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
Copy link
Author

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
Copy link
Author

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

@aldrienht
Copy link
Author

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
Copy link

ryleto commented Feb 16, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants