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
mask = (if post.isReply then 2 else 1)
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).
for filter in Filter.filters[key]
continue if (
@ -165,19 +165,23 @@ Filter =
isHidden: (post) ->
!!Filter.test(post).hide
postID: (post) -> "#{post.ID}"
name: (post) -> post.info.name
uniqueID: (post) -> post.info.uniqueID or ''
tripcode: (post) -> post.info.tripcode
capcode: (post) -> post.info.capcode
pass: (post) -> post.info.pass
subject: (post) -> post.info.subject or (if post.isReply then undefined else '')
comment: (post) -> (post.info.comment ?= Build.parseComment post.info.commentHTML.innerHTML)
flag: (post) -> post.info.flag
filename: (post) -> post.file?.name
dimensions: (post) -> post.file?.dimensions
filesize: (post) -> post.file?.size
MD5: (post) -> post.file?.MD5
valueF:
postID: (post) -> "#{post.ID}"
name: (post) -> post.info.name
uniqueID: (post) -> post.info.uniqueID or ''
tripcode: (post) -> post.info.tripcode
capcode: (post) -> post.info.capcode
pass: (post) -> post.info.pass
subject: (post) -> post.info.subject or (if post.isReply then undefined else '')
comment: (post) -> (post.info.comment ?= Build.parseComment post.info.commentHTML.innerHTML)
flag: (post) -> post.info.flag
filename: (post) -> post.file?.name
dimensions: (post) -> post.file?.dimensions
filesize: (post) -> post.file?.size
MD5: (post) -> post.file?.MD5
value: (key, post) ->
Filter.valueF[key](post)
addFilter: (type, re, cb) ->
$.get type, Conf[type], (item) ->
@ -273,14 +277,14 @@ Filter =
return {
el: el
open: (post) ->
value = Filter[type] post
value = Filter.value type, post
value?
}
makeFilter: ->
{type} = @dataset
# 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']
"/#{re}/"

View File

@ -91,8 +91,8 @@ Build.Test =
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')
val1 = Filter[key] obj
val2 = Filter[key] post2
val1 = Filter.value key, obj
val2 = Filter.value key, post2
if val1 isnt val2
fail = true
c.log "#{post.fullID} has filter bug in #{key}"

View File

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