From 779aa10e9c2e5f0a270ea015cdbba09c52a2a01c Mon Sep 17 00:00:00 2001 From: ccd0 Date: Fri, 7 Aug 2015 21:44:36 -0700 Subject: [PATCH] Fix QR.cooldown data not being set up when called from DeleteLink. --- src/General/Main.coffee | 2 ++ src/General/lib/$.coffee | 2 +- src/Posting/QR.coffee | 2 +- src/Posting/QR.cooldown.coffee | 23 +++++++++++++++-------- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/General/Main.coffee b/src/General/Main.coffee index 737dda2ad..71c7c9235 100755 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -51,6 +51,7 @@ Main = for db in DataBoard.keys Conf[db] = boards: {} Conf['selectedArchives'] = {} + Conf['cooldowns'] = {} $.get Conf, (items) -> $.extend Conf, items @@ -338,6 +339,7 @@ Main = ['Recursive', Recursive] ['Strike-through Quotes', QuoteStrikeThrough] ['Quick Reply', QR] + ['Cooldown', QR.cooldown] ['Menu', Menu] ['Index Generator (Menu)', Index.menu] ['Report Link', ReportLink] diff --git a/src/General/lib/$.coffee b/src/General/lib/$.coffee index 3706e0258..7896c412c 100755 --- a/src/General/lib/$.coffee +++ b/src/General/lib/$.coffee @@ -524,7 +524,7 @@ $.clear = (cb) -> # XXX https://github.com/greasemonkey/greasemonkey/issues/2033 # Also support case where GM_listValues is not defined. $.delete Object.keys(Conf) - $.delete ['previousversion', 'AutoWatch', 'cooldowns', 'QR Size', 'captchas', 'QR.persona', 'hiddenPSA'] + $.delete ['previousversion', 'AutoWatch', 'QR Size', 'captchas', 'QR.persona', 'hiddenPSA'] $.delete ("#{id}.position" for id in ['embedding', 'updater', 'thread-stats', 'thread-watcher', 'qr']) try $.delete $.listValues().map (key) -> key.replace g.NAMESPACE, '' diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index be5ef55f9..f9df94c9d 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -565,7 +565,7 @@ QR = QR.persona.init() new QR.post true QR.status() - QR.cooldown.init() + QR.cooldown.setup() QR.captcha.init() $.add d.body, dialog diff --git a/src/Posting/QR.cooldown.coffee b/src/Posting/QR.cooldown.coffee index cadfb43da..699554a95 100644 --- a/src/Posting/QR.cooldown.coffee +++ b/src/Posting/QR.cooldown.coffee @@ -1,7 +1,14 @@ QR.cooldown = seconds: 0 + # Called from Main init: -> + return unless Conf['Quick Reply'] and Conf['Cooldown'] + @data = Conf['cooldowns'] + $.sync 'cooldowns', @sync + + # Called from QR + setup: -> return unless Conf['Cooldown'] # Read cooldown times @@ -18,17 +25,17 @@ QR.cooldown = # There is a 300 second inter-board thread cooldown. QR.cooldown.delays['thread_global'] = 300 - # Retrieve recent posts and delays. - $.get 'cooldowns', {}, ({cooldowns}) -> - QR.cooldown.data = cooldowns - QR.cooldown.start() - $.sync 'cooldowns', QR.cooldown.sync + QR.cooldown.start() start: -> {data} = QR.cooldown - unless QR.cooldown.isCounting or Object.keys(data[g.BOARD.ID] or {}).length + Object.keys(data.global or {}).length is 0 - QR.cooldown.isCounting = true - QR.cooldown.count() + return unless ( + QR.cooldown.delays and + !QR.cooldown.isCounting and + Object.keys(data[g.BOARD.ID] or {}).length + Object.keys(data.global or {}).length > 0 + ) + QR.cooldown.isCounting = true + QR.cooldown.count() sync: (data) -> QR.cooldown.data = data or {}