mirror of https://gitlab.com/bashrc2/epicyon
Set featured hashtags from edit profile screen
parent
b8c74cff96
commit
1a6bc85d17
17
daemon.py
17
daemon.py
|
@ -63,6 +63,8 @@ from donate import get_website
|
||||||
from donate import set_website
|
from donate import set_website
|
||||||
from donate import get_gemini_link
|
from donate import get_gemini_link
|
||||||
from donate import set_gemini_link
|
from donate import set_gemini_link
|
||||||
|
from person import get_featured_hashtags
|
||||||
|
from person import set_featured_hashtags
|
||||||
from person import clear_person_qrcodes
|
from person import clear_person_qrcodes
|
||||||
from person import add_alternate_domains
|
from person import add_alternate_domains
|
||||||
from person import add_actor_update_timestamp
|
from person import add_actor_update_timestamp
|
||||||
|
@ -7103,6 +7105,21 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
set_occupation_name(actor_json, '')
|
set_occupation_name(actor_json, '')
|
||||||
actor_changed = True
|
actor_changed = True
|
||||||
|
|
||||||
|
# featured hashtags on edit profile screen
|
||||||
|
featured_hashtags = get_featured_hashtags(actor_json)
|
||||||
|
if fields.get('featuredHashtags'):
|
||||||
|
fields['featuredHashtags'] = \
|
||||||
|
remove_html(fields['featuredHashtags'])
|
||||||
|
if featured_hashtags != \
|
||||||
|
fields['featuredHashtags']:
|
||||||
|
set_featured_hashtags(actor_json,
|
||||||
|
fields['featuredHashtags'])
|
||||||
|
actor_changed = True
|
||||||
|
else:
|
||||||
|
if featured_hashtags:
|
||||||
|
set_featured_hashtags(actor_json, '')
|
||||||
|
actor_changed = True
|
||||||
|
|
||||||
# Other accounts (alsoKnownAs)
|
# Other accounts (alsoKnownAs)
|
||||||
also_known_as = []
|
also_known_as = []
|
||||||
if actor_json.get('alsoKnownAs'):
|
if actor_json.get('alsoKnownAs'):
|
||||||
|
|
78
person.py
78
person.py
|
@ -38,6 +38,7 @@ from roles import set_role
|
||||||
from roles import actor_roles_from_list
|
from roles import actor_roles_from_list
|
||||||
from roles import get_actor_roles_list
|
from roles import get_actor_roles_list
|
||||||
from media import process_meta_data
|
from media import process_meta_data
|
||||||
|
from utils import valid_hash_tag
|
||||||
from utils import acct_handle_dir
|
from utils import acct_handle_dir
|
||||||
from utils import safe_system_string
|
from utils import safe_system_string
|
||||||
from utils import get_attachment_property_value
|
from utils import get_attachment_property_value
|
||||||
|
@ -1904,3 +1905,80 @@ def valid_sending_actor(session, base_dir: str,
|
||||||
store_person_in_cache(base_dir, sending_actor, actor_json,
|
store_person_in_cache(base_dir, sending_actor, actor_json,
|
||||||
person_cache, False)
|
person_cache, False)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def get_featured_hashtags(actor_json: {}) -> str:
|
||||||
|
"""returns a string containing featured hashtags
|
||||||
|
"""
|
||||||
|
result = ''
|
||||||
|
if not actor_json.get('tag'):
|
||||||
|
return result
|
||||||
|
if not isinstance(actor_json['tag'], list):
|
||||||
|
return result
|
||||||
|
for tag_dict in actor_json['tag']:
|
||||||
|
if not tag_dict.get('type'):
|
||||||
|
continue
|
||||||
|
if not isinstance(tag_dict['type'], str):
|
||||||
|
continue
|
||||||
|
if not tag_dict['type'].endswith('Hashtag'):
|
||||||
|
continue
|
||||||
|
if not tag_dict.get('name'):
|
||||||
|
continue
|
||||||
|
if not isinstance(tag_dict['name'], str):
|
||||||
|
continue
|
||||||
|
if not tag_dict.get('href'):
|
||||||
|
continue
|
||||||
|
if not isinstance(tag_dict['href'], str):
|
||||||
|
continue
|
||||||
|
tag_name = tag_dict['name']
|
||||||
|
if not tag_name:
|
||||||
|
continue
|
||||||
|
if tag_name.startswith('#'):
|
||||||
|
tag_name = tag_name[1:]
|
||||||
|
if not tag_name:
|
||||||
|
continue
|
||||||
|
tag_url = tag_dict['href']
|
||||||
|
if '://' not in tag_url or '.' not in tag_url:
|
||||||
|
continue
|
||||||
|
if not valid_hash_tag(tag_name):
|
||||||
|
continue
|
||||||
|
result += '#' + tag_name + ' '
|
||||||
|
return result.strip()
|
||||||
|
|
||||||
|
|
||||||
|
def set_featured_hashtags(actor_json: {}, hashtags: str) -> None:
|
||||||
|
"""sets featured hashtags
|
||||||
|
"""
|
||||||
|
separator_str = ' '
|
||||||
|
separators = (' ', ',')
|
||||||
|
for separator_str in separators:
|
||||||
|
if separator_str in hashtags:
|
||||||
|
break
|
||||||
|
tag_list = hashtags.split(separator_str)
|
||||||
|
result = []
|
||||||
|
tags_used = []
|
||||||
|
for tag_str in tag_list:
|
||||||
|
if not tag_str:
|
||||||
|
continue
|
||||||
|
if not tag_str.startswith('#'):
|
||||||
|
tag_str = '#' + tag_str
|
||||||
|
if tag_str in tags_used:
|
||||||
|
continue
|
||||||
|
url = \
|
||||||
|
actor_json['id'] + '/tags/' + tag_str.replace('#', '')
|
||||||
|
result.append({
|
||||||
|
"name": tag_str,
|
||||||
|
"type": "Hashtag",
|
||||||
|
"href": url
|
||||||
|
})
|
||||||
|
tags_used.append(tag_str)
|
||||||
|
# add any non-hashtags to the result
|
||||||
|
if actor_json.get('tag'):
|
||||||
|
for tag_dict in actor_json['tag']:
|
||||||
|
if not tag_dict.get('type'):
|
||||||
|
continue
|
||||||
|
if not isinstance(tag_dict['type'], str):
|
||||||
|
continue
|
||||||
|
if tag_dict['type'] != 'Hashtag':
|
||||||
|
result.append(tag_dict)
|
||||||
|
actor_json['tag'] = result
|
||||||
|
|
|
@ -10,7 +10,6 @@ __module_group__ = "Web Interface"
|
||||||
import os
|
import os
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
from webfinger import webfinger_handle
|
from webfinger import webfinger_handle
|
||||||
from utils import valid_hash_tag
|
|
||||||
from utils import remove_id_ending
|
from utils import remove_id_ending
|
||||||
from utils import standardize_text
|
from utils import standardize_text
|
||||||
from utils import get_display_name
|
from utils import get_display_name
|
||||||
|
@ -37,6 +36,7 @@ from utils import remove_eol
|
||||||
from languages import get_actor_languages
|
from languages import get_actor_languages
|
||||||
from skills import get_skills
|
from skills import get_skills
|
||||||
from theme import get_themes_list
|
from theme import get_themes_list
|
||||||
|
from person import get_featured_hashtags
|
||||||
from person import person_box_json
|
from person import person_box_json
|
||||||
from person import get_actor_json
|
from person import get_actor_json
|
||||||
from person import get_person_avatar_url
|
from person import get_person_avatar_url
|
||||||
|
@ -2576,45 +2576,6 @@ def _html_edit_profile_top_banner(base_dir: str,
|
||||||
return edit_profile_form
|
return edit_profile_form
|
||||||
|
|
||||||
|
|
||||||
def _get_featured_hashtags(actor_json: {}) -> str:
|
|
||||||
"""returns a string containing featured hashtags
|
|
||||||
"""
|
|
||||||
result = ''
|
|
||||||
if not actor_json.get('tag'):
|
|
||||||
return result
|
|
||||||
if not isinstance(actor_json['tag'], list):
|
|
||||||
return result
|
|
||||||
for tag_dict in actor_json['tag']:
|
|
||||||
if not tag_dict.get('type'):
|
|
||||||
continue
|
|
||||||
if not isinstance(tag_dict['type'], str):
|
|
||||||
continue
|
|
||||||
if not tag_dict['type'].endswith('Hashtag'):
|
|
||||||
continue
|
|
||||||
if not tag_dict.get('name'):
|
|
||||||
continue
|
|
||||||
if not isinstance(tag_dict['name'], str):
|
|
||||||
continue
|
|
||||||
if not tag_dict.get('href'):
|
|
||||||
continue
|
|
||||||
if not isinstance(tag_dict['href'], str):
|
|
||||||
continue
|
|
||||||
tag_name = tag_dict['name']
|
|
||||||
if not tag_name:
|
|
||||||
continue
|
|
||||||
if tag_name.startswith('#'):
|
|
||||||
tag_name = tag_name[1:]
|
|
||||||
if not tag_name:
|
|
||||||
continue
|
|
||||||
tag_url = tag_dict['href']
|
|
||||||
if '://' not in tag_url or '.' not in tag_url:
|
|
||||||
continue
|
|
||||||
if not valid_hash_tag(tag_name):
|
|
||||||
continue
|
|
||||||
result += '#' + tag_name + ' '
|
|
||||||
return result.strip()
|
|
||||||
|
|
||||||
|
|
||||||
def html_edit_profile(server, translate: {},
|
def html_edit_profile(server, translate: {},
|
||||||
base_dir: str, path: str,
|
base_dir: str, path: str,
|
||||||
domain: str, port: int,
|
domain: str, port: int,
|
||||||
|
@ -2668,7 +2629,7 @@ def html_edit_profile(server, translate: {},
|
||||||
if actor_json:
|
if actor_json:
|
||||||
if actor_json.get('movedTo'):
|
if actor_json.get('movedTo'):
|
||||||
moved_to = actor_json['movedTo']
|
moved_to = actor_json['movedTo']
|
||||||
featured_hashtags = _get_featured_hashtags(actor_json)
|
featured_hashtags = get_featured_hashtags(actor_json)
|
||||||
donate_url = get_donation_url(actor_json)
|
donate_url = get_donation_url(actor_json)
|
||||||
website_url = get_website(actor_json, translate)
|
website_url = get_website(actor_json, translate)
|
||||||
gemini_link = get_gemini_link(actor_json, translate)
|
gemini_link = get_gemini_link(actor_json, translate)
|
||||||
|
|
Loading…
Reference in New Issue