mirror of https://gitlab.com/bashrc2/epicyon
Show public shared items on profile
parent
2f51e46119
commit
7e6b43515b
51
shares.py
51
shares.py
|
@ -2224,6 +2224,20 @@ def vf_proposal_from_id(base_dir: str, nickname: str, domain: str,
|
|||
reciprocal_direction)
|
||||
|
||||
|
||||
def _is_valueflows_attachment(attach_item: {}) -> bool:
|
||||
"""Returns true if the given item is a ValueFlows entry
|
||||
within the actor attachment list
|
||||
"""
|
||||
if 'rel' in attach_item and 'href' in attach_item:
|
||||
if isinstance(attach_item['rel'], list) and \
|
||||
isinstance(attach_item['href'], str):
|
||||
if len(attach_item['rel']) == 2:
|
||||
if attach_item['rel'][0] == 'payment' and \
|
||||
attach_item['rel'][1].endswith('/valueflows/Proposal'):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def actor_attached_shares(actor_json: {}) -> []:
|
||||
"""Returns any shared items attached to an actor
|
||||
https://codeberg.org/fediverse/fep/src/branch/main/fep/0837/fep-0837.md
|
||||
|
@ -2233,16 +2247,29 @@ def actor_attached_shares(actor_json: {}) -> []:
|
|||
|
||||
attached_shares = []
|
||||
for attach_item in actor_json['attachment']:
|
||||
if 'rel' in attach_item and 'href' in attach_item:
|
||||
if isinstance(attach_item['rel'], list) and \
|
||||
isinstance(attach_item['href'], str):
|
||||
if len(attach_item['rel']) == 2:
|
||||
if attach_item['rel'][0] == 'payment' and \
|
||||
attach_item['rel'][1].endswith('/valueflows/Proposal'):
|
||||
attached_shares.append(attach_item['href'])
|
||||
if _is_valueflows_attachment(attach_item):
|
||||
attached_shares.append(attach_item['href'])
|
||||
return attached_shares
|
||||
|
||||
|
||||
def actor_attached_shares_as_html(actor_json: {}) -> str:
|
||||
"""Returns html for any shared items attached to an actor
|
||||
https://codeberg.org/fediverse/fep/src/branch/main/fep/0837/fep-0837.md
|
||||
"""
|
||||
if not actor_json.get('attachment'):
|
||||
return ''
|
||||
|
||||
html_str = ''
|
||||
for attach_item in actor_json['attachment']:
|
||||
if _is_valueflows_attachment(attach_item):
|
||||
html_str += \
|
||||
'<a href="' + attach_item['href'] + '" tabindex="1">' + \
|
||||
attach_item['name'] + '</a> '
|
||||
if html_str:
|
||||
html_str = html_str.strip()
|
||||
return html_str
|
||||
|
||||
|
||||
def add_shares_to_actor(base_dir: str,
|
||||
nickname: str, domain: str,
|
||||
actor_json: {},
|
||||
|
@ -2258,13 +2285,9 @@ def add_shares_to_actor(base_dir: str,
|
|||
new_attachment = []
|
||||
for attach_item in actor_json['attachment']:
|
||||
is_proposal = False
|
||||
if 'rel' in attach_item:
|
||||
if isinstance(attach_item['rel'], list):
|
||||
if len(attach_item['rel']) == 2:
|
||||
if attach_item['rel'][0] == 'payment' and \
|
||||
attach_item['rel'][1].endswith('/valueflows/Proposal'):
|
||||
changed = True
|
||||
is_proposal = True
|
||||
if _is_valueflows_attachment(attach_item):
|
||||
changed = True
|
||||
is_proposal = True
|
||||
if not is_proposal:
|
||||
new_attachment.append(attach_item)
|
||||
actor_json['attachment'] = new_attachment
|
||||
|
|
|
@ -97,6 +97,7 @@ from roles import is_devops
|
|||
from session import get_json_valid
|
||||
from session import site_is_verified
|
||||
from session import get_json
|
||||
from shares import actor_attached_shares_as_html
|
||||
|
||||
THEME_FORMATS = '.zip, .gz'
|
||||
BLOCKFILE_FORMATS = '.csv'
|
||||
|
@ -517,6 +518,7 @@ def _get_profile_header(base_dir: str, http_prefix: str, nickname: str,
|
|||
theme: str, moved_to: str,
|
||||
also_known_as: [],
|
||||
pinned_content: str,
|
||||
attached_shared_items: str,
|
||||
access_keys: {},
|
||||
joined_date: str,
|
||||
occupation_name: str,
|
||||
|
@ -632,6 +634,10 @@ def _get_profile_header(base_dir: str, http_prefix: str, nickname: str,
|
|||
featured_hashtags + login_button
|
||||
if pinned_content:
|
||||
html_str += pinned_content.replace('<p>', '<p>📎', 1)
|
||||
if attached_shared_items:
|
||||
html_str += \
|
||||
'<p><b>' + translate['Shares'] + ':</b><br>\n' + \
|
||||
attached_shared_items + '</p>\n'
|
||||
|
||||
# show vcard download link
|
||||
html_str += \
|
||||
|
@ -1113,14 +1119,18 @@ def html_profile(signing_priv_key_pem: str,
|
|||
'/system/accounts/avatars/',
|
||||
'://' + domain_full + '/users/')
|
||||
|
||||
# get pinned post content
|
||||
account_dir = acct_dir(base_dir, nickname, domain)
|
||||
# get pinned post content
|
||||
pinned_filename = account_dir + '/pinToProfile.txt'
|
||||
pinned_content = None
|
||||
if os.path.isfile(pinned_filename):
|
||||
with open(pinned_filename, 'r', encoding='utf-8') as pin_file:
|
||||
pinned_content = pin_file.read()
|
||||
|
||||
# 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)
|
||||
|
||||
profile_header_str = \
|
||||
_get_profile_header(base_dir, http_prefix,
|
||||
nickname,
|
||||
|
@ -1130,8 +1140,10 @@ def html_profile(signing_priv_key_pem: str,
|
|||
featured_hashtags,
|
||||
login_button, avatar_url, theme,
|
||||
moved_to, also_known_as,
|
||||
pinned_content, access_keys,
|
||||
joined_date, occupation_name,
|
||||
pinned_content,
|
||||
attached_shared_items,
|
||||
access_keys, joined_date,
|
||||
occupation_name,
|
||||
actor_proxied)
|
||||
|
||||
# keyboard navigation
|
||||
|
|
Loading…
Reference in New Issue