Overview
The Blog Marketing Platform features a comprehensive commenting system with moderation tools, nested replies (threaded discussions), and built-in spam protection. The system supports multiple comment states and provides detailed moderation history.
Pending New comments awaiting moderator approval before becoming visible
Approved Verified comments visible to all users on the platform
Rejected Comments that violate guidelines or are inappropriate
Spam Detected or reported spam comments automatically filtered
Comments support rich metadata and hierarchical organization:
interface Comment {
id : number ;
postId : string | number ;
postTitle ?: string ;
authorId : number ;
author : {
id : number ;
name : string ;
email : string ;
avatar : string | null ;
username ?: string ;
};
content : string ;
status : 'pending' | 'approved' | 'rejected' | 'spam' ;
parentId ?: number | null ; // For nested replies
likes : number ;
createdAt : string ;
updatedAt : string ;
moderatedBy ?: number | null ; // Moderator user ID
moderatedAt ?: string | null ;
moderationNotes ?: string | null ;
isEdited ?: boolean ;
editedAt ?: string | null ;
depth ?: number ; // Nesting level (0-based)
path ?: number []; // Comment hierarchy path
replies ?: Comment []; // Nested replies
}
import { createComment } from '@/services/commentsService' ;
const newComment = await createComment ({
postId: 42 ,
authorId: userId ,
content: 'Great article! Very informative.' ,
status: 'pending' // New comments start as pending
});
All comments initially have pending status and require moderator approval before becoming visible to other users, except for trusted users or if auto-approval is enabled.
Nested Reply
Create a reply to an existing comment:
const reply = await createComment ({
postId: 42 ,
authorId: userId ,
content: 'Thanks! Glad you found it helpful.' ,
parentId: 123 , // ID of parent comment
status: 'pending'
});
Get all comments with user data:
import { getAllComments } from '@/services/commentsService' ;
const comments = await getAllComments ();
Retrieve comments for a specific post with pagination:
import { getCommentsByPostId } from '@/services/commentsService' ;
const { comments , total , page , pages } = await getCommentsByPostId ( 42 , {
withUser: true , // Include author data
withReplies: true , // Include nested replies
page: 1 ,
limit: 20
});
console . log ( `Showing ${ comments . length } of ${ total } comments` );
Get comments awaiting moderation:
import { getPendingComments } from '@/services/commentsService' ;
const pending = getPendingComments ();
console . log ( ` ${ pending . length } comments need review` );
Fetch all replies to a specific comment:
import { getCommentReplies } from '@/services/commentsService' ;
const replies = await getCommentReplies ( commentId );
import { updateCommentStatus } from '@/services/commentsService' ;
const approved = await updateCommentStatus (
commentId ,
'approved' ,
'Comment meets community guidelines'
);
const rejected = await updateCommentStatus (
commentId ,
'rejected' ,
'Contains inappropriate language'
);
Mark as Spam
const spam = await updateCommentStatus (
commentId ,
'spam' ,
'Detected as spam by moderator'
);
Only users with the editar_post_cualquiera permission (Editors and Administrators) can moderate comments. The moderator ID is automatically recorded with each action.
Moderation History
Each moderation action is tracked:
interface Comment {
// ... other fields
moderatedBy ?: number ; // User ID of moderator
moderatedAt ?: string ; // Timestamp of moderation
moderationNotes ?: string ; // Moderator's notes
}
// Example moderated comment
const comment = {
id: 123 ,
content: 'Original comment text' ,
status: 'approved' ,
moderatedBy: 5 ,
moderatedAt: '2024-01-15T10:30:00Z' ,
moderationNotes: 'Approved after review'
};
Nested Replies
The system supports multi-level threaded discussions:
// Comment structure with nested replies
const commentThread = {
id: 1 ,
content: 'Top-level comment' ,
depth: 0 ,
path: [ 1 ],
replies: [
{
id: 2 ,
content: 'First reply' ,
parentId: 1 ,
depth: 1 ,
path: [ 1 , 2 ],
replies: [
{
id: 3 ,
content: 'Nested reply' ,
parentId: 2 ,
depth: 2 ,
path: [ 1 , 2 , 3 ],
replies: []
}
]
},
{
id: 4 ,
content: 'Second reply' ,
parentId: 1 ,
depth: 1 ,
path: [ 1 , 4 ],
replies: []
}
]
};
The depth field indicates nesting level (0 for top-level), and path provides the full hierarchy chain for traversal and sorting.
Engagement Features
Users can like comments:
import { likeComment } from '@/services/commentsService' ;
const success = await likeComment ( commentId );
if ( success ) {
console . log ( 'Comment liked!' );
}
Users can report inappropriate comments:
import { reportComment } from '@/services/commentsService' ;
const reported = await reportComment ( commentId , {
reason: 'spam' ,
description: 'This comment appears to be promotional spam'
});
Report Reasons
spam - Promotional or irrelevant content
offensive - Offensive or abusive language
misinformation - False or misleading information
harassment - Bullying or harassment
other - Other violations
General Stats
Get overview of comment activity:
import { getCommentsStats } from '@/services/commentsService' ;
const stats = await getCommentsStats ();
// Returns:
// {
// total: 1247,
// approved: 1180,
// pending: 45,
// spam: 22
// }
Find posts with most engagement:
import { getTopCommentedPosts } from '@/services/commentsService' ;
const topPosts = await getTopCommentedPosts ( 10 );
// Returns posts sorted by comment count
Identify your most engaged users:
import { getMostActiveCommenters } from '@/services/commentsService' ;
const activeUsers = await getMostActiveCommenters ( 10 );
// Returns users sorted by comment count
Remove comments permanently:
import { deleteComment } from '@/services/commentsService' ;
const deleted = await deleteComment ( commentId );
if ( deleted ) {
console . log ( 'Comment removed' );
}
Deleting a parent comment will also delete all nested replies. This action cannot be undone.
Users can edit their own comments:
interface Comment {
isEdited ?: boolean ; // True if comment was modified
editedAt ?: string ; // Timestamp of last edit
}
// The edit history is tracked automatically
const editedComment = {
id: 123 ,
content: 'Updated comment text' ,
isEdited: true ,
editedAt: '2024-01-15T11:00:00Z'
};
Real-time Updates
The system supports real-time comment notifications:
// Subscribe to new comments on a post
function subscribeToPostComments ( postId : number ) {
// Poll for new comments
const interval = setInterval ( async () => {
const { comments } = await getCommentsByPostId ( postId , {
page: 1 ,
limit: 10
});
// Update UI with new comments
updateCommentsUI ( comments );
}, 5000 ); // Check every 5 seconds
return () => clearInterval ( interval );
}
Moderation Workflow
New Comment Submitted
User submits a comment, automatically set to pending status.
Moderator Review
Editor or Administrator reviews pending comments in the moderation queue.
Decision
Moderator approves, rejects, or marks as spam with optional notes.
User Notification
Author receives notification of moderation decision (if enabled).
Public Display
Approved comments become visible to all users on the post.
Spam Protection
The platform includes multiple spam prevention mechanisms:
Status filtering : Spam comments are hidden from public view
Report system : Users can flag suspicious comments
Moderation queue : All new comments reviewed before approval
Rate limiting : Prevent comment flooding (implementation dependent)
Content filters : Detect common spam patterns (implementation dependent)
Best Practices
Moderation
Review pending comments daily
Add clear moderation notes
Be consistent with decisions
Respond to reports promptly
Community Guidelines
Post clear commenting rules
Define acceptable behavior
Explain moderation process
Provide appeal mechanism
Engagement
Respond to quality comments
Encourage constructive discussion
Feature insightful comments
Thank active commenters
Performance
Paginate long comment threads
Lazy-load nested replies
Cache frequently accessed threads
Archive old comments
Track comment performance metrics:
// Average comments per post
const stats = await getCommentsStats ();
const avgPerPost = stats . total / totalPosts ;
// Engagement rate
const engagementRate = ( stats . approved / totalPosts ) * 100 ;
// Moderation efficiency
const approvalRate = ( stats . approved / stats . total ) * 100 ;