Better fix for false-positive deleted posts: Check Last-Modified header.

This commit is contained in:
ccd0 2015-03-08 18:54:03 -07:00
parent 949eb05187
commit 01af49fd52
2 changed files with 15 additions and 35 deletions

View File

@ -215,26 +215,6 @@ class Post
quotelink.textContent = quotelink.textContent + '\u00A0(Dead)' quotelink.textContent = quotelink.textContent + '\u00A0(Dead)'
$.addClass quotelink, 'deadlink' $.addClass quotelink, 'deadlink'
return 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: -> collect: ->
@kill() @kill()

View File

@ -123,7 +123,7 @@ ThreadUpdater =
{req} = ThreadUpdater {req} = ThreadUpdater
switch req.status switch req.status
when 200 when 200
ThreadUpdater.parse req.response.posts ThreadUpdater.parse req
if ThreadUpdater.thread.isArchived if ThreadUpdater.thread.isArchived
ThreadUpdater.kill() ThreadUpdater.kill()
else else
@ -251,7 +251,13 @@ ThreadUpdater =
'not closed anymore' 'not closed anymore'
new Notice 'info', "The thread is #{change}.", 30 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] OP = postObjects[0]
Build.spoilerRange[ThreadUpdater.thread.board] = OP.custom_spoiler Build.spoilerRange[ThreadUpdater.thread.board] = OP.custom_spoiler
@ -278,21 +284,15 @@ ThreadUpdater =
node = Build.postFromObject postObject, ThreadUpdater.thread.board.ID node = Build.postFromObject postObject, ThreadUpdater.thread.board.ID
posts.push new Post node, ThreadUpdater.thread, ThreadUpdater.thread.board posts.push new Post node, ThreadUpdater.thread, ThreadUpdater.thread.board
# Check for deleted posts/files.
ThreadUpdater.thread.posts.forEach (post) -> ThreadUpdater.thread.posts.forEach (post) ->
# XXX tmp fix for 4chan's racing condition return if post.isDead
# giving us false-positive dead posts.
# continue if post.isDead
ID = +post.ID
# Assume deleted posts less than 60 seconds old are false positives. # Check for deleted posts/files.
unless post.info.date > Date.now() - 60 * $.SECOND ID = +post.ID
unless ID in index unless ID in index
post.kill() post.kill()
else if post.isDead else if post.file and not (post.file.isDead or ID in files)
post.resurrect() post.kill true
else if post.file and not (post.file.isDead or ID in files)
post.kill true
# Fetching your own posts after posting # Fetching your own posts after posting
if ThreadUpdater.postID and ThreadUpdater.postID is ID if ThreadUpdater.postID and ThreadUpdater.postID is ID