From 8b1f460bf7d4291e70ddaeff9f4e8e8174808ba7 Mon Sep 17 00:00:00 2001 From: julian laplace Date: Thu, 27 Oct 2022 17:09:18 +0200 Subject: filtering pics that might be in a comment --- public/assets/js/lib/views/stream/hootstream.js | 35 ++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'public/assets/js/lib/views/stream/hootstream.js') diff --git a/public/assets/js/lib/views/stream/hootstream.js b/public/assets/js/lib/views/stream/hootstream.js index 777489d..628d59c 100644 --- a/public/assets/js/lib/views/stream/hootstream.js +++ b/public/assets/js/lib/views/stream/hootstream.js @@ -109,7 +109,12 @@ var HootStream = View.extend({ ) { return true; } - if (filters.images && thread.images.length) { + if ( + (filters.images && thread.images.length) || + thread.comments.some((comment) => + CONTAINS_IMAGE_URL_REGEXP.test(comment.comment) + ) + ) { return true; } return false; @@ -131,10 +136,20 @@ var HootStream = View.extend({ return filters.files; }) : [], - comments: filters.hoots ? thread.comments : [], + comments: filters.hoots + ? thread.comments + : filters.images + ? thread.comments.filter((comment) => + CONTAINS_IMAGE_URL_REGEXP.test(comment.comment) + ) + : [], query: data.query, }; - if (threadData.files.length || threadData.comments.length) { + if ( + threadData.images.length || + threadData.files.length || + threadData.comments.length + ) { return this.renderThread(threadData).reduce( ($el, $item) => $el.append($item), $("
") @@ -238,6 +253,16 @@ var HootStream = View.extend({ 1.0 ); + const filteredImages = images + .map((image) => [image, new RegExp(encodeURIComponent(image.filename))]) + .filter( + ([, filenameRegexp]) => + !comments.some((comment) => filenameRegexp.test(comment.comment)) + ) + .map(([image]) => image); + + console.log(filteredImages); + // console.log(thread); return [ "
", @@ -257,7 +282,9 @@ var HootStream = View.extend({ comment_opacity: age_opacity * get_size_opacity(thread.comment_count), }), this.renderImages( - isViewingThread || postedToday ? images : images.slice(0, 6) + isViewingThread || postedToday + ? filteredImages + : filteredImages.slice(0, 6) ), this.renderFiles( isViewingThread || postedToday ? files : files.slice(0, 10) -- cgit v1.2.3-70-g09d2