From c8a2bee2ed6c147e4d220bb9dd9ad12e4639a842 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 24 Aug 2023 11:55:19 +0100 Subject: [PATCH] Limit the number of shared items shown on profile --- daemon.py | 46 ++++++++++++++++++++++++++++++++++++---------- shares.py | 3 ++- webapp_profile.py | 12 ++++++++---- 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/daemon.py b/daemon.py index c98a64c9e..f8685db6c 100644 --- a/daemon.py +++ b/daemon.py @@ -3284,6 +3284,8 @@ class PubServer(BaseHTTPRequestHandler): min_images_for_accounts = \ self.server.min_images_for_accounts + max_shares_on_profile = \ + self.server.max_shares_on_profile profile_str = \ html_profile_after_search(recent_posts_cache, self.server.max_recent_posts, @@ -3319,7 +3321,8 @@ class PubServer(BaseHTTPRequestHandler): bold_reading, self.server.dogwhistles, min_images_for_accounts, - self.server.buy_sites) + self.server.buy_sites, + max_shares_on_profile) if profile_str: msg = profile_str.encode('utf-8') msglen = len(msg) @@ -4909,6 +4912,8 @@ class PubServer(BaseHTTPRequestHandler): min_images_for_accounts = \ self.server.min_images_for_accounts + max_shares_on_profile = \ + self.server.max_shares_on_profile profile_str = \ html_profile_after_search(recent_posts_cache, self.server.max_recent_posts, @@ -4944,7 +4949,8 @@ class PubServer(BaseHTTPRequestHandler): bold_reading, self.server.dogwhistles, min_images_for_accounts, - self.server.buy_sites) + self.server.buy_sites, + max_shares_on_profile) if profile_str: msg = profile_str.encode('utf-8') msglen = len(msg) @@ -12382,7 +12388,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.lists_enabled, self.server.content_license_url, timezone, bold_reading, - self.server.buy_sites, None) + self.server.buy_sites, None, + self.server.max_shares_on_profile) msg = msg.encode('utf-8') msglen = len(msg) self._set_headers('text/html', msglen, @@ -12475,6 +12482,8 @@ class PubServer(BaseHTTPRequestHandler): bold_reading = False if self.server.bold_reading.get(nick): bold_reading = True + max_shares_on_profile = \ + self.server.max_shares_on_profile msg = \ html_profile(signing_priv_key_pem, self.server.rss_icon_at_top, @@ -12510,7 +12519,8 @@ class PubServer(BaseHTTPRequestHandler): content_license_url, timezone, bold_reading, self.server.buy_sites, - None) + None, + max_shares_on_profile) msg = msg.encode('utf-8') msglen = len(msg) self._set_headers('text/html', msglen, @@ -15159,7 +15169,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.content_license_url, timezone, bold_reading, self.server.buy_sites, - None) + None, + self.server.max_shares_on_profile) msg = msg.encode('utf-8') msglen = len(msg) self._set_headers('text/html', msglen, @@ -15266,6 +15277,8 @@ class PubServer(BaseHTTPRequestHandler): bold_reading = False if self.server.bold_reading.get(nickname): bold_reading = True + max_shares_on_profile = \ + self.server.max_shares_on_profile msg = \ html_profile(self.server.signing_priv_key_pem, self.server.rss_icon_at_top, @@ -15303,7 +15316,8 @@ class PubServer(BaseHTTPRequestHandler): content_license_url, timezone, bold_reading, self.server.buy_sites, - None).encode('utf-8') + None, + max_shares_on_profile).encode('utf-8') msglen = len(msg) self._set_headers('text/html', msglen, cookie, calling_domain, False) @@ -15404,6 +15418,8 @@ class PubServer(BaseHTTPRequestHandler): bold_reading = False if self.server.bold_reading.get(nickname): bold_reading = True + max_shares_on_profile = \ + self.server.max_shares_on_profile msg = \ html_profile(self.server.signing_priv_key_pem, self.server.rss_icon_at_top, @@ -15441,7 +15457,8 @@ class PubServer(BaseHTTPRequestHandler): content_license_url, timezone, bold_reading, self.server.buy_sites, - None).encode('utf-8') + None, + max_shares_on_profile).encode('utf-8') msglen = len(msg) self._set_headers('text/html', msglen, cookie, calling_domain, False) @@ -15546,6 +15563,8 @@ class PubServer(BaseHTTPRequestHandler): bold_reading = False if self.server.bold_reading.get(nickname): bold_reading = True + max_shares_on_profile = \ + self.server.max_shares_on_profile msg = \ html_profile(self.server.signing_priv_key_pem, self.server.rss_icon_at_top, @@ -15583,7 +15602,8 @@ class PubServer(BaseHTTPRequestHandler): content_license_url, timezone, bold_reading, self.server.buy_sites, - None).encode('utf-8') + None, + max_shares_on_profile).encode('utf-8') msglen = len(msg) self._set_headers('text/html', msglen, cookie, calling_domain, False) @@ -15688,6 +15708,8 @@ class PubServer(BaseHTTPRequestHandler): bold_reading = False if self.server.bold_reading.get(nickname): bold_reading = True + max_shares_on_profile = \ + self.server.max_shares_on_profile msg = \ html_profile(self.server.signing_priv_key_pem, self.server.rss_icon_at_top, @@ -15726,7 +15748,8 @@ class PubServer(BaseHTTPRequestHandler): content_license_url, timezone, bold_reading, self.server.buy_sites, - None).encode('utf-8') + None, + max_shares_on_profile).encode('utf-8') msglen = len(msg) self._set_headers('text/html', msglen, cookie, calling_domain, False) @@ -15861,6 +15884,8 @@ class PubServer(BaseHTTPRequestHandler): bold_reading = False if self.server.bold_reading.get(nickname): bold_reading = True + max_shares_on_profile = \ + self.server.max_shares_on_profile msg = \ html_profile(self.server.signing_priv_key_pem, self.server.rss_icon_at_top, @@ -15894,7 +15919,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.content_license_url, timezone, bold_reading, self.server.buy_sites, - None).encode('utf-8') + None, + max_shares_on_profile).encode('utf-8') msglen = len(msg) self._set_headers('text/html', msglen, cookie, calling_domain, False) diff --git a/shares.py b/shares.py index ee874171c..2771e5b90 100644 --- a/shares.py +++ b/shares.py @@ -2255,7 +2255,8 @@ def actor_attached_shares(actor_json: {}) -> []: return attached_shares -def actor_attached_shares_as_html(actor_json: {}) -> str: +def actor_attached_shares_as_html(actor_json: {}, + max_shares_on_profile: int) -> str: """Returns html for any shared items attached to an actor https://codeberg.org/fediverse/fep/src/branch/main/fep/0837/fep-0837.md """ diff --git a/webapp_profile.py b/webapp_profile.py index a456886cc..eead904ea 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -203,7 +203,8 @@ def html_profile_after_search(recent_posts_cache: {}, max_recent_posts: int, onion_domain: str, i2p_domain: str, bold_reading: bool, dogwhistles: {}, min_images_for_accounts: [], - buy_sites: {}) -> str: + buy_sites: {}, + max_shares_on_profile: int) -> str: """Show a profile page after a search for a fediverse address """ http = False @@ -257,7 +258,8 @@ def html_profile_after_search(recent_posts_cache: {}, max_recent_posts: int, # shared items attached to the actor # https://codeberg.org/fediverse/fep/src/branch/main/fep/0837/fep-0837.md - attached_shared_items = actor_attached_shares_as_html(profile_json) + attached_shared_items = \ + actor_attached_shares_as_html(profile_json, max_shares_on_profile) avatar_url = '' if profile_json.get('icon'): @@ -801,7 +803,8 @@ def html_profile(signing_priv_key_pem: str, content_license_url: str, timezone: str, bold_reading: bool, buy_sites: {}, - actor_proxied: str) -> str: + actor_proxied: str, + max_shares_on_profile: int) -> str: """Show the profile page as html """ show_moved_accounts = False @@ -1139,7 +1142,8 @@ def html_profile(signing_priv_key_pem: str, # shared items attached to the actor # https://codeberg.org/fediverse/fep/src/branch/main/fep/0837/fep-0837.md - attached_shared_items = actor_attached_shares_as_html(profile_json) + attached_shared_items = \ + actor_attached_shares_as_html(profile_json, max_shares_on_profile) profile_header_str = \ _get_profile_header(base_dir, http_prefix,