When the user clicks 'save' and then while is the comment is being saved, clicks reply to another comment, the previous comment gets saved as a reply to this one.

To reproduce:
1. Write a comment
2. Click save
3. While the comment is not yet saved, click reply to another comment.
4. You will see the comment being popped into the incorrect thread.

I looked into the JS code and found out that the click to reply handler does the job of assigning the comment number. This function does not check whether a comment save is still in progress.

Since I am a newbie in AJAX and know almost nothing about this module, I was not sure what to put in there to fix. This problem definitely needs to be fixed. It affects slower sites really badly.

Comments

udvranto’s picture

The following function in ajax_comments.js should return before setting the pid if the comment is still being saved

/**
 * Helper function for reply handler.
 *
 * In addition to clearing the textareas and forms, this is where the PID value
 * is set for the comment. The PID controls whether this is a new standalone
 * 'anchor' comment or a reply to an existing comment thread. A PID value
 * of 0 is a new anchor comment while any other number is a reply.
 *
 * @param $pid
 * Some comments are replies to other comments. In those cases, $pid is the parent comment's cid.
 * @param $rows
 *
 */
function ajax_comments_rewind(pid, rows){
// Return if the comment is being saved.
udvranto’s picture

What does this code fragment do? There is no variable named 'submitted'! Or is there?

     // Add sending on Ctrl+Enter.
    if ((e.ctrlKey) && ((e.keyCode == 0xA) || (e.keyCode == 0xD)) && !submitted) {
      submitted = true;
      $('#ajax-comments-submit').click()
    }
udvranto’s picture

I tried. It does not work. Takes me to a new page.

if(submitted) return;
udvranto’s picture

Any update on this?

udvranto’s picture

Shouldn't we remove the reply handlers as well?

/**
 * Comment submit routine.
 */
function ajax_comments_submit($form, &$form_state) {
  //remove self
  unset($form_state['submit_handlers']);
  // ..and standart comments submit handler
  foreach ($form['#submit'] as $key => $value) {
    if ($value == 'comment_form_submit') {
      unset($form['#submit'][$key]);
    }
  }
  //execute all others
  form_execute_handlers('submit', $form, $form_state);

udvranto’s picture

How do I know if the comment is being saved now?

/**
 * Reply links handler.
 *
 * This function is called as the handler to the .click() event. The events were bound
 * during the init functions above. This is the function executed when the user clicks
 * on a 'reply' button on the page or the 'Post new comment' link.
 */
Drupal.ajax_comments_reply_click = function() {
  // We should only handle non pressed links.
  if (!$(this).is('.pressed')){
    action = $(this).attr('href');
    form_action = $('#comment-form').attr('action');
    link_cid = ajax_comments_get_cid_from_href(action);
    rows = Drupal.settings.ajax_comments_rows_default;
    if ($('#comment-form-content').attr('cid') != link_cid) {

qzmenko’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

Issue is closed because 6.x version is unsupported. Feel free to open new issue for 7.x or 8.x versions of module.