From e0d73a64a744c24a97f2e970e67b0935944190b3 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 5 Sep 2012 03:33:51 +0200 Subject: [PATCH] Fix error where we could have parsed the same post more than once because of multiple request callbacks. --- 4chan_x.user.js | 18 ++++++++++++------ script.coffee | 17 ++++++++++++----- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index b8777fa53..594cbcb84 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1404,8 +1404,12 @@ link.nextSibling.href = "/" + board + "/res/" + threadID + "#q" + postID; inBoard = g.boards[board] || new Board(board); inThread = g.threads["" + board + "." + threadID] || new Thread(threadID, inBoard); - post = new Post(pc, inThread, inBoard); - Main.callbackNodes(Post, [post]); + if (!(post = g.posts["" + board + "." + postID])) { + post = new Post(postContainer, thread, board, { + isArchived: true + }); + Main.callbackNodes(Post, [post]); + } if (!root.parentNode) { return; } @@ -1482,10 +1486,12 @@ }); board = g.boards[board] || new Board(board); thread = g.threads["" + board + "." + threadID] || new Thread(threadID, board); - post = new Post(postContainer, thread, board, { - isArchived: true - }); - Main.callbackNodes(Post, [post]); + if (!(post = g.posts["" + board + "." + postID])) { + post = new Post(postContainer, thread, board, { + isArchived: true + }); + Main.callbackNodes(Post, [post]); + } if (!root.parentNode) { return; } diff --git a/script.coffee b/script.coffee index d99f05cd0..540da4509 100644 --- a/script.coffee +++ b/script.coffee @@ -1194,8 +1194,12 @@ Get = new Board board inThread = g.threads["#{board}.#{threadID}"] or new Thread threadID, inBoard - post = new Post pc, inThread, inBoard - Main.callbackNodes Post, [post] + # In case of multiple callbacks for the same request, + # don't parse the same original post more than once. + unless post = g.posts["#{board}.#{postID}"] + post = new Post postContainer, thread, board, + isArchived: true + Main.callbackNodes Post, [post] # Stop here if the container has been removed while loading. return unless root.parentNode @@ -1283,9 +1287,12 @@ Get = new Board board thread = g.threads["#{board}.#{threadID}"] or new Thread threadID, board - post = new Post postContainer, thread, board, - isArchived: true - Main.callbackNodes Post, [post] + # In case of multiple callbacks for the same request, + # don't parse the same original post more than once. + unless post = g.posts["#{board}.#{postID}"] + post = new Post postContainer, thread, board, + isArchived: true + Main.callbackNodes Post, [post] # Stop here if the container has been removed while loading. return unless root.parentNode