Reorganize thread building.

This commit is contained in:
ccd0 2016-09-24 22:06:15 -07:00
parent 5fbe0c27d2
commit 2917636bcf
2 changed files with 19 additions and 24 deletions

View File

@ -162,32 +162,24 @@ Build =
textContent: Build.summaryText '', posts, files textContent: Build.summaryText '', posts, files
href: "/#{boardID}/thread/#{threadID}" href: "/#{boardID}/thread/#{threadID}"
thread: (board, data) -> thread: (board, data, OP) ->
Build.spoilerRange[board] = data.custom_spoiler if (root = OP.nodes.root.parentNode)
if OP = board.posts[data.no]
OP = null if OP.isFetchedQuote
if OP and (root = OP.nodes.root.parentNode)
$.rmAll root $.rmAll root
else else
root = $.el 'div', root = $.el 'div',
className: 'thread' className: 'thread'
id: "t#{data.no}" id: "t#{data.no}"
$.add root, Build.hat.cloneNode(false) if Build.hat
$.add root, Build.excerptThread(board, data, OP) $.add root, OP.nodes.root
root
excerptThread: (board, data, OP) ->
nodes = [if OP then OP.nodes.root else Build.postFromObject data, board.ID, true]
if data.omitted_posts or !Conf['Show Replies'] and data.replies if data.omitted_posts or !Conf['Show Replies'] and data.replies
[posts, files] = if Conf['Show Replies'] [posts, files] = if Conf['Show Replies']
# XXX data.omitted_images is not accurate. # XXX data.omitted_images is not accurate.
[data.omitted_posts, data.images - data.last_replies.filter((data) -> !!data.ext).length] [data.omitted_posts, data.images - data.last_replies.filter((data) -> !!data.ext).length]
else else
[data.replies, data.images] [data.replies, data.images]
nodes.push Build.summary board.ID, data.no, posts, files summary = Build.summary board.ID, data.no, posts, files
nodes $.add root, summary
root
catalogThread: (thread) -> catalogThread: (thread) ->
{staticPath, gifIcon} = Build {staticPath, gifIcon} = Build

View File

@ -107,13 +107,13 @@ Index =
d.title = d.title.replace /\ -\ Page\ \d+/, '' d.title = d.title.replace /\ -\ Page\ \d+/, ''
$.onExists doc, '.board > .thread > .postContainer, .board + *', -> $.onExists doc, '.board > .thread > .postContainer, .board + *', ->
Index.hat = $ '.board > .thread > img:first-child' Build.hat = $ '.board > .thread > img:first-child'
if Index.hat if Build.hat
if Index.nodes if Index.nodes
for ID, threadRoot of Index.nodes for ID, threadRoot of Index.nodes
$.prepend threadRoot, Index.hat.cloneNode false $.prepend threadRoot, Build.hat.cloneNode false
$.addClass doc, 'hats-enabled' $.addClass doc, 'hats-enabled'
$.addStyle ".catalog-thread::after {background-image: url(#{Index.hat.src});}" $.addStyle ".catalog-thread::after {background-image: url(#{Build.hat.src});}"
board = $ '.board' board = $ '.board'
$.replace board, Index.root $.replace board, Index.root
@ -562,6 +562,8 @@ Index =
Index.threadsNumPerPage = pages[0]?.threads.length or 1 Index.threadsNumPerPage = pages[0]?.threads.length or 1
Index.liveThreadData = pages.reduce ((arr, next) -> arr.concat next.threads), [] Index.liveThreadData = pages.reduce ((arr, next) -> arr.concat next.threads), []
Index.liveThreadIDs = Index.liveThreadData.map (data) -> data.no Index.liveThreadIDs = Index.liveThreadData.map (data) -> data.no
if Index.liveThreadData[0]
Build.spoilerRange[g.BOARD.ID] = Index.liveThreadData[0].custom_spoiler
g.BOARD.threads.forEach (thread) -> g.BOARD.threads.forEach (thread) ->
thread.collect() unless thread.ID in Index.liveThreadIDs thread.collect() unless thread.ID in Index.liveThreadIDs
return return
@ -573,8 +575,6 @@ Index =
posts = [] posts = []
for threadData, i in Index.liveThreadData for threadData, i in Index.liveThreadData
try try
threadRoot = Build.thread g.BOARD, threadData
$.prepend threadRoot, Index.hat.cloneNode false if Index.hat
if (thread = g.BOARD.threads[threadData.no]) if (thread = g.BOARD.threads[threadData.no])
thread.setCount 'post', threadData.replies + 1, threadData.bumplimit thread.setCount 'post', threadData.replies + 1, threadData.bumplimit
thread.setCount 'file', threadData.images + !!threadData.ext, threadData.imagelimit thread.setCount 'file', threadData.images + !!threadData.ext, threadData.imagelimit
@ -583,10 +583,13 @@ Index =
else else
thread = new Thread threadData.no, g.BOARD thread = new Thread threadData.no, g.BOARD
threads.push thread threads.push thread
Index.nodes[thread.ID] = threadRoot
unless thread.OP and not thread.OP.isFetchedQuote unless (OP = thread.OP) and not OP.isFetchedQuote
posts.push new Post $('.opContainer', threadRoot), thread, g.BOARD OP = new Post Build.postFromObject(threadData, g.BOARD.ID, true), thread, g.BOARD
posts.push OP
thread.setPage i // Index.threadsNumPerPage + 1 thread.setPage i // Index.threadsNumPerPage + 1
Index.nodes[thread.ID] = Build.thread g.BOARD, threadData, OP
catch err catch err
# Skip posts that we failed to parse. # Skip posts that we failed to parse.
errors = [] unless errors errors = [] unless errors