mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
hide low quality comments
This commit is contained in:
parent
b630f76152
commit
58282b971b
9 changed files with 98 additions and 17 deletions
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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 = "<a href='#'>[-] hide</a>";
|
||||
} else {
|
||||
hideEl.innerHTML = "<a href='#'>[+] show</a>";
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -121,3 +121,11 @@ 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;
|
||||
}
|
||||
}
|
|
@ -14,11 +14,9 @@
|
|||
</div>
|
||||
<h1 class="mt-2">{{ post.title }}</h1>
|
||||
{% if post.url %}
|
||||
<p><small><a href="{{ post.url }}" rel="nofollow ugc">{{ post.url|shorten_url }}</a>
|
||||
{% if post.type == post_type_link %}
|
||||
<span class="domain_link">(<a href="/d/{{ post.domain_id }}">domain</a>)</span>
|
||||
{% endif %}
|
||||
</small></p>
|
||||
<p><small><a href="{{ post.url }}" rel="nofollow ugc">{{ post.url|shorten_url }}
|
||||
<img src="/static/images/external_link_black.svg" class="external_link_icon" alt="External link" />
|
||||
</a></small></p>
|
||||
{% endif %}
|
||||
<p><small>submitted {{ moment(post.posted_at).fromNow() }} by {{ render_username(post.author) }}</small></p>
|
||||
</div>
|
||||
|
@ -48,9 +46,6 @@
|
|||
{% if post.url %}
|
||||
<p><small><a href="{{ post.url }}" rel="nofollow ugc">{{ post.url|shorten_url }}
|
||||
<img src="/static/images/external_link_black.svg" class="external_link_icon" alt="External link" /></a>
|
||||
{% if post.type == post_type_link %}
|
||||
<span class="domain_link">(<a href="/d/{{ post.domain_id }}">domain</a>)</span>
|
||||
{% endif %}
|
||||
</small></p>
|
||||
{% endif %}
|
||||
<p class="small">submitted {{ moment(post.posted_at).fromNow() }} by
|
||||
|
|
|
@ -8,8 +8,11 @@
|
|||
<div class="col{% if post.image_id %}-8{% endif %}">
|
||||
<h3>
|
||||
<a href="{{ url_for('community.show_post', post_id=post.id) }}">{{ post.title }}</a>
|
||||
{% if post.type == post_type_link %}
|
||||
<span class="domain_link">(<a href="/d/{{ post.domain_id }}">domain</a>)</span>
|
||||
{% if post.type == post_type_link and post.domain_id %}
|
||||
<a href="{{ post.url }}" rel="nofollow ugc">
|
||||
<img src="/static/images/external_link_black.svg" class="external_link_icon" alt="External link" />
|
||||
</a>
|
||||
<span class="domain_link">(<a href="/d/{{ post.domain_id }}">{{ post.domain.name }}</a>)</span>
|
||||
{% endif %}
|
||||
</h3>
|
||||
</div>
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
{% from 'bootstrap/form.html' import render_form %}
|
||||
|
||||
{% block app_content %}
|
||||
<script type="text/javascript" nonce="{{ session['nonce'] }}">
|
||||
var toBeHidden = Array(); // this list of comment IDs will be iterated over in setupHideButtons() and the 'hide' button clicked
|
||||
</script>
|
||||
<div class="row">
|
||||
<div class="col-12 col-md-8 position-relative">
|
||||
{% include 'community/_post_full.html' %}
|
||||
|
@ -35,19 +38,21 @@
|
|||
{% include "community/_voting_buttons.html" %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
<div class="hide_button"><a href='#'>[-] hide</a></div>
|
||||
<div class="hide_button">{% if comment['comment'].score <= -10 %}<a href='#'>[+] show</a>{% else %}<a href='#'>[-] hide</a>{% endif %}
|
||||
</div>
|
||||
<div class="comment_author">
|
||||
{% if comment['comment'].author.deleted %}
|
||||
<strong>[deleted]</strong>
|
||||
{% else %}
|
||||
{% if comment['comment'].author.avatar_id %}
|
||||
{% if comment['comment'].author.avatar_id and comment['comment'].score > -10 %}
|
||||
<a href="/u/{{ comment['comment'].author.link() }}" title="{{ comment['comment'].author.ap_id }}">
|
||||
<img src="{{ comment['comment'].author.avatar_image() }}" alt="Avatar" /></a>
|
||||
{% endif %}
|
||||
<a href="/u/{{ comment['comment'].author.link() }}" title="{{ comment['comment'].author.link() }}">
|
||||
<strong>{{ comment['comment'].author.user_name }}</strong></a>
|
||||
{% if comment['comment'].score > -10 %}<strong>{% endif %}
|
||||
{{ comment['comment'].author.user_name }}{% if comment['comment'].score > -10 %}</strong>{% endif %}</a>
|
||||
{% endif %}
|
||||
{% if comment['comment'].author.id == post.author.id %}<span title="Submitter of original post" aria-label="submitter">[S]</span>{% endif %}
|
||||
{% if comment['comment'].author.id == post.author.id %}<span title="Submitter of original post" aria-label="submitter" class="small">[OP]</span>{% endif %}
|
||||
<span class="text-muted small">{{ moment(comment['comment'].posted_at).fromNow(refresh=True) }}</span>
|
||||
</div>
|
||||
<div class="comment_body hidable">
|
||||
|
@ -74,7 +79,11 @@
|
|||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if comment['comment'].score <= -10 %}
|
||||
<script nonce="{{ session['nonce'] }}" type="text/javascript">
|
||||
toBeHidden.push({{ comment['comment'].id }});
|
||||
</script>
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
<div id="replies" class="comments">
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue