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)
|
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: {}) -> []:
|
def actor_attached_shares(actor_json: {}) -> []:
|
||||||
"""Returns any shared items attached to an actor
|
"""Returns any shared items attached to an actor
|
||||||
https://codeberg.org/fediverse/fep/src/branch/main/fep/0837/fep-0837.md
|
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 = []
|
attached_shares = []
|
||||||
for attach_item in actor_json['attachment']:
|
for attach_item in actor_json['attachment']:
|
||||||
if 'rel' in attach_item and 'href' in attach_item:
|
if _is_valueflows_attachment(attach_item):
|
||||||
if isinstance(attach_item['rel'], list) and \
|
attached_shares.append(attach_item['href'])
|
||||||
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'])
|
|
||||||
return attached_shares
|
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,
|
def add_shares_to_actor(base_dir: str,
|
||||||
nickname: str, domain: str,
|
nickname: str, domain: str,
|
||||||
actor_json: {},
|
actor_json: {},
|
||||||
|
@ -2258,13 +2285,9 @@ def add_shares_to_actor(base_dir: str,
|
||||||
new_attachment = []
|
new_attachment = []
|
||||||
for attach_item in actor_json['attachment']:
|
for attach_item in actor_json['attachment']:
|
||||||
is_proposal = False
|
is_proposal = False
|
||||||
if 'rel' in attach_item:
|
if _is_valueflows_attachment(attach_item):
|
||||||
if isinstance(attach_item['rel'], list):
|
changed = True
|
||||||
if len(attach_item['rel']) == 2:
|
is_proposal = True
|
||||||
if attach_item['rel'][0] == 'payment' and \
|
|
||||||
attach_item['rel'][1].endswith('/valueflows/Proposal'):
|
|
||||||
changed = True
|
|
||||||
is_proposal = True
|
|
||||||
if not is_proposal:
|
if not is_proposal:
|
||||||
new_attachment.append(attach_item)
|
new_attachment.append(attach_item)
|
||||||
actor_json['attachment'] = new_attachment
|
actor_json['attachment'] = new_attachment
|
||||||
|
|
|
@ -97,6 +97,7 @@ from roles import is_devops
|
||||||
from session import get_json_valid
|
from session import get_json_valid
|
||||||
from session import site_is_verified
|
from session import site_is_verified
|
||||||
from session import get_json
|
from session import get_json
|
||||||
|
from shares import actor_attached_shares_as_html
|
||||||
|
|
||||||
THEME_FORMATS = '.zip, .gz'
|
THEME_FORMATS = '.zip, .gz'
|
||||||
BLOCKFILE_FORMATS = '.csv'
|
BLOCKFILE_FORMATS = '.csv'
|
||||||
|
@ -517,6 +518,7 @@ def _get_profile_header(base_dir: str, http_prefix: str, nickname: str,
|
||||||
theme: str, moved_to: str,
|
theme: str, moved_to: str,
|
||||||
also_known_as: [],
|
also_known_as: [],
|
||||||
pinned_content: str,
|
pinned_content: str,
|
||||||
|
attached_shared_items: str,
|
||||||
access_keys: {},
|
access_keys: {},
|
||||||
joined_date: str,
|
joined_date: str,
|
||||||
occupation_name: str,
|
occupation_name: str,
|
||||||
|
@ -632,6 +634,10 @@ def _get_profile_header(base_dir: str, http_prefix: str, nickname: str,
|
||||||
featured_hashtags + login_button
|
featured_hashtags + login_button
|
||||||
if pinned_content:
|
if pinned_content:
|
||||||
html_str += pinned_content.replace('<p>', '<p>📎', 1)
|
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
|
# show vcard download link
|
||||||
html_str += \
|
html_str += \
|
||||||
|
@ -1113,14 +1119,18 @@ def html_profile(signing_priv_key_pem: str,
|
||||||
'/system/accounts/avatars/',
|
'/system/accounts/avatars/',
|
||||||
'://' + domain_full + '/users/')
|
'://' + domain_full + '/users/')
|
||||||
|
|
||||||
# get pinned post content
|
|
||||||
account_dir = acct_dir(base_dir, nickname, domain)
|
account_dir = acct_dir(base_dir, nickname, domain)
|
||||||
|
# get pinned post content
|
||||||
pinned_filename = account_dir + '/pinToProfile.txt'
|
pinned_filename = account_dir + '/pinToProfile.txt'
|
||||||
pinned_content = None
|
pinned_content = None
|
||||||
if os.path.isfile(pinned_filename):
|
if os.path.isfile(pinned_filename):
|
||||||
with open(pinned_filename, 'r', encoding='utf-8') as pin_file:
|
with open(pinned_filename, 'r', encoding='utf-8') as pin_file:
|
||||||
pinned_content = pin_file.read()
|
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 = \
|
profile_header_str = \
|
||||||
_get_profile_header(base_dir, http_prefix,
|
_get_profile_header(base_dir, http_prefix,
|
||||||
nickname,
|
nickname,
|
||||||
|
@ -1130,8 +1140,10 @@ def html_profile(signing_priv_key_pem: str,
|
||||||
featured_hashtags,
|
featured_hashtags,
|
||||||
login_button, avatar_url, theme,
|
login_button, avatar_url, theme,
|
||||||
moved_to, also_known_as,
|
moved_to, also_known_as,
|
||||||
pinned_content, access_keys,
|
pinned_content,
|
||||||
joined_date, occupation_name,
|
attached_shared_items,
|
||||||
|
access_keys, joined_date,
|
||||||
|
occupation_name,
|
||||||
actor_proxied)
|
actor_proxied)
|
||||||
|
|
||||||
# keyboard navigation
|
# keyboard navigation
|
||||||
|
|
Loading…
Reference in New Issue