From fc90fd45d991b257328b82bb23b9e6ee448fd6eb Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Thu, 16 Jan 2014 11:56:21 -0700 Subject: [PATCH] Fix thread updater --- builds/4chan-X.user.js | 22 ++++++++-------------- builds/crx/script.js | 22 ++++++++-------------- src/Monitoring/ThreadUpdater.coffee | 10 ++++------ 3 files changed, 20 insertions(+), 34 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 1a8757cb3..df16a79dc 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -9218,7 +9218,7 @@ return new Notice('info', "The thread is " + change + ".", 30); }, parse: function(postObjects) { - var ID, OP, count, deletedFiles, deletedPosts, files, index, key, node, num, post, postObject, posts, root, scroll, _i, _j, _len, _len1, _ref; + var OP, count, deletedFiles, deletedPosts, files, index, node, num, post, postObject, posts, root, scroll, _i, _j, _len, _len1; OP = postObjects[0]; Build.spoilerRange[ThreadUpdater.thread.board] = OP.custom_spoiler; ThreadUpdater.updateThreadStatus('Sticky', !!OP.sticky); @@ -9245,12 +9245,9 @@ } deletedPosts = []; deletedFiles = []; - posts = ThreadUpdater.thread.posts; - _ref = posts.keys; - for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { - ID = _ref[_j]; - post = posts[ID]; - ID = +ID; + ThreadUpdater.thread.posts.forEach(function(post) { + var ID; + ID = +post.ID; if (__indexOf.call(index, ID) < 0) { post.kill(); deletedPosts.push(post); @@ -9261,9 +9258,9 @@ deletedFiles.push(post); } if (ThreadUpdater.postID && ThreadUpdater.postID === ID) { - ThreadUpdater.foundPost = true; + return ThreadUpdater.foundPost = true; } - } + }); if (!count) { ThreadUpdater.set('status', null, null); ThreadUpdater.outdateCount++; @@ -9281,11 +9278,8 @@ ThreadUpdater.lastPost = posts[count - 1].ID; Main.callbackNodes(Post, posts); scroll = Conf['Auto Scroll'] && ThreadUpdater.scrollBG() && ThreadUpdater.root.getBoundingClientRect().bottom - doc.clientHeight < 25; - for (key in posts) { - post = posts[key]; - if (!posts.hasOwnProperty(key)) { - continue; - } + for (_j = 0, _len1 = posts.length; _j < _len1; _j++) { + post = posts[_j]; root = post.nodes.root; if (post.cb) { if (!post.cb()) { diff --git a/builds/crx/script.js b/builds/crx/script.js index d959177b8..3613fc935 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -9201,7 +9201,7 @@ return new Notice('info', "The thread is " + change + ".", 30); }, parse: function(postObjects) { - var ID, OP, count, deletedFiles, deletedPosts, files, index, key, node, num, post, postObject, posts, root, scroll, _i, _j, _len, _len1, _ref; + var OP, count, deletedFiles, deletedPosts, files, index, node, num, post, postObject, posts, root, scroll, _i, _j, _len, _len1; OP = postObjects[0]; Build.spoilerRange[ThreadUpdater.thread.board] = OP.custom_spoiler; ThreadUpdater.updateThreadStatus('Sticky', !!OP.sticky); @@ -9228,12 +9228,9 @@ } deletedPosts = []; deletedFiles = []; - posts = ThreadUpdater.thread.posts; - _ref = posts.keys; - for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { - ID = _ref[_j]; - post = posts[ID]; - ID = +ID; + ThreadUpdater.thread.posts.forEach(function(post) { + var ID; + ID = +post.ID; if (__indexOf.call(index, ID) < 0) { post.kill(); deletedPosts.push(post); @@ -9244,9 +9241,9 @@ deletedFiles.push(post); } if (ThreadUpdater.postID && ThreadUpdater.postID === ID) { - ThreadUpdater.foundPost = true; + return ThreadUpdater.foundPost = true; } - } + }); if (!count) { ThreadUpdater.set('status', null, null); ThreadUpdater.outdateCount++; @@ -9264,11 +9261,8 @@ ThreadUpdater.lastPost = posts[count - 1].ID; Main.callbackNodes(Post, posts); scroll = Conf['Auto Scroll'] && ThreadUpdater.scrollBG() && ThreadUpdater.root.getBoundingClientRect().bottom - doc.clientHeight < 25; - for (key in posts) { - post = posts[key]; - if (!posts.hasOwnProperty(key)) { - continue; - } + for (_j = 0, _len1 = posts.length; _j < _len1; _j++) { + post = posts[_j]; root = post.nodes.root; if (post.cb) { if (!post.cb()) { diff --git a/src/Monitoring/ThreadUpdater.coffee b/src/Monitoring/ThreadUpdater.coffee index 43b61e8da..a55877426 100755 --- a/src/Monitoring/ThreadUpdater.coffee +++ b/src/Monitoring/ThreadUpdater.coffee @@ -290,13 +290,11 @@ ThreadUpdater = deletedFiles = [] # Check for deleted posts/files. - {posts} = ThreadUpdater.thread - for ID in posts.keys - post = posts[ID] + ThreadUpdater.thread.posts.forEach (post) -> # XXX tmp fix for 4chan's racing condition # giving us false-positive dead posts. # continue if post.isDead - ID = +ID + ID = +post.ID unless ID in index post.kill() @@ -307,6 +305,7 @@ ThreadUpdater = post.kill true deletedFiles.push post + # Fetching your own posts after posting if ThreadUpdater.postID and ThreadUpdater.postID is ID ThreadUpdater.foundPost = true @@ -327,8 +326,7 @@ ThreadUpdater = scroll = Conf['Auto Scroll'] and ThreadUpdater.scrollBG() and ThreadUpdater.root.getBoundingClientRect().bottom - doc.clientHeight < 25 - for key, post of posts - continue unless posts.hasOwnProperty key + for post in posts root = post.nodes.root if post.cb unless post.cb()