import { logMessage } from "https://esm.town/v/willthereader/logMessage";
export const extractCommentInfo = (comment) => {
try {
if (
!comment || typeof comment !== "object" || !comment.id || !comment.member || !comment.member.name || !comment.html
) {
throw new Error("Invalid comment object");
}
const createdAt = new Date(comment.created_at).toISOString();
const authorName = comment.member.name;
const commentText = comment.html;
let parentCommentText = null;
if (comment.replies && comment.replies.length > 0) {
parentCommentText = comment.replies[0].html;
}
const result = { authorName, commentText, parentCommentText, createdAt };
return result;
} catch (error) {
return { authorName: "Unknown", createdAt: new Date().toISOString() };
}
};