mirror of https://gitlab.com/bashrc2/epicyon
Screen to show the list of likers of a post
parent
c0226d3870
commit
fd80babfb8
74
daemon.py
74
daemon.py
|
@ -377,6 +377,7 @@ from fitnessFunctions import fitness_thread
|
|||
from fitnessFunctions import sorted_watch_points
|
||||
from fitnessFunctions import html_watch_points_graph
|
||||
from siteactive import referer_is_active
|
||||
from webapp_likers import html_likers_of_post
|
||||
import os
|
||||
|
||||
|
||||
|
@ -10421,6 +10422,63 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.debug)
|
||||
return result
|
||||
|
||||
def _show_likers_of_post(self, authorized: bool,
|
||||
calling_domain: str, path: str,
|
||||
base_dir: str, http_prefix: str,
|
||||
domain: str, domain_full: str, port: int,
|
||||
onion_domain: str, i2p_domain: str,
|
||||
getreq_start_time,
|
||||
proxy_type: str, cookie: str,
|
||||
debug: str) -> bool:
|
||||
"""Show the likers of a post
|
||||
"""
|
||||
if not authorized:
|
||||
return False
|
||||
if '?likers=' not in path:
|
||||
return False
|
||||
if '/users/' not in path:
|
||||
return False
|
||||
nickname = path.split('/users/')[1]
|
||||
if '?' in nickname:
|
||||
nickname = nickname.split('?')[0]
|
||||
post_url = path.split('?likers=')[1]
|
||||
if '?' in post_url:
|
||||
post_url = post_url.split('?')[0]
|
||||
post_url = post_url.replace('--', '/')
|
||||
|
||||
msg = \
|
||||
html_likers_of_post(base_dir, nickname, domain, port,
|
||||
post_url, self.server.translate,
|
||||
http_prefix,
|
||||
self.server.theme_name,
|
||||
self.server.access_keys,
|
||||
self.server.recent_posts_cache,
|
||||
self.server.max_recent_posts,
|
||||
self.server.session,
|
||||
self.server.cached_webfingers,
|
||||
self.server.person_cache,
|
||||
self.server.project_version,
|
||||
self.server.yt_replace_domain,
|
||||
self.server.twitter_replacement_domain,
|
||||
self.server.show_published_date_only,
|
||||
self.server.peertube_instances,
|
||||
self.server.allow_local_network_access,
|
||||
self.server.system_language,
|
||||
self.server.max_like_count,
|
||||
self.server.signing_priv_key_pem,
|
||||
self.server.cw_lists,
|
||||
self.server.lists_enabled,
|
||||
'inbox', self.server.default_timeline)
|
||||
msg = msg.encode('utf-8')
|
||||
msglen = len(msg)
|
||||
self._set_headers('text/html', msglen,
|
||||
cookie, calling_domain, False)
|
||||
self._write(msg)
|
||||
fitness_performance(getreq_start_time, self.server.fitness,
|
||||
'_GET', '_show_likers_of_post',
|
||||
self.server.debug)
|
||||
return True
|
||||
|
||||
def _show_post_from_file(self, post_filename: str, liked_by: str,
|
||||
react_by: str, react_emoji: str,
|
||||
authorized: bool,
|
||||
|
@ -16487,6 +16545,22 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.getreq_busy = False
|
||||
return
|
||||
|
||||
# show the likers of a post
|
||||
if self._show_likers_of_post(authorized,
|
||||
calling_domain, self.path,
|
||||
self.server.base_dir,
|
||||
self.server.http_prefix,
|
||||
self.server.domain,
|
||||
self.server.domain_full,
|
||||
self.server.port,
|
||||
self.server.onion_domain,
|
||||
self.server.i2p_domain,
|
||||
getreq_start_time,
|
||||
self.server.proxy_type,
|
||||
cookie, self.server.debug):
|
||||
self.server.getreq_busy = False
|
||||
return
|
||||
|
||||
fitness_performance(getreq_start_time, self.server.fitness,
|
||||
'_GET', 'individual post done',
|
||||
self.server.debug)
|
||||
|
|
|
@ -0,0 +1,129 @@
|
|||
__filename__ = "webapp_likers.py"
|
||||
__author__ = "Bob Mottram"
|
||||
__license__ = "AGPL3+"
|
||||
__version__ = "1.3.0"
|
||||
__maintainer__ = "Bob Mottram"
|
||||
__email__ = "bob@libreserver.org"
|
||||
__status__ = "Production"
|
||||
__module_group__ = "ActivityPub"
|
||||
|
||||
import os
|
||||
from utils import locate_post
|
||||
from utils import get_config_param
|
||||
from utils import get_account_timezone
|
||||
from utils import get_display_name
|
||||
from utils import get_nickname_from_actor
|
||||
from utils import has_object_dict
|
||||
from webapp_utils import html_header_with_external_style
|
||||
from webapp_utils import html_footer
|
||||
from webapp_utils import get_banner_file
|
||||
from webapp_post import individual_post_as_html
|
||||
|
||||
|
||||
def html_likers_of_post(base_dir: str, nickname: str,
|
||||
domain: str, port: int,
|
||||
post_url: str, translate: {},
|
||||
http_prefix: str,
|
||||
theme: str, access_keys: {},
|
||||
recent_posts_cache: {}, max_recent_posts: int,
|
||||
session, cached_webfingers: {},
|
||||
person_cache: {},
|
||||
project_version: str,
|
||||
yt_replace_domain: str,
|
||||
twitter_replacement_domain: str,
|
||||
show_published_date_only: bool,
|
||||
peertube_instances: [],
|
||||
allow_local_network_access: bool,
|
||||
system_language: str,
|
||||
max_like_count: int, signing_priv_key_pem: str,
|
||||
cw_lists: {}, lists_enabled: str,
|
||||
boxName: str, default_timeline: str) -> str:
|
||||
"""Returns html for a screen showing who liked a post
|
||||
"""
|
||||
css_filename = base_dir + '/epicyon-profile.css'
|
||||
if os.path.isfile(base_dir + '/epicyon.css'):
|
||||
css_filename = base_dir + '/epicyon.css'
|
||||
|
||||
instance_title = get_config_param(base_dir, 'instanceTitle')
|
||||
html_str = \
|
||||
html_header_with_external_style(css_filename, instance_title, None)
|
||||
|
||||
# get the post which was liked
|
||||
post_json_object = \
|
||||
locate_post(base_dir, nickname, domain, post_url)
|
||||
if not post_json_object:
|
||||
return html_str + html_footer()
|
||||
|
||||
# show the top banner
|
||||
banner_file, _ = \
|
||||
get_banner_file(base_dir, nickname, domain, theme)
|
||||
html_str += \
|
||||
'<header>\n' + \
|
||||
'<a href="/users/' + nickname + '/' + default_timeline + \
|
||||
'" title="' + \
|
||||
translate['Switch to timeline view'] + '" alt="' + \
|
||||
translate['Switch to timeline view'] + '" ' + \
|
||||
'accesskey="' + access_keys['menuTimeline'] + '">\n'
|
||||
html_str += '<img loading="lazy" class="timeline-banner" src="' + \
|
||||
'/users/' + nickname + '/' + banner_file + '" alt="" /></a>\n' + \
|
||||
'</header>\n'
|
||||
|
||||
# show the post which was liked
|
||||
timezone = get_account_timezone(base_dir, nickname, domain)
|
||||
html_str += \
|
||||
individual_post_as_html(signing_priv_key_pem,
|
||||
True, recent_posts_cache,
|
||||
max_recent_posts,
|
||||
translate, None,
|
||||
base_dir, session,
|
||||
cached_webfingers,
|
||||
person_cache,
|
||||
nickname, domain, port,
|
||||
post_json_object,
|
||||
None, True, False,
|
||||
http_prefix,
|
||||
project_version,
|
||||
boxName,
|
||||
yt_replace_domain,
|
||||
twitter_replacement_domain,
|
||||
show_published_date_only,
|
||||
peertube_instances,
|
||||
allow_local_network_access,
|
||||
theme, system_language,
|
||||
max_like_count,
|
||||
False, False, False,
|
||||
False, False, False,
|
||||
cw_lists, lists_enabled,
|
||||
timezone)
|
||||
|
||||
# show likers beneath the post
|
||||
obj = post_json_object
|
||||
if has_object_dict(post_json_object):
|
||||
obj = post_json_object['object']
|
||||
if not obj.get('likes'):
|
||||
return html_str + html_footer()
|
||||
if not isinstance(obj['likes'], dict):
|
||||
return html_str + html_footer()
|
||||
if not obj['likes'].get('items'):
|
||||
return html_str + html_footer()
|
||||
|
||||
html_str += '<center><h2>' + translate['Liked by'] + '</h2></center>\n'
|
||||
|
||||
likers_list = ''
|
||||
for like_item in obj['likes']['items']:
|
||||
if not like_item.get('actor'):
|
||||
continue
|
||||
liker_actor = like_item['actor']
|
||||
liker_display_name = \
|
||||
get_display_name(base_dir, liker_actor, person_cache)
|
||||
if liker_display_name:
|
||||
liker_name = liker_display_name
|
||||
else:
|
||||
liker_name = get_nickname_from_actor(liker_actor)
|
||||
if likers_list:
|
||||
likers_list += ' '
|
||||
likers_list += \
|
||||
'<a href="' + liker_actor + '">' + liker_name + '</a>'
|
||||
html_str += '<center>\n' + likers_list + '\n</center>\n'
|
||||
|
||||
return html_str + html_footer()
|
|
@ -659,6 +659,9 @@ def _get_like_icon_html(nickname: str, domain_full: str,
|
|||
like_str += '</label>\n'
|
||||
like_post_id = remove_hash_from_post_id(post_json_object['id'])
|
||||
like_post_id = remove_id_ending(like_post_id)
|
||||
likers_post_id = like_post_id.replace('/', '--')
|
||||
likers_screen_link = \
|
||||
'/users/' + nickname + '?likers=' + likers_post_id
|
||||
like_str += \
|
||||
' <a class="imageAnchor" href="/users/' + nickname + '?' + \
|
||||
like_link + '=' + like_post_id + \
|
||||
|
@ -666,7 +669,8 @@ def _get_like_icon_html(nickname: str, domain_full: str,
|
|||
'?actor=' + post_json_object['actor'] + \
|
||||
'?bm=' + timeline_post_bookmark + \
|
||||
'?tl=' + box_name + '" title="' + \
|
||||
like_title + like_count_str + '">\n'
|
||||
'<a href=' + "'" + likers_screen_link + "'>" + \
|
||||
like_title + like_count_str + '</a>">\n'
|
||||
like_str += \
|
||||
' ' + \
|
||||
'<img loading="lazy" title="' + like_title + like_count_str + \
|
||||
|
|
Loading…
Reference in New Issue