Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP/Proof] Filter Labels #3369

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/Filtering/Filter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ Filter =
hl = undefined
top = false
noti = false
matcher = undefined
fielder = undefined
if QuoteYou.isYou(post)
hideable = false
mask = (if post.isReply then 2 else 1)
Expand All @@ -139,6 +141,8 @@ Filter =
(filter.mask & mask) or
(if filter.isstring then (filter.regexp isnt value) else !filter.regexp.test(value))
)
matcher = key
fielder = filter.regexp
if filter.hide
if hideable
hide = true
Expand All @@ -150,21 +154,24 @@ Filter =
if filter.noti
noti = true
if hide
{hide, stub}
{hide, stub, matcher, fielder}
else
{hl, top, noti}
{hl, top, noti, matcher, fielder}

node: ->
return if @isClone
{hide, stub, hl, top, noti} = Filter.test @, (!@isFetchedQuote and (@isReply or g.VIEW is 'index'))
{hide, stub, hl, top, noti, matcher, fielder} = Filter.test @, (!@isFetchedQuote and (@isReply or g.VIEW is 'index'))
if hide
if @isReply
PostHiding.hide @, stub
@labels.push "Hidden by the #{fielder} in #{matcher}"
else
ThreadHiding.hide @thread, stub
@labels.push "Hidden by the #{fielder} in #{matcher}"
else
if hl
@highlights = hl
@labels.push "Highlighting with #{hl} by the #{fielder} in #{matcher}"
$.addClass @nodes.root, hl...
if noti and Unread.posts and (@ID > Unread.lastReadPost) and not QuoteYou.isYou(@)
Unread.openNotification @, ' triggered a notification filter'
Expand Down
27 changes: 17 additions & 10 deletions src/Filtering/PostHiding.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ PostHiding =

if data = PostHiding.db.get {boardID: @board.ID, threadID: @thread.ID, postID: @ID}
if data.thisPost
PostHiding.hide @, data.makeStub, data.hideRecursively
PostHiding.hide @, 'Manually hidden', data.makeStub, data.hideRecursively
else
Recursive.apply PostHiding.hide, @, data.makeStub, true
Recursive.add PostHiding.hide, @, data.makeStub, true
label = "Recursively hidden for quoting No.#{@postID}"
Recursive.apply PostHiding.hide, @, label, data.makeStub, true
Recursive.add PostHiding.hide, @, label, data.makeStub, true

return unless Conf['Reply Hiding Buttons']

Expand Down Expand Up @@ -121,15 +122,16 @@ PostHiding =
thisPost = $('input[name=thisPost]', parent).checked
replies = $('input[name=replies]', parent).checked
makeStub = $('input[name=makeStub]', parent).checked
label = 'Manually hidden'
{post} = PostHiding.menu
if thisPost
PostHiding.hide post, makeStub, replies
PostHiding.hide post, label, makeStub, replies
else if replies
Recursive.apply PostHiding.hide, post, makeStub, true
Recursive.add PostHiding.hide, post, makeStub, true
Recursive.apply PostHiding.hide, post, label, makeStub, true
Recursive.add PostHiding.hide, post, label, makeStub, true
else
return
PostHiding.saveHiddenState post, true, thisPost, makeStub, replies
PostHiding.saveHiddenState post, true, thisPost, label, makeStub, replies
$.event 'CloseMenu'

show: ->
Expand Down Expand Up @@ -186,13 +188,15 @@ PostHiding =
PostHiding[(if post.isHidden then 'show' else 'hide')] post
PostHiding.saveHiddenState post, post.isHidden

hide: (post, makeStub=Conf['Stubs'], hideRecursively=Conf['Recursive Hiding']) ->
hide: (post, label, makeStub=Conf['Stubs'], hideRecursively=Conf['Recursive Hiding']) ->
post.labels.push label unless label in post.labels
return if post.isHidden
post.isHidden = true

if hideRecursively
Recursive.apply PostHiding.hide, post, makeStub, true
Recursive.add PostHiding.hide, post, makeStub, true
label = "Recursively hidden for quoting No.#{post.postID}"
Recursive.apply PostHiding.hide, post, label, makeStub, true
Recursive.add PostHiding.hide, post, label, makeStub, true

for quotelink in Get.allQuotelinksLinkingTo post
$.addClass quotelink, 'filtered'
Expand All @@ -217,6 +221,9 @@ PostHiding =
else
post.nodes.root.hidden = false
post.isHidden = false
post.labels = post.labels.filter (label) ->
# Mayhem says this is lame
!/^(Manually hidden|Recurisvely hidden|Hidden by)/.test label
if showRecursively
Recursive.apply PostHiding.show, post, true
Recursive.rm PostHiding.hide, post
Expand Down
18 changes: 18 additions & 0 deletions src/Menu/FilterLabels.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FilterLabels =
init: ->
return unless g.VIEW in ['index', 'thread'] and Conf['Menu'] and Conf['Filter Labels']

div = $.el 'div',
textContent: 'Labels'

Menu.menu.addEntry
el: div
order: 117
open: (post) ->
{labels} = post.origin or post
return false unless labels.length
@subEntries.length = 0
for label in labels
@subEntries.push el: $.el 'div', textContent: label
true
subEntries: []
1 change: 1 addition & 0 deletions src/classes/Post.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Post
@parseQuotes()
@parseFiles()

@labels = []
@isDead = false
@isHidden = false

Expand Down
5 changes: 5 additions & 0 deletions src/config/Config.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@ Config =
'Add a download with original filename link to the menu.'
1
]
'Filter Labels': [
true
'Add a menu entry that lists reasons for a post matching a filter.'
1
]

'Monitoring':
'Thread Updater': [
Expand Down
1 change: 1 addition & 0 deletions src/main/Main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ Main =
['Edit Link', QR.oekaki.menu]
['Download Link', DownloadLink]
['Archive Link', ArchiveLink]
['Filter Labels', FilterLabels]
['Quote Inlining', QuoteInline]
['Quote Previewing', QuotePreview]
['Quote Backlinks', QuoteBacklink]
Expand Down