From 1f9546cc035a5a9c3d154241fc1f3e11f4c9cc26 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sun, 17 Mar 2013 14:44:41 -0700 Subject: [PATCH] Added functionality to update thread until (your) post is found. --- 4chan_x.user.js | 22 ++++++++++++++++++++-- src/features.coffee | 16 +++++++++++++++- src/qr.coffee | 2 ++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index b2c049429..6ed35aaf3 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -5575,6 +5575,7 @@ this.dialog = UI.dialog('updater', 'bottom: 0; right: 0;', html); this.timer = $('#update-timer', this.dialog); this.status = $('#update-status', this.dialog); + this.checkPostCount = 0; return Thread.prototype.callbacks.push({ name: 'Thread Updater', cb: this.node @@ -5646,6 +5647,14 @@ return setTimeout(ThreadUpdater.update, 1000); } }, + checkpost: function() { + if (!(g.DEAD || ThreadUpdater.foundPost || ThreadUpdater.checkPostCount >= 10)) { + return setTimeout(ThreadUpdater.update, ++ThreadUpdater.checkPostCount * 500); + } + ThreadUpdater.checkPostCount = 0; + delete ThreadUpdater.foundPost; + return delete ThreadUpdater.postID; + }, visibility: function() { if (d.hidden) { return; @@ -5676,7 +5685,7 @@ return $.cb.value.call(this); }, load: function() { - var klass, req, text, _ref, _ref1; + var klass, req, text, _ref; req = ThreadUpdater.req; switch (req.status) { case 200: @@ -5705,9 +5714,12 @@ This saves bandwidth for both the user and the servers and avoid unnecessary computation. */ - _ref1 = (_ref = req.status) === 0 || _ref === 304 ? [null, null] : ["" + req.statusText + " (" + req.status + ")", 'warning'], text = _ref1[0], klass = _ref1[1]; + _ref = [0, 304].contains(req.status) ? [null, null] : ["" + req.statusText + " (" + req.status + ")", 'warning'], text = _ref[0], klass = _ref[1]; ThreadUpdater.set('status', text, klass); } + if (ThreadUpdater.postID) { + ThreadUpdater.cb.checkpost(this.status); + } return delete ThreadUpdater.req; } }, @@ -5831,6 +5843,11 @@ post.kill(true); deletedFiles.push(post); } + if (ThreadUpdater.postID) { + if (ID === ThreadUpdater.postID) { + ThreadUpdater.foundPost = true; + } + } } if (!count) { ThreadUpdater.set('status', null, null); @@ -7391,6 +7408,7 @@ threadID = +threadID || postID; ((_base = QR.yourPosts.threads)[threadID] || (_base[threadID] = [])).push(postID); $.set("yourPosts." + g.BOARD, QR.yourPosts); + ThreadUpdater.postID = postID; $.event('QRPostSuccessful', { board: g.BOARD, threadID: threadID, diff --git a/src/features.coffee b/src/features.coffee index ae35a1fcc..665e07294 100644 --- a/src/features.coffee +++ b/src/features.coffee @@ -3737,6 +3737,7 @@ ThreadUpdater = @dialog = UI.dialog 'updater', 'bottom: 0; right: 0;', html @timer = $ '#update-timer', @dialog @status = $ '#update-status', @dialog + @checkPostCount = 0 Thread::callbacks.push name: 'Thread Updater' @@ -3793,6 +3794,12 @@ ThreadUpdater = return unless Conf['Auto Update This'] and e.detail.threadID is ThreadUpdater.thread.ID ThreadUpdater.outdateCount = 0 setTimeout ThreadUpdater.update, 1000 if ThreadUpdater.seconds > 2 + checkpost: -> + unless g.DEAD or ThreadUpdater.foundPost or ThreadUpdater.checkPostCount >= 10 + return setTimeout ThreadUpdater.update, ++ThreadUpdater.checkPostCount * 500 + ThreadUpdater.checkPostCount = 0 + delete ThreadUpdater.foundPost + delete ThreadUpdater.postID visibility: -> return if d.hidden # Reset the counter when we focus this tab. @@ -3839,11 +3846,15 @@ ThreadUpdater = This saves bandwidth for both the user and the servers and avoid unnecessary computation. ### # XXX 304 -> 0 in Opera - [text, klass] = if req.status in [0, 304] + [text, klass] = if [0, 304].contains req.status [null, null] else ["#{req.statusText} (#{req.status})", 'warning'] ThreadUpdater.set 'status', text, klass + + if ThreadUpdater.postID + ThreadUpdater.cb.checkpost @status + delete ThreadUpdater.req getInterval: -> @@ -3956,6 +3967,9 @@ ThreadUpdater = else if post.file and !post.file.isDead and not files.contains ID post.kill true deletedFiles.push post + if ThreadUpdater.postID + if ID is ThreadUpdater.postID + ThreadUpdater.foundPost = true unless count ThreadUpdater.set 'status', null, null diff --git a/src/qr.coffee b/src/qr.coffee index 1bffbfe22..fca6fa181 100644 --- a/src/qr.coffee +++ b/src/qr.coffee @@ -968,6 +968,8 @@ QR = (QR.yourPosts.threads[threadID] or= []).push postID $.set "yourPosts.#{g.BOARD}", QR.yourPosts + + ThreadUpdater.postID = postID # Post/upload confirmed as successful. $.event 'QRPostSuccessful', {