deletion reason and email for soft deleted forum posts and comments by admin
This commit is contained in:
@@ -9,6 +9,7 @@ const TemplateManager = require("../core/TemplateManager");
|
||||
* - Sending answer accepted notifications
|
||||
* - Sending thread activity notifications to participants
|
||||
* - Sending location-based item request notifications to nearby users
|
||||
* - Sending post/comment deletion notifications to authors
|
||||
*/
|
||||
class ForumEmailService {
|
||||
constructor() {
|
||||
@@ -386,6 +387,128 @@ class ForumEmailService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send notification when a forum post is deleted by admin
|
||||
* @param {Object} postAuthor - Post author user object
|
||||
* @param {string} postAuthor.firstName - Post author's first name
|
||||
* @param {string} postAuthor.email - Post author's email
|
||||
* @param {Object} admin - Admin user object who deleted the post
|
||||
* @param {string} admin.firstName - Admin's first name
|
||||
* @param {string} admin.lastName - Admin's last name
|
||||
* @param {Object} post - Forum post object
|
||||
* @param {string} post.title - Post title
|
||||
* @param {string} deletionReason - Reason for deletion
|
||||
* @returns {Promise<{success: boolean, messageId?: string, error?: string}>}
|
||||
*/
|
||||
async sendForumPostDeletionNotification(postAuthor, admin, post, deletionReason) {
|
||||
if (!this.initialized) {
|
||||
await this.initialize();
|
||||
}
|
||||
|
||||
try {
|
||||
const supportEmail = process.env.SUPPORT_EMAIL;
|
||||
const frontendUrl = process.env.FRONTEND_URL || "http://localhost:3000";
|
||||
|
||||
const variables = {
|
||||
postAuthorName: postAuthor.firstName || "there",
|
||||
adminName: `${admin.firstName} ${admin.lastName}`.trim() || "An administrator",
|
||||
postTitle: post.title,
|
||||
deletionReason,
|
||||
supportEmail,
|
||||
forumUrl: `${frontendUrl}/forum`,
|
||||
};
|
||||
|
||||
const htmlContent = await this.templateManager.renderTemplate(
|
||||
"forumPostDeletionToAuthor",
|
||||
variables
|
||||
);
|
||||
|
||||
const subject = `Important: Your forum post "${post.title}" has been removed`;
|
||||
|
||||
const result = await this.emailClient.sendEmail(
|
||||
postAuthor.email,
|
||||
subject,
|
||||
htmlContent
|
||||
);
|
||||
|
||||
if (result.success) {
|
||||
console.log(
|
||||
`Forum post deletion notification email sent to ${postAuthor.email}`
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error(
|
||||
"Failed to send forum post deletion notification email:",
|
||||
error
|
||||
);
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send notification when a forum comment is deleted by admin
|
||||
* @param {Object} commentAuthor - Comment author user object
|
||||
* @param {string} commentAuthor.firstName - Comment author's first name
|
||||
* @param {string} commentAuthor.email - Comment author's email
|
||||
* @param {Object} admin - Admin user object who deleted the comment
|
||||
* @param {string} admin.firstName - Admin's first name
|
||||
* @param {string} admin.lastName - Admin's last name
|
||||
* @param {Object} post - Forum post object the comment belongs to
|
||||
* @param {string} post.title - Post title
|
||||
* @param {string} post.id - Post ID
|
||||
* @param {string} deletionReason - Reason for deletion
|
||||
* @returns {Promise<{success: boolean, messageId?: string, error?: string}>}
|
||||
*/
|
||||
async sendForumCommentDeletionNotification(commentAuthor, admin, post, deletionReason) {
|
||||
if (!this.initialized) {
|
||||
await this.initialize();
|
||||
}
|
||||
|
||||
try {
|
||||
const supportEmail = process.env.SUPPORT_EMAIL;
|
||||
const frontendUrl = process.env.FRONTEND_URL || "http://localhost:3000";
|
||||
const postUrl = `${frontendUrl}/forum/posts/${post.id}`;
|
||||
|
||||
const variables = {
|
||||
commentAuthorName: commentAuthor.firstName || "there",
|
||||
adminName: `${admin.firstName} ${admin.lastName}`.trim() || "An administrator",
|
||||
postTitle: post.title,
|
||||
postUrl,
|
||||
deletionReason,
|
||||
supportEmail,
|
||||
};
|
||||
|
||||
const htmlContent = await this.templateManager.renderTemplate(
|
||||
"forumCommentDeletionToAuthor",
|
||||
variables
|
||||
);
|
||||
|
||||
const subject = `Your comment on "${post.title}" has been removed`;
|
||||
|
||||
const result = await this.emailClient.sendEmail(
|
||||
commentAuthor.email,
|
||||
subject,
|
||||
htmlContent
|
||||
);
|
||||
|
||||
if (result.success) {
|
||||
console.log(
|
||||
`Forum comment deletion notification email sent to ${commentAuthor.email}`
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error(
|
||||
"Failed to send forum comment deletion notification email:",
|
||||
error
|
||||
);
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send notification to nearby users about an item request
|
||||
* @param {Object} recipient - Recipient user object
|
||||
|
||||
Reference in New Issue
Block a user