Count unread posts if desktop notifications are enabled.

Also fix missing Conf check, and return too early in counting replies to you.
Minor tweaks here and there.
This commit is contained in:
Mayhem 2013-08-21 15:45:32 +02:00
parent 606cbcc1c1
commit 08ea3cf7d0

View File

@ -1,6 +1,6 @@
Unread = Unread =
init: -> init: ->
return if g.VIEW isnt 'thread' or !Conf['Unread Count'] and !Conf['Unread Tab Icon'] return if g.VIEW isnt 'thread' or !Conf['Unread Count'] and !Conf['Unread Tab Icon'] and !Conf['Desktop Notifications']
@db = new DataBoard 'lastReadPosts', @sync @db = new DataBoard 'lastReadPosts', @sync
@hr = $.el 'hr', @hr = $.el 'hr',
@ -30,10 +30,10 @@ Unread =
for ID, post of Unread.thread.posts for ID, post of Unread.thread.posts
posts.push post if post.isReply posts.push post if post.isReply
Unread.addPosts posts Unread.addPosts posts
return unless Conf['Scroll to Last Read Post']
Unread.scroll() Unread.scroll()
scroll: -> scroll: ->
return unless Conf['Scroll to Last Read Post']
# Let the header's onload callback handle it. # Let the header's onload callback handle it.
return if (hash = location.hash.match /\d+/) and hash[0] of Unread.thread.posts return if (hash = location.hash.match /\d+/) and hash[0] of Unread.thread.posts
if Unread.posts.length if Unread.posts.length
@ -64,7 +64,7 @@ Unread =
Unread.lastReadPost = lastReadPost Unread.lastReadPost = lastReadPost
Unread.readArray Unread.posts Unread.readArray Unread.posts
Unread.readArray Unread.postsQuotingYou Unread.readArray Unread.postsQuotingYou
Unread.setLine() Unread.setLine() if Conf['Unread Line']
Unread.update() Unread.update()
addPosts: (posts) -> addPosts: (posts) ->
@ -91,7 +91,7 @@ Unread =
for quotelink in post.nodes.quotelinks when QR.db.get Get.postDataFromLink quotelink for quotelink in post.nodes.quotelinks when QR.db.get Get.postDataFromLink quotelink
Unread.postsQuotingYou.push post Unread.postsQuotingYou.push post
Unread.openNotification post Unread.openNotification post
return return
openNotification: (post) -> openNotification: (post) ->
return unless Header.areNotificationsEnabled return unless Header.areNotificationsEnabled
name = if Conf['Anonymize'] name = if Conf['Anonymize']
@ -150,12 +150,11 @@ Unread =
setLine: (force) -> setLine: (force) ->
return unless d.hidden or force is true return unless d.hidden or force is true
if post = Unread.posts[0] unless post = Unread.posts[0]
{root} = post.nodes
if root isnt $ '.thread > .replyContainer', root.parentNode # not the first reply
$.before root, Unread.hr
else
$.rm Unread.hr $.rm Unread.hr
return
if $.x 'preceding-sibling::div[contains(@class,"replyContainer")]', post.nodes.root # not the first reply
$.before post.nodes.root, Unread.hr
update: <% if (type === 'crx') { %>(dontrepeat) <% } %>-> update: <% if (type === 'crx') { %>(dontrepeat) <% } %>->
count = Unread.posts.length count = Unread.posts.length
@ -167,18 +166,18 @@ Unread =
# crbug.com/124381 # crbug.com/124381
# Call it one second later, # Call it one second later,
# but don't display outdated unread count. # but don't display outdated unread count.
unless dontrepeat return if dontrepeat
setTimeout -> setTimeout ->
d.title = '' d.title = ''
Unread.update true Unread.update true
, $.SECOND , $.SECOND
<% } %> <% } %>
return unless Conf['Unread Tab Icon'] return unless Conf['Unread Tab Icon']
Favicon.el.href = Favicon.el.href =
if g.DEAD if g.DEAD
if Unread.postsQuotingYou.length if Unread.postsQuotingYou[0]
Favicon.unreadDeadY Favicon.unreadDeadY
else if count else if count
Favicon.unreadDead Favicon.unreadDead
@ -186,7 +185,7 @@ Unread =
Favicon.dead Favicon.dead
else else
if count if count
if Unread.postsQuotingYou.length if Unread.postsQuotingYou[0]
Favicon.unreadY Favicon.unreadY
else else
Favicon.unread Favicon.unread