Move these functions out of the main Filter object and into a subobject.

This commit is contained in:
ccd0 2019-03-30 15:36:11 -07:00
parent 29ff3bbede
commit e784844333
3 changed files with 23 additions and 19 deletions

View File

@ -123,7 +123,7 @@ Filter =
hideable = false hideable = false
mask = (if post.isReply then 2 else 1) mask = (if post.isReply then 2 else 1)
mask = (mask | (if post.file then 4 else 8)) mask = (mask | (if post.file then 4 else 8))
for key of Filter.filters when ((value = Filter[key] post)?) for key of Filter.filters when ((value = Filter.value key, post)?)
# Continue if there's nothing to filter (no tripcode for example). # Continue if there's nothing to filter (no tripcode for example).
for filter in Filter.filters[key] for filter in Filter.filters[key]
continue if ( continue if (
@ -165,19 +165,23 @@ Filter =
isHidden: (post) -> isHidden: (post) ->
!!Filter.test(post).hide !!Filter.test(post).hide
postID: (post) -> "#{post.ID}" valueF:
name: (post) -> post.info.name postID: (post) -> "#{post.ID}"
uniqueID: (post) -> post.info.uniqueID or '' name: (post) -> post.info.name
tripcode: (post) -> post.info.tripcode uniqueID: (post) -> post.info.uniqueID or ''
capcode: (post) -> post.info.capcode tripcode: (post) -> post.info.tripcode
pass: (post) -> post.info.pass capcode: (post) -> post.info.capcode
subject: (post) -> post.info.subject or (if post.isReply then undefined else '') pass: (post) -> post.info.pass
comment: (post) -> (post.info.comment ?= Build.parseComment post.info.commentHTML.innerHTML) subject: (post) -> post.info.subject or (if post.isReply then undefined else '')
flag: (post) -> post.info.flag comment: (post) -> (post.info.comment ?= Build.parseComment post.info.commentHTML.innerHTML)
filename: (post) -> post.file?.name flag: (post) -> post.info.flag
dimensions: (post) -> post.file?.dimensions filename: (post) -> post.file?.name
filesize: (post) -> post.file?.size dimensions: (post) -> post.file?.dimensions
MD5: (post) -> post.file?.MD5 filesize: (post) -> post.file?.size
MD5: (post) -> post.file?.MD5
value: (key, post) ->
Filter.valueF[key](post)
addFilter: (type, re, cb) -> addFilter: (type, re, cb) ->
$.get type, Conf[type], (item) -> $.get type, Conf[type], (item) ->
@ -273,14 +277,14 @@ Filter =
return { return {
el: el el: el
open: (post) -> open: (post) ->
value = Filter[type] post value = Filter.value type, post
value? value?
} }
makeFilter: -> makeFilter: ->
{type} = @dataset {type} = @dataset
# Convert value -> regexp, unless type is MD5 # Convert value -> regexp, unless type is MD5
value = Filter[type] Filter.menu.post value = Filter.value type, Filter.menu.post
re = if type in ['uniqueID', 'MD5'] then value else Filter.escape(value) re = if type in ['uniqueID', 'MD5'] then value else Filter.escape(value)
re = if type in ['uniqueID', 'MD5'] re = if type in ['uniqueID', 'MD5']
"/#{re}/" "/#{re}/"

View File

@ -91,8 +91,8 @@ Build.Test =
c.log y.outerHTML c.log y.outerHTML
for key of Config.filter when not key is 'General' and not (key is 'MD5' and post.board.ID is 'f') for key of Config.filter when not key is 'General' and not (key is 'MD5' and post.board.ID is 'f')
val1 = Filter[key] obj val1 = Filter.value key, obj
val2 = Filter[key] post2 val2 = Filter.value key, post2
if val1 isnt val2 if val1 isnt val2
fail = true fail = true
c.log "#{post.fullID} has filter bug in #{key}" c.log "#{post.fullID} has filter bug in #{key}"

View File

@ -45,7 +45,7 @@ ArchiveLink =
value = if type is 'country' value = if type is 'country'
post.info.flagCode or post.info.flagCodeTroll post.info.flagCode or post.info.flagCodeTroll
else else
Filter[type] post Filter.value type, post
# We want to parse the exact same stuff as the filter does already. # We want to parse the exact same stuff as the filter does already.
return false unless value return false unless value
el.href = Redirect.to 'search', el.href = Redirect.to 'search',