Index: openacs-4/packages/forums/sql/postgresql/forums-messages-package-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/forums/sql/postgresql/forums-messages-package-create.sql,v
diff -u -r1.17 -r1.18
--- openacs-4/packages/forums/sql/postgresql/forums-messages-package-create.sql	25 Jan 2005 13:01:14 -0000	1.17
+++ openacs-4/packages/forums/sql/postgresql/forums-messages-package-create.sql	15 Mar 2005 20:06:45 -0000	1.18
@@ -62,7 +62,7 @@
         into v_forum_policy
         from forums_forums
         where forum_id = p_forum_id;
-             
+
         if v_forum_policy = ''moderated''
         then v_state := ''pending'';
         else v_state := ''approved'';
@@ -72,10 +72,10 @@
     end if;
 
     insert into forums_messages
-    (message_id, forum_id, subject, content, format, user_id, parent_id, state, last_child_post)
+    (message_id, forum_id, subject, content, format, user_id, parent_id, state, last_child_post, last_poster)
     values
     (v_message_id, p_forum_id, p_subject, p_content, p_format, p_user_id, p_parent_id,
-     v_state, current_timestamp);
+     v_state, current_timestamp, p_user_id);
 
     update forums_forums
     set last_post = current_timestamp
@@ -97,16 +97,17 @@
         update forums_messages
         set approved_reply_count = approved_reply_count + 1,
           reply_count = reply_count + 1,
+          last_poster = p_user_id,
           last_child_post = current_timestamp
         where message_id = forums_message__root_message_id(v_message_id);
       else
+        -- dont update last_poster, last_child_post when not approved
         update forums_messages
-        set reply_count = reply_count + 1,
-          last_child_post = current_timestamp
+        set reply_count = reply_count + 1
         where message_id = forums_message__root_message_id(v_message_id);
       end if;
     end if;
- 
+
     return v_message_id;
 
 end;' language 'plpgsql';
@@ -216,7 +217,9 @@
   else
     if p_state = ''approved'' and v_cur.state <> ''approved'' then
       update forums_messages
-      set approved_reply_count = approved_reply_count + 1
+      set approved_reply_count = approved_reply_count + 1, 
+        last_poster = (case when v_cur.posting_date > last_child_post then v_cur.user_id else last_poster end),
+        last_child_post = (case when v_cur.posting_date > last_child_post then v_cur.posting_date else last_child_post end)
       where message_id = forums_message__root_message_id(v_cur.message_id);
     elsif p_state <> ''approved'' and v_cur.state = ''approved'' then
       update forums_messages
@@ -271,8 +274,7 @@
   end if;
 
   perform acs_object__delete(p_message_id);
-  return 0;    
-
+  return 0;
 end;' language 'plpgsql';
 
 select define_function_args ('forums_message__delete_thread', 'message_id');
@@ -289,7 +291,7 @@
     into v_forum_id, v_sortkey
     from forums_messages
     where message_id = p_message_id;
-           
+
     -- if it is already deleted
     if v_forum_id is null
     then return 0;
