From 58282b971be139dd44fe99c7345777499c98ac37 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Mon, 23 Oct 2023 22:54:11 +1300 Subject: [PATCH] hide low quality comments --- app/community/routes.py | 5 ++- app/models.py | 1 + app/static/js/scripts.js | 50 +++++++++++++++++++++++ app/static/styles.css | 8 ++++ app/static/styles.scss | 8 ++++ app/templates/community/_post_full.html | 11 ++--- app/templates/community/_post_teaser.html | 7 +++- app/templates/community/post.html | 19 ++++++--- app/utils.py | 6 ++- 9 files changed, 98 insertions(+), 17 deletions(-) diff --git a/app/community/routes.py b/app/community/routes.py index 4b5ca040..e1cbb069 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -15,7 +15,7 @@ from app.models import User, Community, CommunityMember, CommunityJoinRequest, C PostReplyVote, PostVote from app.community import bp from app.utils import get_setting, render_template, allowlist_html, markdown_to_html, validation_required, \ - shorten_string, markdown_to_text + shorten_string, markdown_to_text, domain_from_url @bp.route('/add_local', methods=['GET', 'POST']) @@ -205,6 +205,9 @@ def add_post(actor): post.title = form.link_title.data post.url = form.link_url.data post.type = POST_TYPE_LINK + domain = domain_from_url(form.link_url.data, create=True) + domain.post_count += 1 + post.domain = domain elif form.type.data == 'image': post.title = form.image_title.data post.type = POST_TYPE_IMAGE diff --git a/app/models.py b/app/models.py index a5677c9b..a04401ff 100644 --- a/app/models.py +++ b/app/models.py @@ -345,6 +345,7 @@ class Post(db.Model): search_vector = db.Column(TSVectorType('title', 'body')) image = db.relationship(File, foreign_keys=[image_id], cascade="all, delete") + domain = db.relationship('Domain', foreign_keys=[domain_id]) @classmethod def get_by_ap_id(cls, ap_id): diff --git a/app/static/js/scripts.js b/app/static/js/scripts.js index 88bef557..a1116883 100644 --- a/app/static/js/scripts.js +++ b/app/static/js/scripts.js @@ -12,6 +12,32 @@ window.addEventListener("load", function () { setupHideButtons(); }); +function collapseReply(comment_id) { + const reply = document.getElementById('comment_' + comment_id); + let isHidden = false; + if(reply) { + const hidables = parentElement.querySelectorAll('.hidable'); + + hidables.forEach(hidable => { + hidable.style.display = isHidden ? 'block' : 'none'; + }); + + const moreHidables = parentElement.parentElement.querySelectorAll('.hidable'); + moreHidables.forEach(hidable => { + hidable.style.display = isHidden ? 'block' : 'none'; + }); + + // Toggle the content of hideEl + if (isHidden) { + hideEl.innerHTML = "[-] hide"; + } else { + hideEl.innerHTML = "[+] show"; + } + + isHidden = !isHidden; // Toggle the state + } +} + // every element with the 'confirm_first' class gets a popup confirmation dialog function setupConfirmFirst() { const show_first = document.querySelectorAll('.confirm_first'); @@ -123,6 +149,30 @@ function setupHideButtons() { isHidden = !isHidden; // Toggle the state }); }); + + if(toBeHidden) { + toBeHidden.forEach((arrayElement) => { + // Build the ID of the outer div + const divId = "comment_" + arrayElement; + + // Access the outer div by its ID + const commentDiv = document.getElementById(divId); + + if (commentDiv) { + // Access the inner div with class "hide_button" inside the outer div + const hideButton = commentDiv.getElementsByClassName("hide_button")[0]; + + if (hideButton) { + // Programmatically trigger a click event on the "hide_button" div + hideButton.click(); + } else { + console.log(`"hide_button" not found in ${divId}`); + } + } else { + console.log(`Div with ID ${divId} not found`); + } + }); + } } function titleToURL(title) { diff --git a/app/static/styles.css b/app/static/styles.css index 3f0b9775..5523abd4 100644 --- a/app/static/styles.css +++ b/app/static/styles.css @@ -358,4 +358,12 @@ nav.navbar { background: whitesmoke url(/static/images/collapsed.gif) no-repeat center left; } +.domain_link { + color: #bbb; + font-size: 73%; +} +.domain_link a { + color: #777; +} + /*# sourceMappingURL=styles.css.map */ diff --git a/app/static/styles.scss b/app/static/styles.scss index f05c772e..68b9fa95 100644 --- a/app/static/styles.scss +++ b/app/static/styles.scss @@ -120,4 +120,12 @@ nav.navbar { .coolfieldset.collapsed legend{ background: whitesmoke url(/static/images/collapsed.gif) no-repeat center left; +} + +.domain_link { + color: $grey; + font-size: 73%; + a { + color: $dark-grey; + } } \ No newline at end of file diff --git a/app/templates/community/_post_full.html b/app/templates/community/_post_full.html index 5615d996..e5585304 100644 --- a/app/templates/community/_post_full.html +++ b/app/templates/community/_post_full.html @@ -14,11 +14,9 @@

{{ post.title }}

{% if post.url %} -

{{ post.url|shorten_url }} - {% if post.type == post_type_link %} - (domain) - {% endif %} -

+

{{ post.url|shorten_url }} + External link +

{% endif %}

submitted {{ moment(post.posted_at).fromNow() }} by {{ render_username(post.author) }}

@@ -48,9 +46,6 @@ {% if post.url %}

{{ post.url|shorten_url }} External link - {% if post.type == post_type_link %} - (domain) - {% endif %}

{% endif %}

submitted {{ moment(post.posted_at).fromNow() }} by diff --git a/app/templates/community/_post_teaser.html b/app/templates/community/_post_teaser.html index 8cafb17b..29483159 100644 --- a/app/templates/community/_post_teaser.html +++ b/app/templates/community/_post_teaser.html @@ -8,8 +8,11 @@

{{ post.title }} - {% if post.type == post_type_link %} - (domain) + {% if post.type == post_type_link and post.domain_id %} + + External link + + ({{ post.domain.name }}) {% endif %}

diff --git a/app/templates/community/post.html b/app/templates/community/post.html index 8c0f9e37..1e670f74 100644 --- a/app/templates/community/post.html +++ b/app/templates/community/post.html @@ -2,6 +2,9 @@ {% from 'bootstrap/form.html' import render_form %} {% block app_content %} +
{% include 'community/_post_full.html' %} @@ -35,19 +38,21 @@ {% include "community/_voting_buttons.html" %} {% endwith %}
-
[-] hide
+
{% if comment['comment'].score <= -10 %}[+] show{% else %}[-] hide{% endif %} +
{% if comment['comment'].author.deleted %} [deleted] {% else %} - {% if comment['comment'].author.avatar_id %} + {% if comment['comment'].author.avatar_id and comment['comment'].score > -10 %} Avatar {% endif %} - {{ comment['comment'].author.user_name }} + {% if comment['comment'].score > -10 %}{% endif %} + {{ comment['comment'].author.user_name }}{% if comment['comment'].score > -10 %}{% endif %} {% endif %} - {% if comment['comment'].author.id == post.author.id %}[S]{% endif %} + {% if comment['comment'].author.id == post.author.id %}[OP]{% endif %} {{ moment(comment['comment'].posted_at).fromNow(refresh=True) }}
@@ -74,7 +79,11 @@ {% endif %} {% endif %}
- + {% if comment['comment'].score <= -10 %} + + {% endif %} {% endmacro %}
diff --git a/app/utils.py b/app/utils.py index bcfdc3d7..7e1996f2 100644 --- a/app/utils.py +++ b/app/utils.py @@ -156,9 +156,13 @@ def markdown_to_text(markdown_text) -> str: return markdown_text.replace("# ", '') -def domain_from_url(url: str) -> Domain: +def domain_from_url(url: str, create=False) -> Domain: parsed_url = urlparse(url) domain = Domain.query.filter_by(name=parsed_url.hostname.lower()).first() + if create and domain is None: + domain = Domain(name=parsed_url.hostname.lower()) + db.session.add(domain) + db.session.commit() return domain