From 9d58a62e1616e1b721e2577535d2fb45fffa8fe2 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Thu, 18 Sep 2014 11:32:15 -0700 Subject: [PATCH] Archived thread related bugfixes. --- src/General/Config.coffee | 2 +- src/General/Main.coffee | 3 +-- src/General/lib/databoard.class | 24 +++++++++--------------- src/Monitoring/ThreadUpdater.coffee | 11 +++++------ src/Monitoring/ThreadWatcher.coffee | 26 ++++++++++++++------------ src/Monitoring/Unread.coffee | 10 ++++++++-- src/Posting/QR.coffee | 4 +++- 7 files changed, 41 insertions(+), 39 deletions(-) diff --git a/src/General/Config.coffee b/src/General/Config.coffee index 3d68cfd1c..45408e983 100755 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -476,7 +476,7 @@ Config = ] 'Auto Prune': [ false - 'Automatically prune 404\'d threads.' + 'Automatically prune dead threads.' ] 'Show Unread Count': [ true diff --git a/src/General/Main.coffee b/src/General/Main.coffee index 932fac15e..5d1f6fe74 100755 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -160,14 +160,13 @@ Main = new Notice 'warning', 'Cookies need to be enabled on 4chan for <%= meta.name %> to operate properly.', 30 initThread: -> - g.DEAD = !!$('.closed')?.textContent.match(/Thread archived/) - if board = $ '.board' threads = [] posts = [] for threadRoot in $$ '.board > .thread', board thread = new Thread +threadRoot.id[1..], g.BOARD + thread.isDead = thread.isArchived = !!$('.closed')?.textContent.match(/Thread archived/) if g.VIEW is 'thread' threads.push thread for postRoot in $$ '.thread > .postContainer', threadRoot try diff --git a/src/General/lib/databoard.class b/src/General/lib/databoard.class index 2ae081d56..3545b5469 100755 --- a/src/General/lib/databoard.class +++ b/src/General/lib/databoard.class @@ -70,23 +70,17 @@ class DataBoard if (@data.lastChecked or 0) < now - 2 * $.HOUR @data.lastChecked = now for boardID of @data.boards - @ajaxClean boardID + for threadID of @data.boards[boardID] + @ajaxClean boardID, threadID @save() - ajaxClean: (boardID) -> - $.cache "//a.4cdn.org/#{boardID}/threads.json", (e) => - if e.target.status isnt 200 - @delete {boardID} if e.target.status is 404 - return - board = @data.boards[boardID] - threads = {} - for page in e.target.response - for thread in page.threads - if thread.no of board - threads[thread.no] = board[thread.no] - @data.boards[boardID] = threads - @deleteIfEmpty {boardID} - @save() + ajaxClean: (boardID, threadID) -> + $.ajax "//a.4cdn.org/#{boardID}/thread/#{threadID}.json", + onloadend: (e) => + if e.target.status is 404 + @delete {boardID, threadID} + , + type: 'head' onSync: (data) => @data = data or boards: {} diff --git a/src/Monitoring/ThreadUpdater.coffee b/src/Monitoring/ThreadUpdater.coffee index eb5ca6764..5130262c4 100755 --- a/src/Monitoring/ThreadUpdater.coffee +++ b/src/Monitoring/ThreadUpdater.coffee @@ -74,7 +74,7 @@ ThreadUpdater = $.on d, 'QRPostSuccessful', ThreadUpdater.cb.checkpost $.on d, 'visibilitychange', ThreadUpdater.cb.visibility - if g.DEAD + if ThreadUpdater.thread.isArchived ThreadUpdater.set 'status', 'Archived', 'warning' else ThreadUpdater.cb.online() @@ -87,7 +87,7 @@ ThreadUpdater = cb: online: -> - return if g.DEAD + return if ThreadUpdater.thread.isDead if ThreadUpdater.online = navigator.onLine ThreadUpdater.outdateCount = 0 ThreadUpdater.setInterval() @@ -105,7 +105,7 @@ ThreadUpdater = ThreadUpdater.seconds = 0 ThreadUpdater.outdateCount = 0 ThreadUpdater.set 'timer', '...' - unless g.DEAD or ThreadUpdater.foundPost or ThreadUpdater.checkPostCount >= 5 + unless ThreadUpdater.thread.isDead or ThreadUpdater.foundPost or ThreadUpdater.checkPostCount >= 5 return setTimeout ThreadUpdater.update, ++ThreadUpdater.checkPostCount * $.SECOND ThreadUpdater.setInterval() ThreadUpdater.checkPostCount = 0 @@ -131,9 +131,9 @@ ThreadUpdater = {req} = ThreadUpdater switch req.status when 200 - g.DEAD = !!+req.response.posts[0].archived ThreadUpdater.parse req.response.posts - if g.DEAD + if !!req.response.posts[0].archived + ThreadUpdater.thread.isArchived = true ThreadUpdater.set 'status', 'Archived', 'warning' ThreadUpdater.kill() else @@ -151,7 +151,6 @@ ThreadUpdater = else confirmed = false if confirmed - g.DEAD = true ThreadUpdater.set 'status', '404', 'warning' ThreadUpdater.kill() else diff --git a/src/Monitoring/ThreadWatcher.coffee b/src/Monitoring/ThreadWatcher.coffee index b9d8ccebb..596e118dc 100755 --- a/src/Monitoring/ThreadWatcher.coffee +++ b/src/Monitoring/ThreadWatcher.coffee @@ -102,13 +102,12 @@ ThreadWatcher = ThreadWatcher.db.delete {boardID, threadID} else data.isDead = true - delete data.unread ThreadWatcher.db.set {boardID, threadID, val: data} ThreadWatcher.refresh() onThreadRefresh: (e) -> thread = g.threads[e.detail.threadID] return unless e.detail[404] and ThreadWatcher.db.get {boardID: thread.board.ID, threadID: thread.ID} - # Update 404 status. + # Update dead status. ThreadWatcher.add thread fetchCount: @@ -120,7 +119,7 @@ ThreadWatcher = ThreadWatcher.fetchStatus thread return fetchStatus: ({boardID, threadID, data}) -> - return if data.isDead + return if data.isDead and !Conf['Show Unread Count'] {fetchCount} = ThreadWatcher if fetchCount.fetching is 0 ThreadWatcher.status.textContent = '...' @@ -139,6 +138,12 @@ ThreadWatcher = ThreadWatcher.status.textContent = status if @status is 200 and @response + isDead = !!@response.posts[0].archived + if isDead and Conf['Auto Prune'] + ThreadWatcher.db.delete {boardID, threadID} + ThreadWatcher.refresh() + return + lastReadPost = ThreadWatcher.unreaddb.get boardID: boardID threadID: threadID @@ -150,7 +155,8 @@ ThreadWatcher = if postObj.no > lastReadPost and !QR.db?.get {boardID, threadID, postID: postObj.no} unread++ - if unread isnt data.unread + if isDead isnt data.isDead or unread isnt data.unread + data.isDead = isDead data.unread = unread ThreadWatcher.db.set {boardID, threadID, val: data} ThreadWatcher.refresh() @@ -163,8 +169,6 @@ ThreadWatcher = delete data.unread ThreadWatcher.db.set {boardID, threadID, val: data} ThreadWatcher.refresh() - , - type: if Conf['Show Unread Count'] then 'get' else 'head' getAll: -> all = [] @@ -189,10 +193,8 @@ ThreadWatcher = textContent: if Conf['Show Unread Count'] and data.unread? then "\u00A0(#{data.unread})" else '' className: 'watcher-unread' - if Conf['404 Redirect'] and data.isDead - href = Redirect.to 'thread', {boardID, threadID} link = $.el 'a', - href: href or "/#{boardID}/thread/#{threadID}" + href: "/#{boardID}/thread/#{threadID}" title: data.excerpt className: 'watcher-link' $.add link, [title, count] @@ -245,7 +247,7 @@ ThreadWatcher = data.excerpt = Get.threadExcerpt thread ThreadWatcher.db.set {boardID, threadID, val: data} ThreadWatcher.refresh() - if Conf['Show Unread Count'] and !data.isDead + if Conf['Show Unread Count'] ThreadWatcher.fetchStatus {boardID, threadID, data} rm: (boardID, threadID) -> ThreadWatcher.db.delete {boardID, threadID} @@ -296,12 +298,12 @@ ThreadWatcher = textContent: 'Open all threads' refresh: -> (if ThreadWatcher.list.firstElementChild then $.rmClass else $.addClass) @el, 'disabled' - # `Prune 404'd threads` entry + # `Prune dead threads` entry entries.push cb: ThreadWatcher.cb.pruneDeads entry: el: $.el 'a', - textContent: 'Prune 404\'d threads' + textContent: 'Prune dead threads' refresh: -> (if $('.dead-thread', ThreadWatcher.list) then $.rmClass else $.addClass) @el, 'disabled' # `Settings` entries: diff --git a/src/Monitoring/Unread.coffee b/src/Monitoring/Unread.coffee index 5dc497441..96f82388a 100755 --- a/src/Monitoring/Unread.coffee +++ b/src/Monitoring/Unread.coffee @@ -180,12 +180,18 @@ Unread = countQuotingYou = Object.keys(Unread.postsQuotingYou).length if Conf['Unread Count'] - d.title = "#{if Conf['Quoted Title'] and countQuotingYou then '(!) ' else ''}#{if count or !Conf['Hide Unread Count at (0)'] then "(#{count}) " else ''}#{if g.DEAD then Unread.title.replace '-', '- 404 -' else Unread.title}" + titleQuotingYou = if Conf['Quoted Title'] and countQuotingYou then '(!) ' else '' + titleCount = if count or !Conf['Hide Unread Count at (0)'] then "(#{count}) " else '' + titleDead = if Unread.thread.isDead + Unread.title.replace '-', (if Unread.thread.isArchived then '- Archived -' else '- 404 -') + else + Unread.title + d.title = "#{titleQuotingYou}#{titleCount}#{titleDead}" return unless Conf['Unread Favicon'] Favicon.el.href = - if g.DEAD + if Unread.thread.isDead if countQuotingYou Favicon.unreadDeadY else if count diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index 453dfcda9..cd88b1503 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -80,7 +80,9 @@ QR = QR.hide() if Conf['Auto-Hide QR'] statusCheck: -> - if g.DEAD + return unless QR.nodes + {thread} = QR.posts[0] + if thread isnt 'new' and g.threads["#{g.BOARD}.#{thread}"].isDead QR.abort() else QR.status()