From a6f78ad1ec3634d0beb05ad3a544d9fad78a3575 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Tue, 6 Jul 2021 23:16:35 -0700 Subject: [PATCH] Fix bug causing captcha to sometimes not work when replying from index. --- src/Posting/Captcha.t.coffee | 20 +++++++++++++++++--- src/Posting/QR.post.coffee | 3 +++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Posting/Captcha.t.coffee b/src/Posting/Captcha.t.coffee index cb22951c2..954b23fd7 100644 --- a/src/Posting/Captcha.t.coffee +++ b/src/Posting/Captcha.t.coffee @@ -12,14 +12,21 @@ Captcha.t = moreNeeded: -> return + getThread: -> + boardID = g.BOARD.ID + if QR.posts[0].thread is 'new' + threadID = '0' + else + threadID = '' + QR.posts[0].thread + {boardID, threadID} + setup: (focus) -> return unless @isEnabled if !@nodes.container @nodes.container = $.el 'div', className: 'captcha-container' $.prepend @nodes.root, @nodes.container - boardID = g.BOARD.ID - threadID = '' + QR.posts[0].thread + Captcha.t.currentThread = Captcha.t.getThread() $.global -> el = document.querySelector '#qr .captcha-container' window.TCaptcha.init el, @boardID, +@threadID @@ -28,7 +35,7 @@ Captcha.t = type: 'warning', content: '' + err }}) - , {boardID, threadID} + , Captcha.t.currentThread if focus $('#t-resp').focus() @@ -40,6 +47,13 @@ Captcha.t = $.rm @nodes.container delete @nodes.container + updateThread: -> + {boardID, threadID} = Captcha.t.currentThread + newThread = Captcha.t.getThread() + unless newThread.boardID is boardID and newThread.threadID is threadID + Captcha.t.destroy() + Captcha.t.setup() + getOne: -> response = {} if @nodes.container diff --git a/src/Posting/QR.post.coffee b/src/Posting/QR.post.coffee index 304a9e2c8..a658a82a2 100644 --- a/src/Posting/QR.post.coffee +++ b/src/Posting/QR.post.coffee @@ -74,6 +74,7 @@ QR.post = class (QR.posts[index-1] or QR.posts[index+1]).select() QR.posts.splice index, 1 QR.status() + QR.captcha.updateThread?() delete: -> $.rm @nodes.el @@ -129,6 +130,7 @@ QR.post = class when 'thread' (if @thread isnt 'new' then $.addClass else $.rmClass) QR.nodes.el, 'reply-to-thread' QR.status() + QR.captcha.updateThread?() when 'com' @updateComment() when 'filename' @@ -403,3 +405,4 @@ QR.post = class post = QR.posts.splice(oldIndex, 1)[0] QR.posts.splice newIndex, 0, post QR.status() + QR.captcha.updateThread?()