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': [
false
'Automatically prune 404\'d threads.'
'Automatically prune dead threads.'
]
'Show Unread Count': [
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
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

View File

@ -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: {}

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -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()