diff --git a/inc/functions.php b/inc/functions.php index e0de1c2c..d7192f43 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -2303,6 +2303,8 @@ function buildThread($id, $return = false, $mod = false) { $action = generation_strategy('sb_thread', array($board['uri'], $id)); + $rendered_thread = null; + if ($action == 'rebuild' || $return || $mod) { $query = prepare(sprintf("SELECT *,'%s' as board FROM ``posts_%s`` WHERE (`thread` IS NULL AND `id` = :id) OR `thread` = :id ORDER BY `thread`,`id`", $board['uri'],$board['uri'])); $query->bindValue(':id', $id, PDO::PARAM_INT); @@ -2323,10 +2325,12 @@ function buildThread($id, $return = false, $mod = false) { $hasnoko50 = $thread->postCount() >= $config['noko50_min']; $antibot = $mod || $return ? false : create_antibot($board['uri'], $id); + $rendered_thread = $thread->build(); + $body = Element('thread.html', array( 'board' => $board, 'thread' => $thread, - 'body' => $thread->build(), + 'body' => $rendered_thread, 'config' => $config, 'id' => $id, 'mod' => $mod, @@ -2364,6 +2368,8 @@ function buildThread($id, $return = false, $mod = false) { } file_write($board['dir'] . $config['dir']['res'] . link_for($thread), $body); + + return $rendered_thread; } } diff --git a/js/lcn/thread_autoupdater.js b/js/lcn/thread_autoupdater.js index 51c85ab8..2308e293 100644 --- a/js/lcn/thread_autoupdater.js +++ b/js/lcn/thread_autoupdater.js @@ -236,22 +236,18 @@ $().ready(() => { return; } - const post_dom = parser.parseFromString( - post_response['post'], + const thread_dom = parser.parseFromString( + post_response['thread'], "text/html"); - const post_elem = post_dom.querySelector(".postcontainer"); - console.log(post_elem); - const post_container = LCNPostContainer.assign(post_elem); - console.log("lcn_post_container:", post_container); - const thread_id_sel = "#thread_" + post_response['thread_id']; - const thread = document.querySelector(thread_id_sel); - console.log("thread:", thread); - const lcn_thread = new LCNThread(thread); - console.log("lcn_thread: ", lcn_thread); + const post_containers = [...thread_dom.querySelectorAll(`${thread_id_sel} > .postcontainer`)] + .map(elem => LCNPostContainer.assign(elem)); - updateThreadFn(lcn_thread, [ post_container ]); + const thread_elem = document.querySelector(thread_id_sel); + const lcn_thread = new LCNThread(thread_elem); + + updateThreadFn(lcn_thread, post_containers); } } }) diff --git a/post.php b/post.php index d6defd43..52ed7605 100644 --- a/post.php +++ b/post.php @@ -1477,7 +1477,7 @@ function handle_post(){ $thread_id = $post['op'] ? $id : $post['thread']; - buildThread($thread_id); + $rendered_thread = buildThread($thread_id); if ($config['syslog']) _syslog(LOG_INFO, 'New post: /' . $board['dir'] . $config['dir']['res'] . @@ -1494,8 +1494,8 @@ function handle_post(){ 'redirect' => $redirect, 'noko' => $noko, 'id' => $id, - 'post' => (new Post($post))->build(), - 'thread_id' => $thread_id + 'thread_id' => $thread_id, + 'thread' => $rendered_thread )); }