Check for deleted posts and images when updating a thread.

ref #73
This commit is contained in:
Nicolas Stepien 2012-09-14 23:01:40 +02:00
parent b9f0aa47fc
commit 101f593e18
2 changed files with 81 additions and 24 deletions

View File

@ -750,12 +750,25 @@
}
this.isReply = $.hasClass(post, 'reply');
if (that.isArchived) {
this.isDead = true;
this.kill();
}
this.clones = [];
g.posts["" + board + "." + this] = thread.posts[this] = board.posts[this] = this;
}
Post.prototype.kill = function(img) {
if (this.file && !this.file.isDead) {
this.file.isDead = true;
$.log('kill image', this.ID);
}
if (img) {
return;
}
$.log('kill post', this.ID);
this.isDead = true;
return $.addClass(this.nodes.root, 'dead');
};
Post.prototype.addClone = function(context) {
return new Clone(this, context);
};
@ -1623,6 +1636,8 @@
textContent: "" + quote + "\u00A0(Dead)",
target: '_blank'
});
a.setAttribute('data-board', board);
a.setAttribute('data-postid', ID);
} else {
a = $.el('a', {
href: "/" + board + "/" + post.thread + "/res/#p" + ID,
@ -2526,7 +2541,7 @@
default:
this.unsuccessfulFetchCount++;
this.set('timer', this.getInterval());
this.set('status', this.req.statusText);
this.set('status', "" + this.req.statusText + " (" + this.req.status + ")");
this.status.className = 'warning';
}
return delete this.req;
@ -2589,23 +2604,40 @@
};
_Class.prototype.parse = function(postObjects) {
var count, node, nodes, postObject, posts, scroll, spoilerRange, _i, _len, _ref;
if (spoilerRange = postObjects[0].custom_spoiler) {
Build.spoilerRange[this.thread.board] = spoilerRange;
}
var ID, count, i, image, index, node, nodes, num, post, postObject, posts, scroll, _i, _len, _ref;
Build.spoilerRange[this.thread.board] = postObjects[0].custom_spoiler;
nodes = [];
posts = [];
index = [];
image = [];
count = 0;
_ref = postObjects.reverse();
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
postObject = _ref[_i];
if (postObject.no <= this.lastPost) {
break;
for (_i = 0, _len = postObjects.length; _i < _len; _i++) {
postObject = postObjects[_i];
num = postObject.no;
index.push(num);
if (postObject.ext) {
image.push(num);
}
if (num <= this.lastPost) {
continue;
}
count++;
node = Build.postFromObject(postObject, this.thread.board.ID);
nodes.unshift(node);
posts.unshift(new Post(node, this.thread, this.thread.board));
nodes.push(node);
posts.push(new Post(node, this.thread, this.thread.board));
}
_ref = this.thread.posts;
for (i in _ref) {
post = _ref[i];
if (post.isDead) {
continue;
}
ID = post.ID;
if (-1 === index.indexOf(ID)) {
post.kill();
} else if (post.file && !post.file.isDead && -1 === image.indexOf(ID)) {
post.kill(true);
}
}
if (count) {
this.set('status', "+" + count);

View File

@ -598,10 +598,18 @@ class Post
@file.dimensions = @file.text.textContent.match(/\d+x\d+/)[0]
@isReply = $.hasClass post, 'reply'
@isDead = true if that.isArchived
@kill() if that.isArchived
@clones = []
g.posts["#{board}.#{@}"] = thread.posts[@] = board.posts[@] = @
kill: (img) ->
if @file and !@file.isDead
@file.isDead = true
return if img
@isDead = true
$.addClass @nodes.root, 'dead'
# XXX style dead posts.
# XXX update quotelinks/backlinks to this post.
addClone: (context) ->
new Clone @, context
rmClone: (index) ->
@ -1577,6 +1585,8 @@ Quotify =
className: 'quotelink deadlink'
textContent: "#{quote}\u00A0(Dead)"
target: '_blank'
a.setAttribute 'data-board', board
a.setAttribute 'data-postid', ID
else
# Don't (Dead) when quotifying in an archived post,
# and we know the post still exists.
@ -2246,7 +2256,7 @@ ThreadUpdater =
else
@unsuccessfulFetchCount++
@set 'timer', @getInterval()
@set 'status', @req.statusText
@set 'status', "#{@req.statusText} (#{@req.status})"
@status.className = 'warning'
delete @req
@ -2291,18 +2301,33 @@ ThreadUpdater =
headers: 'If-Modified-Since': @lastModified
parse: (postObjects) ->
if spoilerRange = postObjects[0].custom_spoiler
Build.spoilerRange[@thread.board] = spoilerRange
Build.spoilerRange[@thread.board] = postObjects[0].custom_spoiler
nodes = []
posts = []
count = 0
for postObject in postObjects.reverse()
break if postObject.no <= @lastPost # Make sure to not insert older posts.
nodes = [] # post container elements
posts = [] # post objects
index = [] # existing posts
image = [] # existing images
count = 0 # new posts count
# Build the index, create posts.
for postObject in postObjects
num = postObject.no
index.push num
image.push num if postObject.ext
continue if num <= @lastPost
# Insert new posts, not older ones.
count++
node = Build.postFromObject postObject, @thread.board.ID
nodes.unshift node
posts.unshift new Post node, @thread, @thread.board
nodes.push node
posts.push new Post node, @thread, @thread.board
# Check for deleted posts and deleted images.
for i, post of @thread.posts
continue if post.isDead
{ID} = post
if -1 is index.indexOf ID
post.kill()
else if post.file and !post.file.isDead and -1 is image.indexOf ID
post.kill true
if count
@set 'status', "+#{count}"