From 73b10ddaf107bba9b85b23c77b45f7fd850bec74 Mon Sep 17 00:00:00 2001
From: Sergiy <sergiy.sergienko@blinkreaction.com>
Date: Mon, 23 Apr 2012 17:51:29 +0300
Subject: [PATCH] Integrates with comment_goodness module

---
 .../all/modules/ajax_comments/ajax_comments.module |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/docroot/sites/all/modules/ajax_comments/ajax_comments.module b/docroot/sites/all/modules/ajax_comments/ajax_comments.module
index e71d75e..cd83835 100644
--- a/docroot/sites/all/modules/ajax_comments/ajax_comments.module
+++ b/docroot/sites/all/modules/ajax_comments/ajax_comments.module
@@ -234,7 +234,18 @@ function ajax_comments_submit_js($form, &$form_state) {
   else {
     // Append comment to root comment wrapper.
     $comment_output = drupal_render($comment_build);
-    $commands[] = ajax_command_append('#comment-wrapper', $notify_text . $comment_output);
+    
+    if (module_exists('comment_goodness') && isset($form['#node']) && variable_get('comment_default_sorting_' . $form['#node']->type, FALSE)) {
+      $curr_sorting = variable_get('comment_default_sorting_' . $form['#node']->type, comment_goodness_OLDER_FIRST);
+      switch ($curr_sorting) {
+        case comment_goodness_OLDER_FIRST:
+            $commands[] = ajax_command_append('#comment-wrapper', $notify_text . $comment_output);
+          break;
+        case comment_goodness_NEWER_FIRST:
+            $commands[] = ajax_command_prepend('#comment-wrapper', $notify_text . $comment_output);
+          break;
+      }
+    }    
 
     // If we have a default form, update it with a new one.
     if (variable_get('comment_form_location_' . $node->type, COMMENT_FORM_BELOW) == COMMENT_FORM_BELOW) {
-- 
1.7.9

