Get Unread Count working in Thread Watcher.

This commit is contained in:
Zixaphir 2015-01-14 11:28:19 -07:00
parent 6163ac3910
commit 905a946a1e
6 changed files with 46 additions and 32 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -872,6 +872,10 @@ Config =
false false
'Automatically remove dead threads.' 'Automatically remove dead threads.'
] ]
'Show Unread Count': [
true
'Show number of unread posts in watched threads.'
]
filter: filter:
name: """ name: """

View File

@ -1,10 +1,10 @@
Get = Get =
threadExcerpt: (thread) -> threadExcerpt: (thread) ->
{OP} = thread {OP} = thread
excerpt = "/#{thread.board}/ - " + ( excerpt =
OP.info.subject?.trim() or OP.info.subject?.trim() or
OP.info.comment.replace(/\n+/g, ' // ') or OP.info.comment.replace(/\n+/g, ' // ') or
OP.info.nameBlock) OP.info.nameBlock
if excerpt.length > 70 if excerpt.length > 70
excerpt = "#{excerpt[...67]}..." excerpt = "#{excerpt[...67]}..."
"/#{thread.board}/ - #{excerpt}" "/#{thread.board}/ - #{excerpt}"

View File

@ -1149,6 +1149,7 @@ nav a,
.slideout-watcher #thread-watcher { .slideout-watcher #thread-watcher {
display: none; display: none;
overflow-y: auto; overflow-y: auto;
text-align: left;
} }
.watch-thread-link { .watch-thread-link {
padding-top: 18px; padding-top: 18px;

View File

@ -142,6 +142,7 @@ ThreadWatcher =
fetchCount: fetchCount:
fetched: 0 fetched: 0
fetching: 0 fetching: 0
fetchAuto: -> fetchAuto: ->
clearTimeout ThreadWatcher.timeout clearTimeout ThreadWatcher.timeout
return unless Conf['Auto Update Thread Watcher'] return unless Conf['Auto Update Thread Watcher']
@ -153,6 +154,7 @@ ThreadWatcher =
ThreadWatcher.fetchAllStatus() ThreadWatcher.fetchAllStatus()
db.save() db.save()
ThreadWatcher.timeout = setTimeout ThreadWatcher.fetchAuto, interval ThreadWatcher.timeout = setTimeout ThreadWatcher.fetchAuto, interval
fetchAllStatus: -> fetchAllStatus: ->
ThreadWatcher.db.forceSync() ThreadWatcher.db.forceSync()
ThreadWatcher.unreaddb.forceSync() ThreadWatcher.unreaddb.forceSync()
@ -161,6 +163,7 @@ ThreadWatcher =
for thread in threads for thread in threads
ThreadWatcher.fetchStatus thread ThreadWatcher.fetchStatus thread
return return
fetchStatus: (thread) -> fetchStatus: (thread) ->
{boardID, threadID, data} = thread {boardID, threadID, data} = thread
return if data.isDead and !Conf['Show Unread Count'] return if data.isDead and !Conf['Show Unread Count']
@ -174,6 +177,7 @@ ThreadWatcher =
ThreadWatcher.parseStatus.call @, thread ThreadWatcher.parseStatus.call @, thread
parseStatus: ({boardID, threadID, data}) -> parseStatus: ({boardID, threadID, data}) ->
{fetchCount} = ThreadWatcher
fetchCount.fetched++ fetchCount.fetched++
if fetchCount.fetched is fetchCount.fetching if fetchCount.fetched is fetchCount.fetching
fetchCount.fetched = 0 fetchCount.fetched = 0
@ -200,9 +204,9 @@ ThreadWatcher =
for postObj in @response.posts for postObj in @response.posts
continue unless postObj.no > lastReadPost continue unless postObj.no > lastReadPost
continue if QR.db?.get {boardID, threadID, postID: postObj.no} continue if QR.db.get {boardID, threadID, postID: postObj.no}
unread++ unread++
continue unless QR.db and postObj.com continue unless postObj.com
regexp = /<a [^>]*\bhref="(?:\/([^\/]+)\/thread\/(\d+))?(?:#p(\d+))?"/g regexp = /<a [^>]*\bhref="(?:\/([^\/]+)\/thread\/(\d+))?(?:#p(\d+))?"/g
while match = regexp.exec postObj.com while match = regexp.exec postObj.com
if QR.db.get { if QR.db.get {
@ -228,6 +232,7 @@ ThreadWatcher =
delete data.unread delete data.unread
delete data.quotingYou delete data.quotingYou
ThreadWatcher.db.set {boardID, threadID, val: data} ThreadWatcher.db.set {boardID, threadID, val: data}
ThreadWatcher.refresh() ThreadWatcher.refresh()
getAll: -> getAll: ->
@ -254,20 +259,20 @@ ThreadWatcher =
if Conf['Show Unread Count'] and data.unread? if Conf['Show Unread Count'] and data.unread?
count = $.el 'span', count = $.el 'span',
textContent: "(#{data.unread})" textContent: "(#{data.unread}) "
className: 'watcher-unread' className: 'watcher-unread'
$.add link, count $.prepend link, count
title = $.el 'span', title = $.el 'span',
textContent: data.excerpt textContent: link.textContent
className: 'watcher-title' className: 'watcher-title'
$.add link, title $.add link, title
div = $.el 'div' div = $.el 'div'
fullID = "#{boardID}.#{threadID}" fullID = "#{boardID}.#{threadID}"
div.dataset.fullID = fullID div.dataset.fullID = fullID
$.addClass div, 'current' if g.VIEW is 'thread' and fullID is "#{g.BOARD}.#{g.THREADID}" $.addClass div, 'current' if g.VIEW is 'thread' and fullID is "#{g.BOARD}.#{g.THREADID}"
$.addClass div, 'dead-thread' if data.isDead $.addClass div, 'dead-thread' if data.isDead
if Conf['Show Unread Count'] if Conf['Show Unread Count']
$.addClass div, 'replies-unread' if data.unread $.addClass div, 'replies-unread' if data.unread
$.addClass div, 'replies-quoting-you' if data.quotingYou $.addClass div, 'replies-quoting-you' if data.quotingYou
@ -368,7 +373,7 @@ ThreadWatcher =
$.on $('.menu-button', ThreadWatcher.dialog), 'click', (e) -> $.on $('.menu-button', ThreadWatcher.dialog), 'click', (e) ->
menu.toggle e, @, ThreadWatcher menu.toggle e, @, ThreadWatcher
@addHeaderMenuEntry() @addHeaderMenuEntry()
@addMenuEntries @addMenuEntries()
addHeaderMenuEntry: -> addHeaderMenuEntry: ->
return if g.VIEW isnt 'thread' return if g.VIEW isnt 'thread'