New test for fake deletions. Also restore post.resurrect. #354
This commit is contained in:
parent
4305703a1c
commit
ba8e6cbdb9
@ -216,6 +216,27 @@ class Post
|
|||||||
$.addClass quotelink, 'deadlink'
|
$.addClass quotelink, 'deadlink'
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# XXX Workaround 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()
|
||||||
g.posts.rm @fullID
|
g.posts.rm @fullID
|
||||||
|
|||||||
@ -63,7 +63,6 @@ ThreadUpdater =
|
|||||||
node: ->
|
node: ->
|
||||||
ThreadUpdater.thread = @
|
ThreadUpdater.thread = @
|
||||||
ThreadUpdater.root = @OP.nodes.root.parentNode
|
ThreadUpdater.root = @OP.nodes.root.parentNode
|
||||||
ThreadUpdater.lastPost = +@posts.keys[@posts.keys.length - 1]
|
|
||||||
ThreadUpdater.outdateCount = 0
|
ThreadUpdater.outdateCount = 0
|
||||||
|
|
||||||
# We must keep track of our own list of live posts/files
|
# We must keep track of our own list of live posts/files
|
||||||
@ -261,17 +260,17 @@ ThreadUpdater =
|
|||||||
new Notice 'info', "The thread is #{change}.", 30
|
new Notice 'info', "The thread is #{change}.", 30
|
||||||
|
|
||||||
parse: (req) ->
|
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
|
postObjects = req.response.posts
|
||||||
OP = postObjects[0]
|
OP = postObjects[0]
|
||||||
{thread} = ThreadUpdater
|
{thread} = ThreadUpdater
|
||||||
{board} = thread
|
{board} = thread
|
||||||
Build.spoilerRange[board] = OP.custom_spoiler
|
[..., lastPost] = ThreadUpdater.postIDs
|
||||||
|
|
||||||
|
# XXX Reject updates that falsely delete the last post.
|
||||||
|
return if postObjects[postObjects.length-1].no < lastPost and
|
||||||
|
new Date(req.getResponseHeader('Last-Modified')) - thread.posts[lastPost].info.date < 30 * $.SECOND
|
||||||
|
|
||||||
|
Build.spoilerRange[board] = OP.custom_spoiler
|
||||||
# XXX Some threads such as /g/'s sticky https://a.4cdn.org/g/thread/39894014.json still use a string as the archived property.
|
# XXX Some threads such as /g/'s sticky https://a.4cdn.org/g/thread/39894014.json still use a string as the archived property.
|
||||||
thread.setStatus 'Archived', !!+OP.archived
|
thread.setStatus 'Archived', !!+OP.archived
|
||||||
ThreadUpdater.updateThreadStatus 'Sticky', !!OP.sticky
|
ThreadUpdater.updateThreadStatus 'Sticky', !!OP.sticky
|
||||||
@ -280,22 +279,31 @@ ThreadUpdater =
|
|||||||
thread.fileLimit = !!OP.imagelimit
|
thread.fileLimit = !!OP.imagelimit
|
||||||
thread.ipCount = OP.unique_ips if OP.unique_ips?
|
thread.ipCount = OP.unique_ips if OP.unique_ips?
|
||||||
|
|
||||||
posts = [] # post objects
|
posts = [] # new post objects
|
||||||
index = [] # existing posts
|
index = [] # existing posts
|
||||||
files = [] # existing files
|
files = [] # existing files
|
||||||
count = 0 # new posts count
|
newPosts = [] # new post fullID list for API
|
||||||
|
|
||||||
# Build the index, create posts.
|
# Build the index, create posts.
|
||||||
for postObject in postObjects
|
for postObject in postObjects
|
||||||
num = postObject.no
|
ID = postObject.no
|
||||||
index.push num
|
index.push ID
|
||||||
files.push num if postObject.fsize
|
files.push ID if postObject.fsize
|
||||||
continue if num <= ThreadUpdater.lastPost
|
|
||||||
# Insert new posts, not older ones.
|
# Insert new posts, not older ones.
|
||||||
count++
|
continue if ID <= lastPost
|
||||||
|
|
||||||
|
newPosts.push "#{board}.#{ID}"
|
||||||
|
|
||||||
|
# XXX Resurrect wrongly deleted posts.
|
||||||
|
if (post = thread.posts[ID]) and not post.isFetchedQuote
|
||||||
|
post.resurrect()
|
||||||
|
continue
|
||||||
|
|
||||||
node = Build.postFromObject postObject, board.ID
|
node = Build.postFromObject postObject, board.ID
|
||||||
posts.push new Post node, thread, board
|
posts.push new Post node, thread, board
|
||||||
# Fetching your own posts after posting
|
# Fetching your own posts after posting
|
||||||
delete ThreadUpdater.postID if ThreadUpdater.postID is num
|
delete ThreadUpdater.postID if ThreadUpdater.postID is ID
|
||||||
|
|
||||||
# Check for deleted posts.
|
# Check for deleted posts.
|
||||||
deletedPosts = []
|
deletedPosts = []
|
||||||
@ -311,17 +319,16 @@ ThreadUpdater =
|
|||||||
deletedFiles.push "#{board}.#{ID}"
|
deletedFiles.push "#{board}.#{ID}"
|
||||||
ThreadUpdater.fileIDs = files
|
ThreadUpdater.fileIDs = files
|
||||||
|
|
||||||
unless count
|
unless posts.length
|
||||||
ThreadUpdater.set 'status', ''
|
ThreadUpdater.set 'status', ''
|
||||||
else
|
else
|
||||||
ThreadUpdater.set 'status', "+#{count}", 'new'
|
ThreadUpdater.set 'status', "+#{posts.length}", 'new'
|
||||||
ThreadUpdater.outdateCount = 0
|
ThreadUpdater.outdateCount = 0
|
||||||
if Conf['Beep'] and d.hidden and Unread.posts and !Unread.posts.size
|
if Conf['Beep'] and d.hidden and Unread.posts and !Unread.posts.size
|
||||||
unless ThreadUpdater.audio
|
unless ThreadUpdater.audio
|
||||||
ThreadUpdater.audio = $.el 'audio', src: ThreadUpdater.beep
|
ThreadUpdater.audio = $.el 'audio', src: ThreadUpdater.beep
|
||||||
ThreadUpdater.audio.play()
|
ThreadUpdater.audio.play()
|
||||||
|
|
||||||
ThreadUpdater.lastPost = posts[count - 1].ID
|
|
||||||
Main.callbackNodes Post, posts
|
Main.callbackNodes Post, posts
|
||||||
|
|
||||||
scroll = Conf['Auto Scroll'] and ThreadUpdater.scrollBG() and
|
scroll = Conf['Auto Scroll'] and ThreadUpdater.scrollBG() and
|
||||||
@ -349,7 +356,7 @@ ThreadUpdater =
|
|||||||
$.event 'ThreadUpdate',
|
$.event 'ThreadUpdate',
|
||||||
404: false
|
404: false
|
||||||
threadID: thread.fullID
|
threadID: thread.fullID
|
||||||
newPosts: (post.fullID for post in posts)
|
newPosts: newPosts
|
||||||
deletedPosts: deletedPosts
|
deletedPosts: deletedPosts
|
||||||
deletedFiles: deletedFiles
|
deletedFiles: deletedFiles
|
||||||
postCount: OP.replies + 1
|
postCount: OP.replies + 1
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user