4chan-x/src/General/lib/thread.class

50 lines
1.4 KiB
Plaintext
Executable File

class Thread
@callbacks = new Callbacks 'Thread'
toString: -> @ID
constructor: (@ID, @board) ->
@fullID = "#{@board}.#{@ID}"
@posts = new SimpleDict
@isSticky = false
@isClosed = false
@postLimit = false
@fileLimit = false
g.threads.push @fullID, board.threads.push @, @
setPage: (pageNum) ->
{info} = @OP.nodes
unless icon = $ '.page-num', info
icon = $.el 'span', className: 'page-num'
$.after $('a[title="Reply to this post"]', info), [$.tn(' '), icon]
icon.title = "This thread is on page #{pageNum} in the original index."
icon.textContent = "[#{pageNum}]"
setStatus: (type, status) ->
name = "is#{type}"
return if @[name] is status
@[name] = status
return unless @OP
typeLC = type.toLowerCase()
unless status
$.rm $ ".#{typeLC}Icon", @OP.nodes.info
return
icon = $.el 'img',
src: "//s.4cdn.org/image/#{typeLC}#{if window.devicePixelRatio >= 2 then '@2x' else ''}.gif"
alt: type
title: type
className: "#{typeLC}Icon retina"
root = if type is 'Closed' and @isSticky
$ '.stickyIcon', @OP.nodes.info
else
$('.page-num', @OP.nodes.info) or $('[title="Reply to this post"]', @OP.nodes.info)
$.after root, [$.tn(' '), icon]
kill: ->
@isDead = true
@timeOfDeath = Date.now()
collect: ->
@posts.forEach (post) -> post.collect()
g.threads.rm @fullID
@board.threads.rm @