Index: bp-blogs/bp-blogs-functions.php
===================================================================
--- bp-blogs/bp-blogs-functions.php	(revision 6145)
+++ bp-blogs/bp-blogs-functions.php	(working copy)
@@ -201,6 +201,9 @@
 			}
 
 			$activity_content = $post->post_content;
+			
+			// if the post was in trash then we take the post_date_gmt to make sure the comments will not be older than the post ;)
+			$post_date = isset( $bp->blogs->post_restored ) ? $post->post_date_gmt : $post->post_modified_gmt ;
 
 			bp_blogs_record_activity( array(
 				'user_id'           => (int) $post->post_author,
@@ -210,12 +213,15 @@
 				'type'              => 'new_blog_post',
 				'item_id'           => $blog_id,
 				'secondary_item_id' => $post_id,
-				'recorded_time'     => $post->post_modified_gmt
+				'recorded_time'     => $post_date
 			));
 		}
 
-		// Update the blogs last activity
-		bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
+		// Update the blogs last activity only if the post wasnt in trash
+		if( !$bp->blogs->post_restored )
+			bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
+			
+		$bp->blogs->post_restored = false;
 	} else {
 		bp_blogs_remove_post( $post_id, $blog_id, $user_id );
 	}
@@ -423,6 +429,74 @@
 }
 add_action( 'delete_post', 'bp_blogs_remove_post' );
 
+/***** beginning of enhancement *****/
+
+/**
+* If the admin move the post to trash, then the activity is deleted
+* but if this post had been commented, then the new_blog_comment activities are still there
+* If someone clicks on the action link of one of these activities, then we get a 404
+* by hooking trashed_post_comments with this function we avoid this. 
+*/
+function bp_blogs_handle_trashed_post_comments( $post_id ) {
+	global $wpdb;
+	
+	$comments = $wpdb->get_results( $wpdb->prepare("SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id) );
+	if ( empty($comments) )
+		return;
+	
+	foreach ( $comments as $comment ) {
+		
+		bp_blogs_delete_activity( array( 'item_id' => $wpdb->blogid, 'secondary_item_id' => $comment->comment_ID, 'type' => 'new_blog_comment' ) );
+
+		do_action( 'bp_blogs_handle_trashed_post_comment', $wpdb->blogid, $post_id, $comment->comment_ID );
+		
+	}
+		
+	do_action( 'bp_blogs_handle_trashed_post_comments', $wpdb->blogid, $post_id, $comments );
+	
+}
+add_action( 'trashed_post_comments', 'bp_blogs_handle_trashed_post_comments', 10, 1 );
+
+/**
+* Now if the admin changes his mind, and move back the post from trash to published
+* then we can record the comment activities we deleted earlier 
+*/
+function bp_blogs_handle_untrashed_post_comments( $post_id ) {
+	global $wpdb;
+	
+	$comments = $wpdb->get_results( $wpdb->prepare("SELECT comment_ID, comment_approved FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id) );
+	if ( empty($comments) )
+		return;
+	
+	foreach ( $comments as $comment ) {
+		
+		if( $comment->comment_approved == 1 )
+			bp_blogs_record_comment( $comment->comment_ID, true );
+
+		do_action( 'bp_blogs_handle_untrashed_post_comment', $wpdb->blogid, $post_id, $comment->comment_ID );
+		
+	}
+		
+	do_action( 'bp_blogs_handle_untrashed_post_comments', $wpdb->blogid, $post_id, $comments );
+	
+}
+
+add_action('untrashed_post_comments', 'bp_blogs_handle_untrashed_post_comments', 10, 1 );
+
+/**
+* now if the post is restored, the activity is taking the 
+*/
+function bp_blogs_post_restored( $post_id ) {
+	global $bp;
+	
+	if( 'publish' == get_post_meta($post_id, '_wp_trash_meta_status', true) )
+		$bp->blogs->post_restored = true;
+}
+
+add_action('untrash_post', 'bp_blogs_post_restored', 10, 1);
+
+/***** end of enhancement *****/
+
 function bp_blogs_remove_comment( $comment_id ) {
 	global $wpdb;
 
