Process posts added by thread updating or expansion scripts.
This commit is contained in:
parent
9630b06f90
commit
0ca735c200
@ -7,7 +7,7 @@ RelativeDates =
|
|||||||
Index.enabled
|
Index.enabled
|
||||||
)
|
)
|
||||||
@flush()
|
@flush()
|
||||||
$.on d, 'visibilitychange ThreadUpdate', @flush
|
$.on d, 'visibilitychange PostsInserted', @flush
|
||||||
|
|
||||||
if Conf['Relative Post Dates']
|
if Conf['Relative Post Dates']
|
||||||
Callbacks.Post.push
|
Callbacks.Post.push
|
||||||
|
|||||||
@ -60,7 +60,7 @@ Unread =
|
|||||||
Unread.readCount = 0
|
Unread.readCount = 0
|
||||||
Unread.readCount++ for ID in @posts.keys when +ID <= Unread.lastReadPost
|
Unread.readCount++ for ID in @posts.keys when +ID <= Unread.lastReadPost
|
||||||
$.one d, '4chanXInitFinished', Unread.ready
|
$.one d, '4chanXInitFinished', Unread.ready
|
||||||
$.on d, 'ThreadUpdate', Unread.onUpdate
|
$.on d, 'PostsInserted', Unread.onUpdate
|
||||||
|
|
||||||
ready: ->
|
ready: ->
|
||||||
Unread.scroll() if Conf['Remember Last Read Post'] and Conf['Scroll to Last Read Post']
|
Unread.scroll() if Conf['Remember Last Read Post'] and Conf['Scroll to Last Read Post']
|
||||||
@ -137,11 +137,11 @@ Unread =
|
|||||||
notif.close()
|
notif.close()
|
||||||
, 7 * $.SECOND
|
, 7 * $.SECOND
|
||||||
|
|
||||||
onUpdate: (e) ->
|
onUpdate: ->
|
||||||
if !e.detail[404]
|
$.queueTask -> # ThreadUpdater may scroll immediately after inserting posts
|
||||||
Unread.setLine()
|
Unread.setLine()
|
||||||
Unread.read()
|
Unread.read()
|
||||||
Unread.update()
|
Unread.update()
|
||||||
|
|
||||||
readSinglePost: (post) ->
|
readSinglePost: (post) ->
|
||||||
{ID} = post
|
{ID} = post
|
||||||
|
|||||||
@ -326,6 +326,9 @@ Main =
|
|||||||
if (board = $ s.board)
|
if (board = $ s.board)
|
||||||
threads = []
|
threads = []
|
||||||
posts = []
|
posts = []
|
||||||
|
errors = []
|
||||||
|
|
||||||
|
Main.addPostsObserver = new MutationObserver Main.addPosts
|
||||||
|
|
||||||
for threadRoot in $$(s.thread, board)
|
for threadRoot in $$(s.thread, board)
|
||||||
boardObj = if (boardID = threadRoot.dataset.board)
|
boardObj = if (boardID = threadRoot.dataset.board)
|
||||||
@ -338,17 +341,9 @@ Main =
|
|||||||
threads.push thread
|
threads.push thread
|
||||||
postRoots = $$ s.postContainer, threadRoot
|
postRoots = $$ s.postContainer, threadRoot
|
||||||
postRoots.unshift threadRoot if Site.isOPContainerThread
|
postRoots.unshift threadRoot if Site.isOPContainerThread
|
||||||
for postRoot in postRoots when $(s.comment, postRoot)
|
Main.parsePosts postRoots, thread, posts, errors
|
||||||
try
|
Main.addPostsObserver.observe threadRoot, {childList: true}
|
||||||
posts.push new Post postRoot, thread, thread.board
|
Main.handleErrors errors if errors.length
|
||||||
catch err
|
|
||||||
# Skip posts that we failed to parse.
|
|
||||||
unless errors
|
|
||||||
errors = []
|
|
||||||
errors.push
|
|
||||||
message: "Parsing of Post No.#{postRoot.id.match(/\d+/)} failed. Post will be skipped."
|
|
||||||
error: err
|
|
||||||
Main.handleErrors errors if errors
|
|
||||||
|
|
||||||
if g.VIEW is 'thread'
|
if g.VIEW is 'thread'
|
||||||
Site.parseThreadMetadata?(threads[0])
|
Site.parseThreadMetadata?(threads[0])
|
||||||
@ -363,6 +358,33 @@ Main =
|
|||||||
Main.expectInitFinished = true
|
Main.expectInitFinished = true
|
||||||
$.event '4chanXInitFinished'
|
$.event '4chanXInitFinished'
|
||||||
|
|
||||||
|
parsePosts: (postRoots, thread, posts, errors) ->
|
||||||
|
for postRoot in postRoots when !postRoot.dataset.fullID and $(Site.selectors.comment, postRoot)
|
||||||
|
try
|
||||||
|
posts.push new Post postRoot, thread, thread.board
|
||||||
|
catch err
|
||||||
|
# Skip posts that we failed to parse.
|
||||||
|
errors.push
|
||||||
|
message: "Parsing of Post No.#{postRoot.id.match(/\d+/)} failed. Post will be skipped."
|
||||||
|
error: err
|
||||||
|
return
|
||||||
|
|
||||||
|
addPosts: (records) ->
|
||||||
|
threads = []
|
||||||
|
posts = []
|
||||||
|
errors = []
|
||||||
|
for record in records
|
||||||
|
thread = Get.threadFromRoot record.target
|
||||||
|
n = posts.length
|
||||||
|
Main.parsePosts record.addedNodes, thread, posts, errors
|
||||||
|
if posts.length > n and thread not in threads
|
||||||
|
threads.push thread
|
||||||
|
Main.handleErrors errors if errors.length
|
||||||
|
Main.callbackNodesDB 'Post', posts, ->
|
||||||
|
for thread in threads
|
||||||
|
$.event 'PostsInserted', null, thread.nodes.root
|
||||||
|
return
|
||||||
|
|
||||||
callbackNodes: (klass, nodes) ->
|
callbackNodes: (klass, nodes) ->
|
||||||
i = 0
|
i = 0
|
||||||
cb = Callbacks[klass]
|
cb = Callbacks[klass]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user