From 2f9e44a7734c18efc32318acc26c3f6642198aaa Mon Sep 17 00:00:00 2001 From: Mayhem Date: Fri, 1 Nov 2013 18:27:37 +0100 Subject: [PATCH] Update the threads sticky/closed status on each index refresh. Also fix the position of the sticky/closed icon. --- src/General/Build.coffee | 4 +-- src/General/Thread.coffee | 28 +++++++++++++++++++-- src/Miscellaneous/Index.coffee | 5 +++- src/Monitoring/ThreadUpdater.coffee | 39 +++++++++++------------------ 4 files changed, 46 insertions(+), 30 deletions(-) diff --git a/src/General/Build.coffee b/src/General/Build.coffee index b62418e13..8d018b8ee 100644 --- a/src/General/Build.coffee +++ b/src/General/Build.coffee @@ -227,7 +227,7 @@ Build = "" + emailStart + "#{name or ''}" + tripcode + - capcodeStart + emailEnd + capcode + userID + flag + sticky + closed + + capcodeStart + emailEnd + capcode + userID + flag + ' ' + "#{date} " + "" + @@ -238,7 +238,7 @@ Build = else "/#{boardID}/res/#{threadID}#q#{postID}" }' title='Quote this post'>#{postID}" + - replyLink + + sticky + closed + replyLink + '' + '' + diff --git a/src/General/Thread.coffee b/src/General/Thread.coffee index 97502ecd2..e681983e5 100644 --- a/src/General/Thread.coffee +++ b/src/General/Thread.coffee @@ -3,11 +3,35 @@ class Thread toString: -> @ID constructor: (@ID, @board) -> - @fullID = "#{@board}.#{@ID}" - @posts = {} + @fullID = "#{@board}.#{@ID}" + @posts = {} + @isSticky = false + @isClosed = false + @postLimit = false + @fileLimit = false g.threads[@fullID] = board.threads[@] = @ + 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: "//static.4chan.org/image/#{typeLC}.gif" + alt: type + title: type + className: "#{typeLC}Icon" + root = if type is 'Closed' and @isSticky + $ '.stickyIcon', @OP.nodes.info + else + $ '[title="Quote this post"]', @OP.nodes.info + $.after root, [$.tn(' '), icon] + kill: -> @isDead = true @timeOfDeath = Date.now() diff --git a/src/Miscellaneous/Index.coffee b/src/Miscellaneous/Index.coffee index f75754fcf..cdb74fe63 100644 --- a/src/Miscellaneous/Index.coffee +++ b/src/Miscellaneous/Index.coffee @@ -118,7 +118,10 @@ Index = for threadData in Index.liveThreadData threadRoot = Build.thread g.BOARD, threadData Index.nodes.push threadRoot, $.el 'hr' - unless thread = g.BOARD.threads[threadData.no] + if thread = g.BOARD.threads[threadData.no] + thread.setStatus 'Sticky', !!threadData.sticky + thread.setStatus 'Closed', !!threadData.closed + else thread = new Thread threadData.no, g.BOARD threads.push thread postRoots = $$ '.thread > .postContainer', threadRoot diff --git a/src/Monitoring/ThreadUpdater.coffee b/src/Monitoring/ThreadUpdater.coffee index 03c8b5053..8e9c68779 100644 --- a/src/Monitoring/ThreadUpdater.coffee +++ b/src/Monitoring/ThreadUpdater.coffee @@ -155,38 +155,27 @@ ThreadUpdater = , whenModified: true - updateThreadStatus: (title, OP) -> - titleLC = title.toLowerCase() - return if ThreadUpdater.thread["is#{title}"] is !!OP[titleLC] - unless ThreadUpdater.thread["is#{title}"] = !!OP[titleLC] - message = if title is 'Sticky' - 'The thread is not a sticky anymore.' + updateThreadStatus: (type, status) -> + return unless hasChanged = ThreadUpdater.thread["is#{type}"] isnt status + ThreadUpdater.thread.setStatus type, status + change = if type is 'Sticky' + if status + 'now a sticky' else - 'The thread is not closed anymore.' - new Notice 'info', message, 30 - $.rm $ ".#{titleLC}Icon", ThreadUpdater.thread.OP.nodes.info - return - message = if title is 'Sticky' - 'The thread is now a sticky.' + 'not a sticky anymore' else - 'The thread is now closed.' - new Notice 'info', message, 30 - icon = $.el 'img', - src: "//static.4chan.org/image/#{titleLC}.gif" - alt: title - title: title - className: "#{titleLC}Icon" - root = $ '[title="Quote this post"]', ThreadUpdater.thread.OP.nodes.info - if title is 'Closed' - root = $('.stickyIcon', ThreadUpdater.thread.OP.nodes.info) or root - $.after root, [$.tn(' '), icon] + if status + 'now closed' + else + 'not closed anymore' + new Notice 'info', "The thread is #{change}.", 30 parse: (postObjects) -> OP = postObjects[0] Build.spoilerRange[ThreadUpdater.thread.board] = OP.custom_spoiler - ThreadUpdater.updateThreadStatus 'Sticky', OP - ThreadUpdater.updateThreadStatus 'Closed', OP + ThreadUpdater.updateThreadStatus 'Sticky', !!OP.sticky + ThreadUpdater.updateThreadStatus 'Closed', !!OP.closed ThreadUpdater.thread.postLimit = !!OP.bumplimit ThreadUpdater.thread.fileLimit = !!OP.imagelimit