From 2003b25c05c7fc418e8966e0d546eaa38634987a Mon Sep 17 00:00:00 2001 From: ebinBuddha <30810167+ebinBuddha@users.noreply.github.com> Date: Sat, 12 Jan 2019 01:25:41 +0100 Subject: [PATCH 1/5] added desktop notification for filters --- src/Filtering/Filter.coffee | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/Filtering/Filter.coffee b/src/Filtering/Filter.coffee index 80df4cffd..bec7324b8 100644 --- a/src/Filtering/Filter.coffee +++ b/src/Filtering/Filter.coffee @@ -63,6 +63,9 @@ Filter = false else Conf['Stubs'] + + # Desktop notification + noti = /notify/.test filter # Highlight the post, or hide it. # If not specified, the highlight class will be filter-highlight. @@ -82,7 +85,7 @@ Filter = else types = ['subject', 'name', 'filename', 'comment'] - filter = @createFilter regexp, boards, excludes, op, stub, hl, top + filter = @createFilter regexp, boards, excludes, op, stub, hl, top, noti if key is 'general' for type in types (@filters[type] or= []).push filter @@ -94,7 +97,7 @@ Filter = name: 'Filter' cb: @node - createFilter: (regexp, boards, excludes, op, stub, hl, top) -> + createFilter: (regexp, boards, excludes, op, stub, hl, top, noti) -> test = if typeof regexp is 'string' # MD5 checking @@ -107,6 +110,7 @@ Filter = stub: stub class: hl top: top + noti: noti (value, boardID, isReply) -> if boards and boardID not in boards @@ -125,6 +129,7 @@ Filter = stub = true hl = undefined top = false + noti = false if QuoteYou.isYou(post) hideable = false for key of Filter.filters when ((value = Filter[key] post)?) @@ -138,14 +143,16 @@ Filter = unless hl and result.class in hl (hl or= []).push result.class top or= result.top + if result.noti + noti = true if hide - {hide, stub} + {hide, stub, noti} else - {hl, top} + {hl, top, noti} node: -> return if @isClone - {hide, stub, hl, top} = Filter.test @, (!@isFetchedQuote and (@isReply or g.VIEW is 'index')) + {hide, stub, hl, top, noti} = Filter.test @, (!@isFetchedQuote and (@isReply or g.VIEW is 'index')) if hide if @isReply PostHiding.hide @, stub @@ -155,7 +162,20 @@ Filter = if hl @highlights = hl $.addClass @nodes.root, hl... - return + if noti + if Header.areNotificationsEnabled + if not (Unread.posts is null) + if (@ID > Unread.lastReadPost) and not QuoteYou.isYou(@) + notif = new Notification "#{@info.nameBlock} triggered a notification filter", + body: @commentDisplay() + icon: Favicon.logo + notif.onclick = -> + Header.scrollToIfNeeded @nodes.bottom, true + window.focus() + notif.onshow = -> + setTimeout -> + notif.close() + , 7 * $.SECOND isHidden: (post) -> !!Filter.test(post).hide From 28a46edcf3654362d33586b68e5172d0f4b54f07 Mon Sep 17 00:00:00 2001 From: ebinBuddha <30810167+ebinBuddha@users.noreply.github.com> Date: Thu, 21 Feb 2019 12:10:05 +0100 Subject: [PATCH 2/5] whitespaces --- src/Filtering/Filter.coffee | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Filtering/Filter.coffee b/src/Filtering/Filter.coffee index bec7324b8..28d463389 100644 --- a/src/Filtering/Filter.coffee +++ b/src/Filtering/Filter.coffee @@ -63,9 +63,9 @@ Filter = false else Conf['Stubs'] - - # Desktop notification - noti = /notify/.test filter + + # Desktop notification + noti = /notify/.test filter # Highlight the post, or hide it. # If not specified, the highlight class will be filter-highlight. @@ -110,7 +110,7 @@ Filter = stub: stub class: hl top: top - noti: noti + noti: noti (value, boardID, isReply) -> if boards and boardID not in boards @@ -129,7 +129,7 @@ Filter = stub = true hl = undefined top = false - noti = false + noti = false if QuoteYou.isYou(post) hideable = false for key of Filter.filters when ((value = Filter[key] post)?) @@ -143,8 +143,8 @@ Filter = unless hl and result.class in hl (hl or= []).push result.class top or= result.top - if result.noti - noti = true + if result.noti + noti = true if hide {hide, stub, noti} else @@ -162,9 +162,9 @@ Filter = if hl @highlights = hl $.addClass @nodes.root, hl... - if noti - if Header.areNotificationsEnabled - if not (Unread.posts is null) + if noti + if Header.areNotificationsEnabled + if not (Unread.posts is null) if (@ID > Unread.lastReadPost) and not QuoteYou.isYou(@) notif = new Notification "#{@info.nameBlock} triggered a notification filter", body: @commentDisplay() From 24f1458a73a7b95c8248783de91c68f274948711 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Mon, 18 Mar 2019 21:54:02 -0700 Subject: [PATCH 3/5] Fix issues from https://github.com/ccd0/4chan-x/pull/2231#issuecomment-467247167 #2231 --- src/Filtering/Filter.coffee | 16 ++-------------- src/Monitoring/Unread.coffee | 4 ++-- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/Filtering/Filter.coffee b/src/Filtering/Filter.coffee index 28d463389..d77057462 100644 --- a/src/Filtering/Filter.coffee +++ b/src/Filtering/Filter.coffee @@ -162,20 +162,8 @@ Filter = if hl @highlights = hl $.addClass @nodes.root, hl... - if noti - if Header.areNotificationsEnabled - if not (Unread.posts is null) - if (@ID > Unread.lastReadPost) and not QuoteYou.isYou(@) - notif = new Notification "#{@info.nameBlock} triggered a notification filter", - body: @commentDisplay() - icon: Favicon.logo - notif.onclick = -> - Header.scrollToIfNeeded @nodes.bottom, true - window.focus() - notif.onshow = -> - setTimeout -> - notif.close() - , 7 * $.SECOND + if noti and Unread.posts and (@ID > Unread.lastReadPost) and not QuoteYou.isYou(@) + Unread.openNotification @, ' triggered a notification filter' isHidden: (post) -> !!Filter.test(post).hide diff --git a/src/Monitoring/Unread.coffee b/src/Monitoring/Unread.coffee index 4714deff8..50a9a9c28 100644 --- a/src/Monitoring/Unread.coffee +++ b/src/Monitoring/Unread.coffee @@ -124,9 +124,9 @@ Unread = Unread.openNotification post return - openNotification: (post) -> + openNotification: (post, predicate=' replied to you') -> return unless Header.areNotificationsEnabled - notif = new Notification "#{post.info.nameBlock} replied to you", + notif = new Notification "#{post.info.nameBlock}#{predicate}", body: post.commentDisplay() icon: Favicon.logo notif.onclick = -> From 28dc40b1d404ff4987a92941ed80424850bcc718 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Mon, 18 Mar 2019 21:58:22 -0700 Subject: [PATCH 4/5] Don't hide posts with notification filters. #2231 --- src/Filtering/Filter.coffee | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Filtering/Filter.coffee b/src/Filtering/Filter.coffee index d77057462..386c8f083 100644 --- a/src/Filtering/Filter.coffee +++ b/src/Filtering/Filter.coffee @@ -106,7 +106,7 @@ Filter = (value) -> regexp.test value settings = - hide: !hl + hide: !(hl or noti) stub: stub class: hl top: top @@ -143,10 +143,10 @@ Filter = unless hl and result.class in hl (hl or= []).push result.class top or= result.top - if result.noti - noti = true + if result.noti + noti = true if hide - {hide, stub, noti} + {hide, stub} else {hl, top, noti} From ef89d9324927629cad6f4d0bff3cd6e845d7e8ca Mon Sep 17 00:00:00 2001 From: ccd0 Date: Mon, 18 Mar 2019 22:03:46 -0700 Subject: [PATCH 5/5] Document notification filters. #2231 --- src/General/Settings/Filter-guide.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/General/Settings/Filter-guide.html b/src/General/Settings/Filter-guide.html index df0838609..911a9051f 100644 --- a/src/General/Settings/Filter-guide.html +++ b/src/General/Settings/Filter-guide.html @@ -30,6 +30,10 @@ Highlighted OPs will have their threads put on top of the board index by default.
For example: top:yes; or top:no;. +
  • + Show a desktop notification instead of hiding.
    + For example: notify;. +
  • Filters in the "General" section apply to multiple fields, by default subject,name,filename,comment.
    The fields can be specified with the type option, separated by commas.