diff --git a/static/comments/getcomments.js b/static/comments/getcomments.js index caceaa4..ac8953e 100644 --- a/static/comments/getcomments.js +++ b/static/comments/getcomments.js @@ -4,6 +4,18 @@ SPDX-FileCopyrightText: 2019 Björn Schießle */ +// Debug logging helper +var debugEnabled = false; +function debugLog(message, data) { + if (debugEnabled) { + if (data !== undefined) { + console.log('[Mastodon Comments] ' + message, data); + } else { + console.log('[Mastodon Comments] ' + message); + } + } +} + $(document).ready(function() { // check if we show a blog post or not. Regex is defined in site-wide config @@ -14,6 +26,8 @@ $(document).ready(function() { return; } + debugLog('Searching for comments for: ' + RelPermalink); + $.ajax({ url: "/comments/getcomments.php", type: "get", @@ -21,13 +35,30 @@ $(document).ready(function() { search : RelPermalink }, success: function(data) { + // Enable debug logging if backend has debug enabled + if (data.debug === true) { + debugEnabled = true; + debugLog('Debug mode enabled'); + } + + debugLog('Received data from backend', data); + var stats = data.stats; var root = data.stats.root; + + debugLog('Stats - Favs: ' + stats.favs + ', Reblogs: ' + stats.reblogs + ', Replies: ' + stats.replies); + debugLog('Root toot ID: ' + root); + $("#like-count-container").append('
'); $("#reblog-count-container").append(''); $("#reply-count-container").append(''); + var comments = data.comments; + var commentCount = Object.keys(comments).length; + debugLog('Processing ' + commentCount + ' comments'); + $.each(comments, function(key, value) { + debugLog('Adding comment: ' + key, value); var timestamp = Date.parse(value.date); var date = new Date(timestamp); var comment = "