Archived thread related bugfixes.

This commit is contained in:
ccd0 2014-09-18 11:32:15 -07:00
parent a197748ab9
commit 9d58a62e16
7 changed files with 41 additions and 39 deletions

View File

@ -476,7 +476,7 @@ Config =
] ]
'Auto Prune': [ 'Auto Prune': [
false false
'Automatically prune 404\'d threads.' 'Automatically prune dead threads.'
] ]
'Show Unread Count': [ 'Show Unread Count': [
true true

View File

@ -160,14 +160,13 @@ Main =
new Notice 'warning', 'Cookies need to be enabled on 4chan for <%= meta.name %> to operate properly.', 30 new Notice 'warning', 'Cookies need to be enabled on 4chan for <%= meta.name %> to operate properly.', 30
initThread: -> initThread: ->
g.DEAD = !!$('.closed')?.textContent.match(/Thread archived/)
if board = $ '.board' if board = $ '.board'
threads = [] threads = []
posts = [] posts = []
for threadRoot in $$ '.board > .thread', board for threadRoot in $$ '.board > .thread', board
thread = new Thread +threadRoot.id[1..], g.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 threads.push thread
for postRoot in $$ '.thread > .postContainer', threadRoot for postRoot in $$ '.thread > .postContainer', threadRoot
try try

View File

@ -70,23 +70,17 @@ class DataBoard
if (@data.lastChecked or 0) < now - 2 * $.HOUR if (@data.lastChecked or 0) < now - 2 * $.HOUR
@data.lastChecked = now @data.lastChecked = now
for boardID of @data.boards for boardID of @data.boards
@ajaxClean boardID for threadID of @data.boards[boardID]
@ajaxClean boardID, threadID
@save() @save()
ajaxClean: (boardID) -> ajaxClean: (boardID, threadID) ->
$.cache "//a.4cdn.org/#{boardID}/threads.json", (e) => $.ajax "//a.4cdn.org/#{boardID}/thread/#{threadID}.json",
if e.target.status isnt 200 onloadend: (e) =>
@delete {boardID} if e.target.status is 404 if e.target.status is 404
return @delete {boardID, threadID}
board = @data.boards[boardID] ,
threads = {} type: 'head'
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()
onSync: (data) => onSync: (data) =>
@data = data or boards: {} @data = data or boards: {}

View File

@ -74,7 +74,7 @@ ThreadUpdater =
$.on d, 'QRPostSuccessful', ThreadUpdater.cb.checkpost $.on d, 'QRPostSuccessful', ThreadUpdater.cb.checkpost
$.on d, 'visibilitychange', ThreadUpdater.cb.visibility $.on d, 'visibilitychange', ThreadUpdater.cb.visibility
if g.DEAD if ThreadUpdater.thread.isArchived
ThreadUpdater.set 'status', 'Archived', 'warning' ThreadUpdater.set 'status', 'Archived', 'warning'
else else
ThreadUpdater.cb.online() ThreadUpdater.cb.online()
@ -87,7 +87,7 @@ ThreadUpdater =
cb: cb:
online: -> online: ->
return if g.DEAD return if ThreadUpdater.thread.isDead
if ThreadUpdater.online = navigator.onLine if ThreadUpdater.online = navigator.onLine
ThreadUpdater.outdateCount = 0 ThreadUpdater.outdateCount = 0
ThreadUpdater.setInterval() ThreadUpdater.setInterval()
@ -105,7 +105,7 @@ ThreadUpdater =
ThreadUpdater.seconds = 0 ThreadUpdater.seconds = 0
ThreadUpdater.outdateCount = 0 ThreadUpdater.outdateCount = 0
ThreadUpdater.set 'timer', '...' 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 return setTimeout ThreadUpdater.update, ++ThreadUpdater.checkPostCount * $.SECOND
ThreadUpdater.setInterval() ThreadUpdater.setInterval()
ThreadUpdater.checkPostCount = 0 ThreadUpdater.checkPostCount = 0
@ -131,9 +131,9 @@ ThreadUpdater =
{req} = ThreadUpdater {req} = ThreadUpdater
switch req.status switch req.status
when 200 when 200
g.DEAD = !!+req.response.posts[0].archived
ThreadUpdater.parse req.response.posts ThreadUpdater.parse req.response.posts
if g.DEAD if !!req.response.posts[0].archived
ThreadUpdater.thread.isArchived = true
ThreadUpdater.set 'status', 'Archived', 'warning' ThreadUpdater.set 'status', 'Archived', 'warning'
ThreadUpdater.kill() ThreadUpdater.kill()
else else
@ -151,7 +151,6 @@ ThreadUpdater =
else else
confirmed = false confirmed = false
if confirmed if confirmed
g.DEAD = true
ThreadUpdater.set 'status', '404', 'warning' ThreadUpdater.set 'status', '404', 'warning'
ThreadUpdater.kill() ThreadUpdater.kill()
else else

View File

@ -102,13 +102,12 @@ ThreadWatcher =
ThreadWatcher.db.delete {boardID, threadID} ThreadWatcher.db.delete {boardID, threadID}
else else
data.isDead = true data.isDead = true
delete data.unread
ThreadWatcher.db.set {boardID, threadID, val: data} ThreadWatcher.db.set {boardID, threadID, val: data}
ThreadWatcher.refresh() ThreadWatcher.refresh()
onThreadRefresh: (e) -> onThreadRefresh: (e) ->
thread = g.threads[e.detail.threadID] thread = g.threads[e.detail.threadID]
return unless e.detail[404] and ThreadWatcher.db.get {boardID: thread.board.ID, threadID: thread.ID} 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 ThreadWatcher.add thread
fetchCount: fetchCount:
@ -120,7 +119,7 @@ ThreadWatcher =
ThreadWatcher.fetchStatus thread ThreadWatcher.fetchStatus thread
return return
fetchStatus: ({boardID, threadID, data}) -> fetchStatus: ({boardID, threadID, data}) ->
return if data.isDead return if data.isDead and !Conf['Show Unread Count']
{fetchCount} = ThreadWatcher {fetchCount} = ThreadWatcher
if fetchCount.fetching is 0 if fetchCount.fetching is 0
ThreadWatcher.status.textContent = '...' ThreadWatcher.status.textContent = '...'
@ -139,6 +138,12 @@ ThreadWatcher =
ThreadWatcher.status.textContent = status ThreadWatcher.status.textContent = status
if @status is 200 and @response 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 lastReadPost = ThreadWatcher.unreaddb.get
boardID: boardID boardID: boardID
threadID: threadID threadID: threadID
@ -150,7 +155,8 @@ ThreadWatcher =
if postObj.no > lastReadPost and !QR.db?.get {boardID, threadID, postID: postObj.no} if postObj.no > lastReadPost and !QR.db?.get {boardID, threadID, postID: postObj.no}
unread++ unread++
if unread isnt data.unread if isDead isnt data.isDead or unread isnt data.unread
data.isDead = isDead
data.unread = unread data.unread = unread
ThreadWatcher.db.set {boardID, threadID, val: data} ThreadWatcher.db.set {boardID, threadID, val: data}
ThreadWatcher.refresh() ThreadWatcher.refresh()
@ -163,8 +169,6 @@ ThreadWatcher =
delete data.unread delete data.unread
ThreadWatcher.db.set {boardID, threadID, val: data} ThreadWatcher.db.set {boardID, threadID, val: data}
ThreadWatcher.refresh() ThreadWatcher.refresh()
,
type: if Conf['Show Unread Count'] then 'get' else 'head'
getAll: -> getAll: ->
all = [] all = []
@ -189,10 +193,8 @@ ThreadWatcher =
textContent: if Conf['Show Unread Count'] and data.unread? then "\u00A0(#{data.unread})" else '' textContent: if Conf['Show Unread Count'] and data.unread? then "\u00A0(#{data.unread})" else ''
className: 'watcher-unread' className: 'watcher-unread'
if Conf['404 Redirect'] and data.isDead
href = Redirect.to 'thread', {boardID, threadID}
link = $.el 'a', link = $.el 'a',
href: href or "/#{boardID}/thread/#{threadID}" href: "/#{boardID}/thread/#{threadID}"
title: data.excerpt title: data.excerpt
className: 'watcher-link' className: 'watcher-link'
$.add link, [title, count] $.add link, [title, count]
@ -245,7 +247,7 @@ ThreadWatcher =
data.excerpt = Get.threadExcerpt thread data.excerpt = Get.threadExcerpt thread
ThreadWatcher.db.set {boardID, threadID, val: data} ThreadWatcher.db.set {boardID, threadID, val: data}
ThreadWatcher.refresh() ThreadWatcher.refresh()
if Conf['Show Unread Count'] and !data.isDead if Conf['Show Unread Count']
ThreadWatcher.fetchStatus {boardID, threadID, data} ThreadWatcher.fetchStatus {boardID, threadID, data}
rm: (boardID, threadID) -> rm: (boardID, threadID) ->
ThreadWatcher.db.delete {boardID, threadID} ThreadWatcher.db.delete {boardID, threadID}
@ -296,12 +298,12 @@ ThreadWatcher =
textContent: 'Open all threads' textContent: 'Open all threads'
refresh: -> (if ThreadWatcher.list.firstElementChild then $.rmClass else $.addClass) @el, 'disabled' refresh: -> (if ThreadWatcher.list.firstElementChild then $.rmClass else $.addClass) @el, 'disabled'
# `Prune 404'd threads` entry # `Prune dead threads` entry
entries.push entries.push
cb: ThreadWatcher.cb.pruneDeads cb: ThreadWatcher.cb.pruneDeads
entry: entry:
el: $.el 'a', el: $.el 'a',
textContent: 'Prune 404\'d threads' textContent: 'Prune dead threads'
refresh: -> (if $('.dead-thread', ThreadWatcher.list) then $.rmClass else $.addClass) @el, 'disabled' refresh: -> (if $('.dead-thread', ThreadWatcher.list) then $.rmClass else $.addClass) @el, 'disabled'
# `Settings` entries: # `Settings` entries:

View File

@ -180,12 +180,18 @@ Unread =
countQuotingYou = Object.keys(Unread.postsQuotingYou).length countQuotingYou = Object.keys(Unread.postsQuotingYou).length
if Conf['Unread Count'] 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'] return unless Conf['Unread Favicon']
Favicon.el.href = Favicon.el.href =
if g.DEAD if Unread.thread.isDead
if countQuotingYou if countQuotingYou
Favicon.unreadDeadY Favicon.unreadDeadY
else if count else if count

View File

@ -80,7 +80,9 @@ QR =
QR.hide() if Conf['Auto-Hide QR'] QR.hide() if Conf['Auto-Hide QR']
statusCheck: -> 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() QR.abort()
else else
QR.status() QR.status()