Back

Version 51

2/15/2024
import { logMessage } from "https://esm.town/v/willthereader/logMessage";
export const extractCommentInfo = (comment) => {
// logMessage("debug", `Comment ID: ${comment.id}, Comment Text: ${comment.html}`);
try {
// Validate the comment object to ensure it has necessary properties
if (
!comment || typeof comment !== "object" || !comment.id || !comment.member || !comment.member.name || !comment.html
) {
throw new Error("Invalid comment object");
}

// Declare and initialize createdAt using the created_at property from the comment object
const createdAt = new Date(comment.created_at).toISOString(); // Convert to ISO string format

// logMessage("debug", `extractCommentInfo called with comment: ${JSON.stringify(comment)}`);
// const authorName = comment.member.name;
/*const commentText = comment.html;
let parentCommentText = null;*/
// Check if there are replies and if so, get the text of the first reply (assuming it's the parent comment)
// console.log("Replies: ", comment.replies);
/*if (comment.replies && comment.replies.length > 0) {
parentCommentText = comment.replies[0].html;
}*/
const result = { authorName };

// logMessage("debug", `extractCommentInfo result: ${JSON.stringify(result)}`);
return result;
} catch (error) {
// logMessage("error", `Error: ${error.message}`);
return { authorName: "Unknown", createdAt: new Date().toISOString() };
}
};
Updated: February 15, 2024