From 79359d17ad86461b776287600a47def2befcebc2 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Thu, 11 Apr 2024 19:21:43 +1200 Subject: [PATCH] add upvote history to user profile and search results --- app/search/routes.py | 12 +++++++++++- app/user/routes.py | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/search/routes.py b/app/search/routes.py index 654be6fe..036f34b9 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 + communities_banned_from, recently_upvoted_posts, recently_downvoted_posts @bp.route('/search', methods=['GET', 'POST']) @@ -46,8 +46,18 @@ def run_search(): next_url = url_for('search.run_search', page=posts.next_num, q=q) if posts.has_next else None prev_url = url_for('search.run_search', page=posts.prev_num, q=q) if posts.has_prev and page != 1 else None + # Voting history + if current_user.is_authenticated: + recently_upvoted = recently_upvoted_posts(current_user.id) + recently_downvoted = recently_downvoted_posts(current_user.id) + else: + recently_upvoted = [] + recently_downvoted = [] + return render_template('search/results.html', title=_('Search results for %(q)s', q=q), posts=posts, q=q, next_url=next_url, prev_url=prev_url, show_post_community=True, + recently_upvoted=recently_upvoted, + recently_downvoted=recently_downvoted, moderating_communities=moderating_communities(current_user.get_id()), joined_communities=joined_communities(current_user.get_id()), site=g.site) diff --git a/app/user/routes.py b/app/user/routes.py index fde0773c..0c02f1a2 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 + allowlist_html, recently_upvoted_posts, recently_downvoted_posts from sqlalchemy import desc, or_, text import os @@ -79,12 +79,22 @@ def show_profile(user): replies_prev_url = url_for('activitypub.user_profile', actor=user.ap_id if user.ap_id is not None else user.user_name, replies_page=post_replies.prev_num) if post_replies.has_prev and replies_page != 1 else None + # Voting history + if current_user.is_authenticated: + recently_upvoted = recently_upvoted_posts(current_user.id) + recently_downvoted = recently_downvoted_posts(current_user.id) + else: + recently_upvoted = [] + recently_downvoted = [] + return render_template('user/show_profile.html', user=user, posts=posts, post_replies=post_replies, moderates=moderates.all(), canonical=canonical, title=_('Posts by %(user_name)s', user_name=user.user_name), description=description, subscribed=subscribed, upvoted=upvoted, post_next_url=post_next_url, post_prev_url=post_prev_url, replies_next_url=replies_next_url, replies_prev_url=replies_prev_url, + recently_upvoted=recently_upvoted, + recently_downvoted=recently_downvoted, noindex=not user.indexable, show_post_community=True, moderating_communities=moderating_communities(current_user.get_id()), joined_communities=joined_communities(current_user.get_id())