From 968cb9744b34f8e42e91c725208a2790930b48da Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 13 Mar 2013 21:42:09 +0100 Subject: [PATCH] Resurrect posts in case of false-positives. #932 --- 4chan_x.user.js | 29 +++++++++++++++++++++++++---- src/features.coffee | 8 ++++++-- src/main.coffee | 16 ++++++++++++++++ 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index de7260e12..c8e8d5bf2 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -5748,11 +5748,10 @@ _ref = ThreadUpdater.thread.posts; for (ID in _ref) { post = _ref[ID]; - if (post.isDead) { - continue; - } ID = +ID; - if (__indexOf.call(index, ID) < 0) { + if (post.isDead && __indexOf.call(index, ID) >= 0) { + post.resurrect(); + } else if (__indexOf.call(index, ID) < 0) { post.kill(); deletedPosts.push(post); } else if (post.file && !post.file.isDead && __indexOf.call(files, ID) < 0) { @@ -7345,6 +7344,28 @@ } }; + Post.prototype.resurrect = function() { + var clone, strong, _i, _len, _ref, _results; + delete this.isDead; + delete this.timeOfDeath; + $.rmClass(this.nodes.root, 'deleted-post'); + strong = $('strong.warning', this.nodes.info); + if (this.file && this.file.isDead) { + strong.textContent = '[File deleted]'; + } else { + $.rm(strong); + } + if (this.isClone) { + _ref = this.clones; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + clone = _ref[_i]; + _results.push(clone.resurrect()); + } + return _results; + } + }; + Post.prototype.addClone = function(context) { return new Clone(this, context); }; diff --git a/src/features.coffee b/src/features.coffee index f64dd39b4..3de6fbd1e 100644 --- a/src/features.coffee +++ b/src/features.coffee @@ -3941,9 +3941,13 @@ ThreadUpdater = deletedFiles = [] # Check for deleted posts/files. for ID, post of ThreadUpdater.thread.posts - continue if post.isDead + # XXX tmp fix for 4chan's racing condition + # giving us false-positive dead posts. + # continue if post.isDead ID = +ID - unless ID in index + if post.isDead and ID in index + post.resurrect() + else unless ID in index post.kill() deletedPosts.push post else if post.file and !post.file.isDead and ID not in files diff --git a/src/main.coffee b/src/main.coffee index 6e4963ecb..3c85dd717 100644 --- a/src/main.coffee +++ b/src/main.coffee @@ -185,6 +185,22 @@ class Post $.add quotelink, $.tn '\u00A0(Dead)' $.addClass quotelink, 'deadlink' return + # XXX tmp fix for 4chan's racing condition + # giving us false-positive dead posts. + resurrect: -> + delete @isDead + delete @timeOfDeath + $.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() + return addClone: (context) -> new Clone @, context rmClone: (index) ->