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

View File

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