From 08ea3cf7d031958db25588c3d353526df884d27c Mon Sep 17 00:00:00 2001 From: Mayhem Date: Wed, 21 Aug 2013 15:45:32 +0200 Subject: [PATCH] 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. --- src/Monitoring/Unread.coffee | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/Monitoring/Unread.coffee b/src/Monitoring/Unread.coffee index 8bf976073..9c31a2dd2 100644 --- a/src/Monitoring/Unread.coffee +++ b/src/Monitoring/Unread.coffee @@ -1,6 +1,6 @@ Unread = 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 @hr = $.el 'hr', @@ -30,10 +30,10 @@ Unread = for ID, post of Unread.thread.posts posts.push post if post.isReply Unread.addPosts posts - return unless Conf['Scroll to Last Read Post'] Unread.scroll() scroll: -> + return unless Conf['Scroll to Last Read Post'] # Let the header's onload callback handle it. return if (hash = location.hash.match /\d+/) and hash[0] of Unread.thread.posts if Unread.posts.length @@ -64,7 +64,7 @@ Unread = Unread.lastReadPost = lastReadPost Unread.readArray Unread.posts Unread.readArray Unread.postsQuotingYou - Unread.setLine() + Unread.setLine() if Conf['Unread Line'] Unread.update() addPosts: (posts) -> @@ -91,7 +91,7 @@ Unread = for quotelink in post.nodes.quotelinks when QR.db.get Get.postDataFromLink quotelink Unread.postsQuotingYou.push post Unread.openNotification post - return + return openNotification: (post) -> return unless Header.areNotificationsEnabled name = if Conf['Anonymize'] @@ -150,12 +150,11 @@ Unread = setLine: (force) -> return unless d.hidden or force is true - if post = Unread.posts[0] - {root} = post.nodes - if root isnt $ '.thread > .replyContainer', root.parentNode # not the first reply - $.before root, Unread.hr - else + unless post = Unread.posts[0] $.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) <% } %>-> count = Unread.posts.length @@ -167,18 +166,18 @@ Unread = # crbug.com/124381 # Call it one second later, # but don't display outdated unread count. - unless dontrepeat - setTimeout -> - d.title = '' - Unread.update true - , $.SECOND + return if dontrepeat + setTimeout -> + d.title = '' + Unread.update true + , $.SECOND <% } %> return unless Conf['Unread Tab Icon'] Favicon.el.href = if g.DEAD - if Unread.postsQuotingYou.length + if Unread.postsQuotingYou[0] Favicon.unreadDeadY else if count Favicon.unreadDead @@ -186,7 +185,7 @@ Unread = Favicon.dead else if count - if Unread.postsQuotingYou.length + if Unread.postsQuotingYou[0] Favicon.unreadY else Favicon.unread