I’m in the process of investigating how to make AJAX Babble add-on compatible with Threaded Comments.
After reading the code of the function submit() in mod.threaded_comments.php it seems to me that it can be made much simple and robust.
As it is now the function submit() mostly duplicates the functionality of insert_new_comment() function of the mod.comment.php file of the Comment module. Only these lines of the submit() function contribute functionality specific to Threaded Comments:
if ($_POST['parent_id']!='' && $_POST['parent_id']!=0)
$parent_id = $this->EE->security->xss_clean($_POST['parent_id']);
$root_id = $parent_id;
$level = 0;
$q = $DB->query("SELECT parent_id FROM exp_comments WHERE comment_id='".$DB->escape_str($root_id)."'");
if ($q->row('parent_id')==0) break;
$root_id = $q->row('parent_id');
} while ($root_id!=0);
$parent_id = 0;
$root_id = 0;
$level = 0;
It’s not good to duplicate ExpressionEngine’s functionality in an add-on. This is prone to break things in case EllisLab decides to change something in insert_new comment() function. It is also complicatiing things for me because in case AJAX Babble is used together with Threaded Comments, then AJAX Babble should branch the code and use submit() function of Threadded Comments instead of insert_new comment() function of Comment module.
Here is my idea how Threadded Comments can simplify its handling of inserting comment. submit() function should be very simple:
if ( ! class_exists('Comment'))
$COMM = new Comment();
Then in the package of Threaded Comments there should be an extension which uses the hook insert_comment_insert_array. That function should execute the code which in the function submit() is specific to Threaded Comments module.
That’s it! After such changes TC code will be much shorter and robust.