diff options
| author | julian laplace <julescarbon@gmail.com> | 2022-10-27 17:09:18 +0200 |
|---|---|---|
| committer | julian laplace <julescarbon@gmail.com> | 2022-10-27 17:09:18 +0200 |
| commit | 8b1f460bf7d4291e70ddaeff9f4e8e8174808ba7 (patch) | |
| tree | 0f49ad4c997db75f9694f73b8abd0d2cd2237c21 /public/assets/js/lib/views/stream | |
| parent | 83c938702eb67bd6d154bb98b632e64e5e7e183f (diff) | |
filtering pics that might be in a comment
Diffstat (limited to 'public/assets/js/lib/views/stream')
| -rw-r--r-- | public/assets/js/lib/views/stream/hootstream.js | 35 |
1 files changed, 31 insertions, 4 deletions
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), $("<div class='thread'>") @@ -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 [ "<div class='divider dark'></div>", @@ -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) |
