From c399eff09ebc1faaf46a177f8824de0fd538ebfa Mon Sep 17 00:00:00 2001 From: ccd0 Date: Fri, 7 Aug 2015 23:10:34 -0700 Subject: [PATCH] Integrate Delete Link cooldown with QR cooldown. This fixes the 4chan v. local time discrepancy problem causing autodelete to fail. --- src/Menu/DeleteLink.coffee | 7 ++----- src/Posting/QR.cooldown.coffee | 27 +++++++++++++++++++-------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/Menu/DeleteLink.coffee b/src/Menu/DeleteLink.coffee index 923801ef9..6cc4e3b3f 100755 --- a/src/Menu/DeleteLink.coffee +++ b/src/Menu/DeleteLink.coffee @@ -111,12 +111,9 @@ DeleteLink = start: (post, node) -> # Already counting. return if DeleteLink.cooldown.seconds[post.fullID]? - # Only start counting on our posts. - return unless QR.db?.get {boardID: post.board.ID, threadID: post.thread.ID, postID: post.ID} - length = 60 - seconds = length - (Date.now() - post.info.date) // $.SECOND - if 0 < seconds <= length + seconds = QR.cooldown.secondsDeletion post + if seconds > 0 DeleteLink.cooldown.seconds[post.fullID] = seconds DeleteLink.cooldown.count post, node diff --git a/src/Posting/QR.cooldown.coffee b/src/Posting/QR.cooldown.coffee index 699554a95..1b21b129b 100644 --- a/src/Posting/QR.cooldown.coffee +++ b/src/Posting/QR.cooldown.coffee @@ -1,5 +1,13 @@ QR.cooldown = seconds: 0 + delays: + thread: 0 + reply: 0 + image: 0 + reply_intra: 0 + image_intra: 0 + deletion: 60 # cooldown for deleting posts/files + thread_global: 300 # inter-board thread cooldown # Called from Main init: -> @@ -12,19 +20,14 @@ QR.cooldown = return unless Conf['Cooldown'] # Read cooldown times - QR.cooldown.delays = if m = Get.scriptData().match /\bcooldowns *= *({[^}]+})/ - JSON.parse m[1] - else - {thread: 0, reply: 0, image: 0, reply_intra: 0, image_intra: 0} + if m = Get.scriptData().match /\bcooldowns *= *({[^}]+})/ + $.extend QR.cooldown.delays, JSON.parse m[1] # The longest reply cooldown, for use in pruning old reply data QR.cooldown.maxDelay = 0 - for type, delay of QR.cooldown.delays when type isnt 'thread' + for type, delay of QR.cooldown.delays when type not in ['thread', 'thread_global'] QR.cooldown.maxDelay = Math.max QR.cooldown.maxDelay, delay - # There is a 300 second inter-board thread cooldown. - QR.cooldown.delays['thread_global'] = 300 - QR.cooldown.start() start: -> @@ -64,6 +67,14 @@ QR.cooldown = delete cooldowns[id] QR.cooldown.save [post.board.ID] + secondsDeletion: (post) -> + cooldowns = QR.cooldown.data[post.board.ID] or {} + for start, cooldown of cooldowns + if !cooldown.delay? and cooldown.threadID is post.thread.ID and cooldown.postID is post.ID + seconds = QR.cooldown.delays.deletion - (Date.now() - start) // $.SECOND + return Math.max seconds, 0 + 0 + categorize: (post) -> if post.thread is 'new' type: 'thread'