From 1341836e09e8dddfb0ce1438a8c32301a0079365 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sat, 13 Apr 2024 13:17:25 +1200 Subject: [PATCH 01/19] tidy up post button css --- app/static/structure.css | 14 +++----------- app/static/structure.scss | 11 ++++------- app/static/styles.css | 2 +- app/static/styles.scss | 2 +- 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/app/static/structure.css b/app/static/structure.css index 1b3a385b..ff5fe197 100644 --- a/app/static/structure.css +++ b/app/static/structure.css @@ -985,7 +985,8 @@ fieldset legend { } .voting_buttons_new .upvote_button, .voting_buttons_new .downvote_button { display: inline-block; - padding: 5px 15px; + padding: 5px 0; + text-align: center; position: relative; cursor: pointer; color: rgba(var(--bs-link-color-rgb), var(--bs-link-opacity, 1)); @@ -1012,11 +1013,6 @@ fieldset legend { .voting_buttons_new .upvote_button { top: 1px; } -@media (min-width: 1280px) { - .voting_buttons_new .upvote_button { - padding-right: 5px; - } -} .voting_buttons_new .upvote_button .htmx-indicator { left: 13px; top: 7px; @@ -1028,9 +1024,6 @@ fieldset legend { left: 12px; } @media (min-width: 1280px) { - .voting_buttons_new .downvote_button { - padding-left: 5px; - } .voting_buttons_new .downvote_button .htmx-indicator { left: 2px; } @@ -1125,7 +1118,6 @@ fieldset legend { .comment { clear: both; - margin-bottom: 10px; margin-left: 15px; padding-top: 8px; } @@ -1178,7 +1170,7 @@ fieldset legend { } .comment .comment_actions a { text-decoration: none; - padding: 5px 0; + padding: 0; } .comment .comment_actions .hide_button { display: inline-block; diff --git a/app/static/structure.scss b/app/static/structure.scss index 2b2a047f..a369118f 100644 --- a/app/static/structure.scss +++ b/app/static/structure.scss @@ -623,7 +623,8 @@ html { .upvote_button, .downvote_button { display: inline-block; - padding: 5px 15px; + padding: 5px 0; + text-align: center; position: relative; cursor: pointer; color: rgba(var(--bs-link-color-rgb),var(--bs-link-opacity,1)); @@ -654,9 +655,7 @@ html { .upvote_button { top: 1px; - @include breakpoint(laptop) { - padding-right: 5px; - } + .htmx-indicator { left: 13px; top: 7px; @@ -669,7 +668,6 @@ html { left: 12px; } @include breakpoint(laptop) { - padding-left: 5px; .htmx-indicator { left: 2px; } @@ -776,7 +774,6 @@ html { .comment { clear: both; - margin-bottom: 10px; margin-left: 15px; padding-top: 8px; @@ -836,7 +833,7 @@ html { position: relative; a { text-decoration: none; - padding: 5px 0; + padding: 0; } .hide_button { diff --git a/app/static/styles.css b/app/static/styles.css index fc3a6609..6039ec53 100644 --- a/app/static/styles.css +++ b/app/static/styles.css @@ -693,7 +693,7 @@ div.navbar { .comment_actions_link { display: block; position: absolute; - bottom: 0; + top: 3px; right: -16px; width: 41px; text-decoration: none; diff --git a/app/static/styles.scss b/app/static/styles.scss index 77e79e04..9fca4211 100644 --- a/app/static/styles.scss +++ b/app/static/styles.scss @@ -284,7 +284,7 @@ div.navbar { .comment_actions_link { display: block; position: absolute; - bottom: 0; + top: 3px; right: -16px; width: 41px; text-decoration: none; From 5d2e7d350c8c3d2d9080c6875705c253033b4400 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sat, 13 Apr 2024 13:30:00 +1200 Subject: [PATCH 02/19] tidy up post button css --- app/static/structure.css | 2 +- app/static/structure.scss | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/static/structure.css b/app/static/structure.css index ff5fe197..0d2f4c83 100644 --- a/app/static/structure.css +++ b/app/static/structure.css @@ -985,7 +985,7 @@ fieldset legend { } .voting_buttons_new .upvote_button, .voting_buttons_new .downvote_button { display: inline-block; - padding: 5px 0; + padding: 5px 0 5px 3px; text-align: center; position: relative; cursor: pointer; diff --git a/app/static/structure.scss b/app/static/structure.scss index a369118f..af288b35 100644 --- a/app/static/structure.scss +++ b/app/static/structure.scss @@ -623,7 +623,7 @@ html { .upvote_button, .downvote_button { display: inline-block; - padding: 5px 0; + padding: 5px 0 5px 3px; text-align: center; position: relative; cursor: pointer; From 2c99d5eea08d0ce0bdc978b31fbb46f1d6297391 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sat, 13 Apr 2024 13:39:04 +1200 Subject: [PATCH 03/19] tidy up post button css --- app/static/structure.css | 6 +----- app/static/structure.scss | 7 +------ 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/app/static/structure.css b/app/static/structure.css index 0d2f4c83..0971865c 100644 --- a/app/static/structure.css +++ b/app/static/structure.css @@ -1022,11 +1022,7 @@ fieldset legend { } .voting_buttons_new .downvote_button .htmx-indicator { left: 12px; -} -@media (min-width: 1280px) { - .voting_buttons_new .downvote_button .htmx-indicator { - left: 2px; - } + top: 5px; } .voting_buttons_new .htmx-indicator { position: absolute; diff --git a/app/static/structure.scss b/app/static/structure.scss index af288b35..a51099c8 100644 --- a/app/static/structure.scss +++ b/app/static/structure.scss @@ -666,13 +666,8 @@ html { top: 1px; .htmx-indicator { left: 12px; + top: 5px; } - @include breakpoint(laptop) { - .htmx-indicator { - left: 2px; - } - } - } .htmx-indicator{ From 75c3f7c8be6e0fe5f07046577f2956dd5aedca84 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sun, 14 Apr 2024 07:59:24 +1200 Subject: [PATCH 04/19] hot sort - more spicy pls (experiment) --- app/activitypub/util.py | 18 ++++++++++++++++-- app/community/routes.py | 2 +- app/main/routes.py | 2 +- app/post/routes.py | 13 +++++++++++-- app/topic/routes.py | 2 +- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/app/activitypub/util.py b/app/activitypub/util.py index f6563c1e..fd86d652 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -1037,7 +1037,13 @@ def downvote_post(post, user): if not existing_vote: effect = -1.0 post.down_votes += 1 - post.score -= 1.0 + # Make 'hot' sort more spicy by amplifying the effect of early downvotes + if post.up_votes + post.down_votes <= 30: + post.score -= 5.0 + elif post.up_votes + post.down_votes <= 60: + post.score -= 2.0 + else: + post.score -= 1.0 vote = PostVote(user_id=user.id, post_id=post.id, author_id=post.author.id, effect=effect) post.author.reputation += effect @@ -1139,10 +1145,18 @@ def upvote_post(post, user): user.last_seen = utcnow() user.recalculate_attitude() effect = instance_weight(user.ap_domain) + # Make 'hot' sort more spicy by amplifying the effect of early upvotes + spicy_effect = effect + if post.up_votes + post.down_votes <= 10: + spicy_effect = effect * 10 + elif post.up_votes + post.down_votes <= 30: + spicy_effect = effect * 5 + elif post.up_votes + post.down_votes <= 60: + spicy_effect = effect * 2 existing_vote = PostVote.query.filter_by(user_id=user.id, post_id=post.id).first() if not existing_vote: post.up_votes += 1 - post.score += effect + post.score += spicy_effect vote = PostVote(user_id=user.id, post_id=post.id, author_id=post.author.id, effect=effect) if post.community.low_quality and effect > 0: diff --git a/app/community/routes.py b/app/community/routes.py index 96b53bdb..03cbe021 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -184,7 +184,7 @@ def show_community(community: Community): if sort == '' or sort == 'hot': posts = posts.order_by(desc(Post.sticky)).order_by(desc(Post.ranking)).order_by(desc(Post.posted_at)) elif sort == 'top': - posts = posts.filter(Post.posted_at > utcnow() - timedelta(days=7)).order_by(desc(Post.sticky)).order_by(desc(Post.score)) + posts = posts.filter(Post.posted_at > utcnow() - timedelta(days=7)).order_by(desc(Post.sticky)).order_by(desc(Post.up_votes - Post.down_votes)) elif sort == 'new': posts = posts.order_by(desc(Post.posted_at)) elif sort == 'active': diff --git a/app/main/routes.py b/app/main/routes.py index 4af5798f..d90f55d3 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -114,7 +114,7 @@ def home_page(type, sort): if sort == 'hot': posts = posts.order_by(desc(Post.ranking)).order_by(desc(Post.posted_at)) elif sort == 'top': - posts = posts.filter(Post.posted_at > utcnow() - timedelta(days=1)).order_by(desc(Post.score)) + posts = posts.filter(Post.posted_at > utcnow() - timedelta(days=1)).order_by(desc(Post.up_votes - Post.down_votes)) elif sort == 'new': posts = posts.order_by(desc(Post.posted_at)) elif sort == 'active': diff --git a/app/post/routes.py b/app/post/routes.py index c3f72e3d..2f62b4d8 100644 --- a/app/post/routes.py +++ b/app/post/routes.py @@ -303,11 +303,20 @@ def post_vote(post_id: int, vote_direction): if vote_direction == 'upvote': effect = 1 post.up_votes += 1 - post.score += 1 + # Make 'hot' sort more spicy by amplifying the effect of early upvotes + if post.up_votes + post.down_votes <= 10: + post.score += 5 + elif post.up_votes + post.down_votes <= 100: + post.score += 2 + else: + post.score += 1 else: effect = -1 post.down_votes += 1 - post.score -= 1 + if post.up_votes + post.down_votes <= 100: + post.score -= 2 + else: + post.score -= 1 vote = PostVote(user_id=current_user.id, post_id=post.id, author_id=post.author.id, effect=effect) # upvotes do not increase reputation in low quality communities diff --git a/app/topic/routes.py b/app/topic/routes.py index a3a0a9dc..325342d4 100644 --- a/app/topic/routes.py +++ b/app/topic/routes.py @@ -77,7 +77,7 @@ def show_topic(topic_path): if sort == '' or sort == 'hot': posts = posts.order_by(desc(Post.ranking)).order_by(desc(Post.posted_at)) elif sort == 'top': - posts = posts.filter(Post.posted_at > utcnow() - timedelta(days=7)).order_by(desc(Post.score)) + posts = posts.filter(Post.posted_at > utcnow() - timedelta(days=7)).order_by(desc(Post.up_votes - Post.down_votes)) elif sort == 'new': posts = posts.order_by(desc(Post.posted_at)) elif sort == 'active': From 2dcbc45d67382bfbf44c204111ae310ab652b80c Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sun, 14 Apr 2024 08:17:02 +1200 Subject: [PATCH 05/19] hot sort - more spicy pls (experiment) --- app/post/routes.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/post/routes.py b/app/post/routes.py index 2f62b4d8..f80ab8b3 100644 --- a/app/post/routes.py +++ b/app/post/routes.py @@ -305,15 +305,19 @@ def post_vote(post_id: int, vote_direction): post.up_votes += 1 # Make 'hot' sort more spicy by amplifying the effect of early upvotes if post.up_votes + post.down_votes <= 10: + post.score += 10 + elif post.up_votes + post.down_votes <= 30: post.score += 5 - elif post.up_votes + post.down_votes <= 100: + elif post.up_votes + post.down_votes <= 60: post.score += 2 else: post.score += 1 else: effect = -1 post.down_votes += 1 - if post.up_votes + post.down_votes <= 100: + if post.up_votes + post.down_votes <= 30: + post.score -= 5 + elif post.up_votes + post.down_votes <= 60: post.score -= 2 else: post.score -= 1 From 59ca0f02a8c6e3a469b35eba3d3e812efde69255 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sun, 14 Apr 2024 08:57:46 +1200 Subject: [PATCH 06/19] blocking an account --- app/community/routes.py | 8 +++++++- app/post/util.py | 5 ++++- app/search/routes.py | 6 +++++- app/topic/routes.py | 8 +++++++- app/user/routes.py | 4 +++- app/utils.py | 8 +++++++- 6 files changed, 33 insertions(+), 6 deletions(-) diff --git a/app/community/routes.py b/app/community/routes.py index 03cbe021..6af5df89 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -30,7 +30,8 @@ from app.utils import get_setting, render_template, allowlist_html, markdown_to_ shorten_string, gibberish, community_membership, ap_datetime, \ request_etag_matches, return_304, instance_banned, can_create_post, can_upvote, can_downvote, user_filters_posts, \ joined_communities, moderating_communities, blocked_domains, mimetype_from_url, blocked_instances, \ - community_moderators, communities_banned_from, show_ban_message, recently_upvoted_posts, recently_downvoted_posts + community_moderators, communities_banned_from, show_ban_message, recently_upvoted_posts, recently_downvoted_posts, \ + blocked_users from feedgen.feed import FeedGenerator from datetime import timezone, timedelta @@ -181,6 +182,11 @@ def show_community(community: Community): if instance_ids: posts = posts.filter(or_(Post.instance_id.not_in(instance_ids), Post.instance_id == None)) + # filter blocked users + blocked_accounts = blocked_users(current_user.id) + if blocked_accounts: + posts = posts.filter(Post.user_id.not_in(blocked_accounts)) + if sort == '' or sort == 'hot': posts = posts.order_by(desc(Post.sticky)).order_by(desc(Post.ranking)).order_by(desc(Post.posted_at)) elif sort == 'top': diff --git a/app/post/util.py b/app/post/util.py index 99e7f6cb..c7dd5b73 100644 --- a/app/post/util.py +++ b/app/post/util.py @@ -5,7 +5,7 @@ from sqlalchemy import desc, text, or_ from app import db from app.models import PostReply -from app.utils import blocked_instances +from app.utils import blocked_instances, blocked_users # replies to a post, in a tree, sorted by a variety of methods @@ -17,6 +17,9 @@ def post_replies(post_id: int, sort_by: str, show_first: int = 0) -> List[PostRe comments = comments.filter(or_(PostReply.instance_id.not_in(instance_ids), PostReply.instance_id == None)) if current_user.ignore_bots: comments = comments.filter(PostReply.from_bot == False) + blocked_accounts = blocked_users(current_user.id) + if blocked_accounts: + comments = comments.filter(PostReply.user_id.not_in(blocked_accounts)) if sort_by == 'hot': comments = comments.order_by(desc(PostReply.ranking)) elif sort_by == 'top': diff --git a/app/search/routes.py b/app/search/routes.py index 036f34b9..4705e82a 100644 --- a/app/search/routes.py +++ b/app/search/routes.py @@ -6,7 +6,7 @@ from sqlalchemy import or_ from app.models import Post from app.search import bp from app.utils import moderating_communities, joined_communities, render_template, blocked_domains, blocked_instances, \ - communities_banned_from, recently_upvoted_posts, recently_downvoted_posts + communities_banned_from, recently_upvoted_posts, recently_downvoted_posts, blocked_users @bp.route('/search', methods=['GET', 'POST']) @@ -30,6 +30,10 @@ def run_search(): instance_ids = blocked_instances(current_user.id) if instance_ids: posts = posts.filter(or_(Post.instance_id.not_in(instance_ids), Post.instance_id == None)) + # filter blocked users + blocked_accounts = blocked_users(current_user.id) + if blocked_accounts: + posts = posts.filter(Post.user_id.not_in(blocked_accounts)) banned_from = communities_banned_from(current_user.id) if banned_from: posts = posts.filter(Post.community_id.not_in(banned_from)) diff --git a/app/topic/routes.py b/app/topic/routes.py index 325342d4..0751bcb4 100644 --- a/app/topic/routes.py +++ b/app/topic/routes.py @@ -17,7 +17,7 @@ from app import db, celery, cache from app.topic.forms import ChooseTopicsForm from app.utils import render_template, user_filters_posts, moderating_communities, joined_communities, \ community_membership, blocked_domains, validation_required, mimetype_from_url, blocked_instances, \ - communities_banned_from + communities_banned_from, blocked_users @bp.route('/topic/', methods=['GET']) @@ -63,12 +63,18 @@ def show_topic(topic_path): posts = posts.filter(Post.nsfw == False) content_filters = user_filters_posts(current_user.id) + # filter blocked domains and instances domains_ids = blocked_domains(current_user.id) if domains_ids: posts = posts.filter(or_(Post.domain_id.not_in(domains_ids), Post.domain_id == None)) instance_ids = blocked_instances(current_user.id) if instance_ids: posts = posts.filter(or_(Post.instance_id.not_in(instance_ids), Post.instance_id == None)) + # filter blocked users + blocked_accounts = blocked_users(current_user.id) + if blocked_accounts: + posts = posts.filter(Post.user_id.not_in(blocked_accounts)) + banned_from = communities_banned_from(current_user.id) if banned_from: posts = posts.filter(Post.community_id.not_in(banned_from)) diff --git a/app/user/routes.py b/app/user/routes.py index 196474ad..c1b2efa9 100644 --- a/app/user/routes.py +++ b/app/user/routes.py @@ -19,7 +19,7 @@ from app.user.utils import purge_user_then_delete from app.utils import get_setting, render_template, markdown_to_html, user_access, markdown_to_text, shorten_string, \ is_image_url, ensure_directory_exists, gibberish, file_get_contents, community_membership, user_filters_home, \ user_filters_posts, user_filters_replies, moderating_communities, joined_communities, theme_list, blocked_instances, \ - allowlist_html, recently_upvoted_posts, recently_downvoted_posts + allowlist_html, recently_upvoted_posts, recently_downvoted_posts, blocked_users from sqlalchemy import desc, or_, text import os @@ -294,6 +294,7 @@ def block_profile(actor): # federate block flash(f'{actor} has been blocked.') + cache.delete_memoized(blocked_users, current_user.id) goto = request.args.get('redirect') if 'redirect' in request.args else f'/u/{actor}' return redirect(goto) @@ -322,6 +323,7 @@ def unblock_profile(actor): # federate unblock flash(f'{actor} has been unblocked.') + cache.delete_memoized(blocked_users, current_user.id) goto = request.args.get('redirect') if 'redirect' in request.args else f'/u/{actor}' return redirect(goto) diff --git a/app/utils.py b/app/utils.py index 853f4c35..a389397b 100644 --- a/app/utils.py +++ b/app/utils.py @@ -29,7 +29,7 @@ import re from app.email import send_welcome_email from app.models import Settings, Domain, Instance, BannedInstances, User, Community, DomainBlock, ActivityPubLog, IpBan, \ - Site, Post, PostReply, utcnow, Filter, CommunityMember, InstanceBlock, CommunityBan, Topic + Site, Post, PostReply, utcnow, Filter, CommunityMember, InstanceBlock, CommunityBan, Topic, UserBlock # Flask's render_template function, with support for themes added @@ -335,6 +335,12 @@ def blocked_instances(user_id) -> List[int]: return [block.instance_id for block in blocks] +@cache.memoize(timeout=86400) +def blocked_users(user_id) -> List[int]: + blocks = UserBlock.query.filter_by(blocker_id=user_id) + return [block.blocked_id for block in blocks] + + @cache.memoize(timeout=86400) def blocked_phrases() -> List[str]: site = Site.query.get(1) From 2f4f56649e1576f13c7d36d8d4c658bea5f6f697 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sun, 14 Apr 2024 20:05:40 +1200 Subject: [PATCH 07/19] move admin nav into main menu --- app/templates/admin/_nav.html | 2 +- app/templates/admin/activities.html | 15 +++++++------ app/templates/admin/activity_json.html | 14 ++++++++----- app/templates/admin/add_user.html | 16 +++++++------- .../admin/approve_registrations.html | 15 +++++++------ app/templates/admin/communities.html | 15 +++++++------ app/templates/admin/edit_community.html | 16 +++++++------- app/templates/admin/edit_topic.html | 20 ++++++++++-------- app/templates/admin/edit_user.html | 16 +++++++------- app/templates/admin/federation.html | 16 +++++++------- app/templates/admin/misc.html | 16 +++++++------- app/templates/admin/newsletter.html | 15 +++++++------ app/templates/admin/posts.html | 16 +++++++------- app/templates/admin/reports.html | 15 +++++++------ app/templates/admin/site.html | 15 +++++++------ app/templates/admin/topics.html | 15 +++++++------ app/templates/admin/users.html | 15 +++++++------ app/templates/base.html | 21 ++++++++++++++++++- 18 files changed, 167 insertions(+), 106 deletions(-) diff --git a/app/templates/admin/_nav.html b/app/templates/admin/_nav.html index 03485e9e..507cd364 100644 --- a/app/templates/admin/_nav.html +++ b/app/templates/admin/_nav.html @@ -1,4 +1,4 @@ -