mirror of https://gitlab.com/bashrc2/epicyon
Add missing name emojis to actor tag list
parent
4ad132ae07
commit
4a906f143f
75
content.py
75
content.py
|
@ -15,6 +15,7 @@ import email.parser
|
|||
import urllib.parse
|
||||
from shutil import copyfile
|
||||
from dateutil.parser import parse
|
||||
from utils import get_full_domain
|
||||
from utils import get_user_paths
|
||||
from utils import convert_published_to_local_timezone
|
||||
from utils import has_object_dict
|
||||
|
@ -1998,3 +1999,77 @@ def reject_twitter_summary(base_dir: str, nickname: str, domain: str,
|
|||
'birdsite' in summary_lower:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def add_name_emojis_to_tags(base_dir: str, http_prefix: str,
|
||||
domain: str, port: int,
|
||||
actor_json: {}) -> None:
|
||||
"""Add any custom emojis within the name of an actor to
|
||||
the tag list
|
||||
"""
|
||||
if not actor_json.get('name'):
|
||||
return
|
||||
name = actor_json['name']
|
||||
|
||||
# does the name contain an emoji?
|
||||
if ':' not in name:
|
||||
return
|
||||
if ':' not in name.split(':', 1)[1]:
|
||||
return
|
||||
|
||||
# get emojis from the actor name
|
||||
words = name.split(' ')
|
||||
emojis = []
|
||||
for wrd in words:
|
||||
if wrd.startswith(':') and wrd.endswith(':'):
|
||||
if wrd not in emojis:
|
||||
emojis.append(wrd)
|
||||
if not emojis:
|
||||
return
|
||||
|
||||
actor_tags = []
|
||||
if actor_json.get('tag'):
|
||||
actor_tags = actor_json['tag']
|
||||
|
||||
# is the emoji already in the tag list?
|
||||
for tag_dict in actor_tags:
|
||||
if not tag_dict.get('type'):
|
||||
continue
|
||||
if tag_dict['type'] != 'Emoji':
|
||||
continue
|
||||
if not tag_dict.get('name'):
|
||||
continue
|
||||
if not tag_dict['name'].startswith(':'):
|
||||
continue
|
||||
if not tag_dict['name'].endswith(':'):
|
||||
continue
|
||||
if tag_dict['name'] in emojis:
|
||||
emojis.remove(tag_dict['name'])
|
||||
if not emojis:
|
||||
return
|
||||
|
||||
domain_full = get_full_domain(domain, port)
|
||||
for emoji_tag_name in emojis:
|
||||
emoji_name = emoji_tag_name.replace(':', '')
|
||||
emoji_id = \
|
||||
http_prefix + '://' + domain_full + '/emoji/' + \
|
||||
emoji_name
|
||||
url = emoji_id + '.png'
|
||||
emoji_filename = base_dir + '/emoji/' + emoji_name + '.png'
|
||||
updated = None
|
||||
if os.path.isfile(emoji_filename):
|
||||
updated = file_last_modified(emoji_filename)
|
||||
new_tag = {
|
||||
'icon': {
|
||||
'mediaType': 'image/png',
|
||||
'type': 'Image',
|
||||
'url': url
|
||||
},
|
||||
'id': emoji_id,
|
||||
'name': emoji_tag_name,
|
||||
'type': 'Emoji',
|
||||
'updated': '2022-11-15T23:45:42Z'
|
||||
}
|
||||
if updated:
|
||||
new_tag['updated'] = updated
|
||||
actor_json['tag'].append(new_tag)
|
||||
|
|
|
@ -346,6 +346,7 @@ from utils import has_group_type
|
|||
from manualapprove import manual_deny_follow_request_thread
|
||||
from manualapprove import manual_approve_follow_request_thread
|
||||
from announce import create_announce
|
||||
from content import add_name_emojis_to_tags
|
||||
from content import load_dogwhistles
|
||||
from content import valid_url_lengths
|
||||
from content import contains_invalid_local_links
|
||||
|
@ -6816,6 +6817,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
actor_changed = True
|
||||
|
||||
# change user bio
|
||||
actor_json['tag'] = []
|
||||
if fields.get('bio'):
|
||||
if fields['bio'] != actor_json['summary']:
|
||||
bio_str = remove_html(fields['bio'])
|
||||
|
@ -6831,7 +6833,6 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
bio_str, [], actor_tags,
|
||||
self.server.translate)
|
||||
if actor_tags:
|
||||
actor_json['tag'] = []
|
||||
for _, tag in actor_tags.items():
|
||||
actor_json['tag'].append(tag)
|
||||
actor_changed = True
|
||||
|
@ -7695,6 +7696,9 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
|
||||
# save actor json file within accounts
|
||||
if actor_changed:
|
||||
add_name_emojis_to_tags(base_dir, http_prefix,
|
||||
domain, self.server.port,
|
||||
actor_json)
|
||||
# update the context for the actor
|
||||
actor_json['@context'] = [
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
|
|
18
tests.py
18
tests.py
|
@ -135,6 +135,7 @@ from inbox import valid_inbox
|
|||
from inbox import valid_inbox_filenames
|
||||
from inbox import cache_svg_images
|
||||
from categories import guess_hashtag_category
|
||||
from content import add_name_emojis_to_tags
|
||||
from content import combine_textarea_lines
|
||||
from content import detect_dogwhistles
|
||||
from content import remove_script
|
||||
|
@ -7591,6 +7592,22 @@ def _test_uninvert():
|
|||
assert result == expected
|
||||
|
||||
|
||||
def _test_emoji_in_actor_name(base_dir: str) -> None:
|
||||
print('test_emoji_in_actor_name')
|
||||
actor_json = {
|
||||
'name': 'First Sea Lord Wibbles :verified:',
|
||||
'tag': []
|
||||
}
|
||||
http_prefix = 'https'
|
||||
domain = 'fluffysupernova.city'
|
||||
port = 443
|
||||
add_name_emojis_to_tags(base_dir, http_prefix,
|
||||
domain, port, actor_json)
|
||||
assert len(actor_json['tag']) == 1
|
||||
assert actor_json['tag'][0].get('updated')
|
||||
assert actor_json['tag'][0]['name'] == ':verified:'
|
||||
|
||||
|
||||
def run_all_tests():
|
||||
base_dir = os.getcwd()
|
||||
print('Running tests...')
|
||||
|
@ -7608,6 +7625,7 @@ def run_all_tests():
|
|||
_test_checkbox_names()
|
||||
_test_thread_functions()
|
||||
_test_functions()
|
||||
_test_emoji_in_actor_name(base_dir)
|
||||
_test_uninvert()
|
||||
_test_hashtag_maps()
|
||||
_test_combine_lines()
|
||||
|
|
Loading…
Reference in New Issue