From 01af49fd5236c611ad1a4516295fba24064a6349 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sun, 8 Mar 2015 18:54:03 -0700 Subject: [PATCH] Better fix for false-positive deleted posts: Check Last-Modified header. --- src/General/lib/post.class | 20 ------------------- src/Monitoring/ThreadUpdater.coffee | 30 ++++++++++++++--------------- 2 files changed, 15 insertions(+), 35 deletions(-) diff --git a/src/General/lib/post.class b/src/General/lib/post.class index fd45f2e83..76d6820c3 100755 --- a/src/General/lib/post.class +++ b/src/General/lib/post.class @@ -215,26 +215,6 @@ class Post quotelink.textContent = quotelink.textContent + '\u00A0(Dead)' $.addClass quotelink, 'deadlink' return - # XXX tmp fix for 4chan's racing condition - # giving us false-positive dead posts. - resurrect: -> - delete @isDead - $.rmClass @nodes.root, 'deleted-post' - strong = $ 'strong.warning', @nodes.info - # no false-positive files - if @file and @file.isDead - strong.textContent = '[File deleted]' - else - $.rm strong - - return if @isClone - for clone in @clones - clone.resurrect() - - for quotelink in Get.allQuotelinksLinkingTo @ when $.hasClass quotelink, 'deadlink' - quotelink.textContent = quotelink.textContent.replace '\u00A0(Dead)', '' - $.rmClass quotelink, 'deadlink' - return collect: -> @kill() diff --git a/src/Monitoring/ThreadUpdater.coffee b/src/Monitoring/ThreadUpdater.coffee index 22fd800cb..ae57b7528 100755 --- a/src/Monitoring/ThreadUpdater.coffee +++ b/src/Monitoring/ThreadUpdater.coffee @@ -123,7 +123,7 @@ ThreadUpdater = {req} = ThreadUpdater switch req.status when 200 - ThreadUpdater.parse req.response.posts + ThreadUpdater.parse req if ThreadUpdater.thread.isArchived ThreadUpdater.kill() else @@ -251,7 +251,13 @@ ThreadUpdater = 'not closed anymore' new Notice 'info', "The thread is #{change}.", 30 - parse: (postObjects) -> + parse: (req) -> + # XXX 4chan sometimes sends outdated JSON which would result in false-positive dead posts. + lastModified = new Date req.getResponseHeader('Last-Modified') + return if ThreadUpdater.lastModified and lastModified < ThreadUpdater.lastModified + ThreadUpdater.lastModified = lastModified + + postObjects = req.response.posts OP = postObjects[0] Build.spoilerRange[ThreadUpdater.thread.board] = OP.custom_spoiler @@ -278,21 +284,15 @@ ThreadUpdater = node = Build.postFromObject postObject, ThreadUpdater.thread.board.ID posts.push new Post node, ThreadUpdater.thread, ThreadUpdater.thread.board - # Check for deleted posts/files. ThreadUpdater.thread.posts.forEach (post) -> - # XXX tmp fix for 4chan's racing condition - # giving us false-positive dead posts. - # continue if post.isDead - ID = +post.ID + return if post.isDead - # Assume deleted posts less than 60 seconds old are false positives. - unless post.info.date > Date.now() - 60 * $.SECOND - unless ID in index - post.kill() - else if post.isDead - post.resurrect() - else if post.file and not (post.file.isDead or ID in files) - post.kill true + # Check for deleted posts/files. + ID = +post.ID + unless ID in index + post.kill() + else if post.file and not (post.file.isDead or ID in files) + post.kill true # Fetching your own posts after posting if ThreadUpdater.postID and ThreadUpdater.postID is ID