mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
reply thresholds
This commit is contained in:
parent
eef9b193f4
commit
9e03775e16
10 changed files with 69 additions and 3 deletions
|
@ -617,6 +617,8 @@ class User(UserMixin, db.Model):
|
|||
markdown_editor = db.Column(db.Boolean, default=False)
|
||||
interface_language = db.Column(db.String(10)) # a locale that the translation system understands e.g. 'en' or 'en-us'. If empty, use browser default
|
||||
language_id = db.Column(db.Integer, db.ForeignKey('language.id')) # the default choice in the language dropdown when composing posts & comments
|
||||
reply_collapse_threshold = db.Column(db.Integer, default=-10)
|
||||
reply_hide_threshold = db.Column(db.Integer, default=-20)
|
||||
|
||||
avatar = db.relationship('File', lazy='joined', foreign_keys=[avatar_id], single_parent=True, cascade="all, delete-orphan")
|
||||
cover = db.relationship('File', lazy='joined', foreign_keys=[cover_id], single_parent=True, cascade="all, delete-orphan")
|
||||
|
|
|
@ -276,11 +276,13 @@ def show_post(post_id: int):
|
|||
recently_downvoted = recently_downvoted_posts(current_user.id)
|
||||
recently_upvoted_replies = recently_upvoted_post_replies(current_user.id)
|
||||
recently_downvoted_replies = recently_downvoted_post_replies(current_user.id)
|
||||
reply_collapse_threshold = current_user.reply_collapse_threshold
|
||||
else:
|
||||
recently_upvoted = []
|
||||
recently_downvoted = []
|
||||
recently_upvoted_replies = []
|
||||
recently_downvoted_replies = []
|
||||
reply_collapse_threshold = -10
|
||||
|
||||
# Polls
|
||||
poll_form = False
|
||||
|
@ -316,6 +318,7 @@ def show_post(post_id: int):
|
|||
noindex=not post.author.indexable, preconnect=post.url if post.url else None,
|
||||
recently_upvoted=recently_upvoted, recently_downvoted=recently_downvoted,
|
||||
recently_upvoted_replies=recently_upvoted_replies, recently_downvoted_replies=recently_downvoted_replies,
|
||||
reply_collapse_threshold=reply_collapse_threshold,
|
||||
etag=f"{post.id}{sort}_{hash(post.last_active)}", markdown_editor=current_user.is_authenticated and current_user.markdown_editor,
|
||||
low_bandwidth=request.cookies.get('low_bandwidth', '0') == '1', SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER,
|
||||
SUBSCRIPTION_OWNER=SUBSCRIPTION_OWNER, SUBSCRIPTION_MODERATOR=SUBSCRIPTION_MODERATOR,
|
||||
|
|
|
@ -21,6 +21,11 @@ def post_replies(post_id: int, sort_by: str, show_first: int = 0) -> List[PostRe
|
|||
blocked_accounts = blocked_users(current_user.id)
|
||||
if blocked_accounts:
|
||||
comments = comments.filter(PostReply.user_id.not_in(blocked_accounts))
|
||||
if current_user.reply_hide_threshold:
|
||||
comments = comments.filter(PostReply.score > current_user.reply_hide_threshold)
|
||||
else:
|
||||
comments.filter(PostReply.score > -20)
|
||||
|
||||
if sort_by == 'hot':
|
||||
comments = comments.order_by(desc(PostReply.ranking))
|
||||
elif sort_by == 'top':
|
||||
|
|
|
@ -621,6 +621,10 @@ div.navbar {
|
|||
margin-bottom: 3px;
|
||||
}
|
||||
|
||||
form h5 {
|
||||
padding-top: 12px;
|
||||
}
|
||||
|
||||
.coolfieldset, .coolfieldset.expanded {
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
|
|
|
@ -189,6 +189,12 @@ div.navbar {
|
|||
margin-bottom: 3px;
|
||||
}
|
||||
|
||||
form {
|
||||
h5 {
|
||||
padding-top: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
.coolfieldset, .coolfieldset.expanded{
|
||||
border:1px solid $light-grey;
|
||||
border-radius: 5px;
|
||||
|
|
|
@ -80,7 +80,7 @@
|
|||
{% if comment['comment'].author.deleted -%}
|
||||
[deleted]
|
||||
{% else -%}
|
||||
{% if comment['comment'].author.avatar_id and comment['comment'].score > -10 and not low_bandwidth -%}
|
||||
{% if comment['comment'].author.avatar_id and comment['comment'].score > reply_collapse_threshold and not low_bandwidth -%}
|
||||
<a href="/u/{{ comment['comment'].author.link() }}" title="{{ comment['comment'].author.ap_id }}">
|
||||
<img src="{{ comment['comment'].author.avatar_thumbnail() }}" alt="" loading="lazy" /></a>
|
||||
{% endif -%}
|
||||
|
@ -122,7 +122,7 @@
|
|||
{% endwith -%}
|
||||
</div>
|
||||
<div class="hide_button">
|
||||
{% if comment['comment'].score <= -10 -%}
|
||||
{% if comment['comment'].score <= reply_collapse_threshold -%}
|
||||
<a href='#'><span class="fe fe-expand"></span></a>
|
||||
{% else -%}
|
||||
<a href='#'><span class="fe fe-collapse"></span></a>
|
||||
|
@ -148,7 +148,7 @@
|
|||
{% endif -%}
|
||||
{% endif -%}
|
||||
</div>
|
||||
{% if comment['comment'].score <= -10 -%}
|
||||
{% if comment['comment'].score <= reply_collapse_threshold -%}
|
||||
<script nonce="{{ session['nonce'] }}" type="text/javascript">
|
||||
toBeHidden.push({{ comment['comment'].id }});
|
||||
</script>
|
||||
|
|
|
@ -26,6 +26,10 @@
|
|||
{{ render_field(form.email_unread) }}
|
||||
<h5> Visibility </h5>
|
||||
{{ render_field(form.ignore_bots) }}
|
||||
{{ render_field(form.reply_collapse_threshold) }}
|
||||
<small class="field_hint">{{ _('Collapse replies with a score at or below this level - click to view.') }}</small>
|
||||
{{ render_field(form.reply_hide_threshold) }}
|
||||
<small class="field_hint">{{ _('Hide replies with a score at or below this level.') }}</small>
|
||||
{{ render_field(form.nsfw) }}
|
||||
{{ render_field(form.nsfl) }}
|
||||
{{ render_field(form.searchable) }}
|
||||
|
|
|
@ -38,6 +38,8 @@ class SettingsForm(FlaskForm):
|
|||
ignore_bots = BooleanField(_l('Hide posts by bots'))
|
||||
nsfw = BooleanField(_l('Show NSFW posts'))
|
||||
nsfl = BooleanField(_l('Show NSFL posts'))
|
||||
reply_collapse_threshold = IntegerField(_l('Reply collapse threshold'))
|
||||
reply_hide_threshold = IntegerField(_l('Reply hide threshold'))
|
||||
markdown_editor = BooleanField(_l('Use markdown editor GUI when writing'))
|
||||
searchable = BooleanField(_l('Show profile in user list'))
|
||||
indexable = BooleanField(_l('My posts appear in search results'))
|
||||
|
|
|
@ -238,6 +238,8 @@ def change_settings():
|
|||
current_user.email_unread = form.email_unread.data
|
||||
current_user.markdown_editor = form.markdown_editor.data
|
||||
current_user.interface_language = form.interface_language.data
|
||||
current_user.reply_collapse_threshold = form.reply_collapse_threshold.data
|
||||
current_user.reply_hide_threshold = form.reply_hide_threshold.data
|
||||
session['ui_language'] = form.interface_language.data
|
||||
import_file = request.files['import_file']
|
||||
if propagate_indexable:
|
||||
|
@ -277,6 +279,8 @@ def change_settings():
|
|||
form.theme.data = current_user.theme
|
||||
form.markdown_editor.data = current_user.markdown_editor
|
||||
form.interface_language.data = current_user.interface_language
|
||||
form.reply_collapse_threshold.data = current_user.reply_collapse_threshold
|
||||
form.reply_hide_threshold.data = current_user.reply_hide_threshold
|
||||
|
||||
return render_template('user/edit_settings.html', title=_('Edit profile'), form=form, user=current_user,
|
||||
moderating_communities=moderating_communities(current_user.get_id()),
|
||||
|
|
36
migrations/versions/363f2f07ff30_reply_thresholds.py
Normal file
36
migrations/versions/363f2f07ff30_reply_thresholds.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
"""reply thresholds
|
||||
|
||||
Revision ID: 363f2f07ff30
|
||||
Revises: 745e3e985199
|
||||
Create Date: 2024-06-28 17:40:49.866284
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '363f2f07ff30'
|
||||
down_revision = '745e3e985199'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('user', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('reply_collapse_threshold', sa.Integer(), nullable=True))
|
||||
batch_op.add_column(sa.Column('reply_hide_threshold', sa.Integer(), nullable=True))
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
op.execute(sa.DDL('UPDATE "user" SET reply_collapse_threshold = -10, reply_hide_threshold = -20 WHERE ap_id is null'))
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('user', schema=None) as batch_op:
|
||||
batch_op.drop_column('reply_hide_threshold')
|
||||
batch_op.drop_column('reply_collapse_threshold')
|
||||
|
||||
# ### end Alembic commands ###
|
Loading…
Reference in a new issue