mirror of https://gitlab.com/bashrc2/epicyon
Full url for mentions
parent
2477618d69
commit
a8134f3243
50
content.py
50
content.py
|
@ -15,6 +15,7 @@ import email.parser
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
|
from utils import get_user_paths
|
||||||
from utils import convert_published_to_local_timezone
|
from utils import convert_published_to_local_timezone
|
||||||
from utils import has_object_dict
|
from utils import has_object_dict
|
||||||
from utils import valid_hash_tag
|
from utils import valid_hash_tag
|
||||||
|
@ -742,8 +743,28 @@ def post_tag_exists(tagType: str, tagName: str, tags: {}) -> bool:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def _add_mention(word_str: str, http_prefix: str, following: [],
|
def _mention_to_url(base_dir: str, http_prefix: str,
|
||||||
petnames: [], replace_mentions: {},
|
domain: str, nickname: str) -> str:
|
||||||
|
"""Convert https://somedomain/@somenick to
|
||||||
|
https://somedomain/users/somenick
|
||||||
|
This uses the hack of trying the cache directory to see if
|
||||||
|
there is a matching actor
|
||||||
|
"""
|
||||||
|
possible_paths = get_user_paths()
|
||||||
|
cache_dir = base_dir + '/cache/actors'
|
||||||
|
cache_path_start = cache_dir + '/' + http_prefix + ':##' + domain
|
||||||
|
for users_path in possible_paths:
|
||||||
|
users_path = users_path.replace('/', '#')
|
||||||
|
possible_cache_entry = \
|
||||||
|
cache_path_start + users_path + nickname + '.json'
|
||||||
|
if os.path.isfile(possible_cache_entry):
|
||||||
|
return http_prefix + '://' + \
|
||||||
|
domain + users_path.replace('#', '/') + nickname
|
||||||
|
return http_prefix + '://' + domain + '/users/' + nickname
|
||||||
|
|
||||||
|
|
||||||
|
def _add_mention(base_dir: str, word_str: str, http_prefix: str,
|
||||||
|
following: [], petnames: [], replace_mentions: {},
|
||||||
recipients: [], tags: {}) -> bool:
|
recipients: [], tags: {}) -> bool:
|
||||||
"""Detects mentions and adds them to the replacements dict and
|
"""Detects mentions and adds them to the replacements dict and
|
||||||
recipients list
|
recipients list
|
||||||
|
@ -761,8 +782,9 @@ def _add_mention(word_str: str, http_prefix: str, following: [],
|
||||||
if possible_nickname == follow_nick:
|
if possible_nickname == follow_nick:
|
||||||
follow_str = remove_eol(follow)
|
follow_str = remove_eol(follow)
|
||||||
replace_domain = follow_str.split('@')[1]
|
replace_domain = follow_str.split('@')[1]
|
||||||
recipient_actor = http_prefix + "://" + \
|
recipient_actor = \
|
||||||
replace_domain + "/@" + possible_nickname
|
_mention_to_url(base_dir, http_prefix,
|
||||||
|
replace_domain, possible_nickname)
|
||||||
if recipient_actor not in recipients:
|
if recipient_actor not in recipients:
|
||||||
recipients.append(recipient_actor)
|
recipients.append(recipient_actor)
|
||||||
tags[word_str] = {
|
tags[word_str] = {
|
||||||
|
@ -787,8 +809,9 @@ def _add_mention(word_str: str, http_prefix: str, following: [],
|
||||||
follow_str = remove_eol(follow)
|
follow_str = remove_eol(follow)
|
||||||
replace_nickname = follow_str.split('@')[0]
|
replace_nickname = follow_str.split('@')[0]
|
||||||
replace_domain = follow_str.split('@')[1]
|
replace_domain = follow_str.split('@')[1]
|
||||||
recipient_actor = http_prefix + "://" + \
|
recipient_actor = \
|
||||||
replace_domain + "/@" + replace_nickname
|
_mention_to_url(base_dir, http_prefix,
|
||||||
|
replace_domain, replace_nickname)
|
||||||
if recipient_actor not in recipients:
|
if recipient_actor not in recipients:
|
||||||
recipients.append(recipient_actor)
|
recipients.append(recipient_actor)
|
||||||
tags[word_str] = {
|
tags[word_str] = {
|
||||||
|
@ -819,8 +842,9 @@ def _add_mention(word_str: str, http_prefix: str, following: [],
|
||||||
for follow in following:
|
for follow in following:
|
||||||
if remove_eol(follow) != possible_handle:
|
if remove_eol(follow) != possible_handle:
|
||||||
continue
|
continue
|
||||||
recipient_actor = http_prefix + "://" + \
|
recipient_actor = \
|
||||||
possible_domain + "/@" + possible_nickname
|
_mention_to_url(base_dir, http_prefix,
|
||||||
|
possible_domain, possible_nickname)
|
||||||
if recipient_actor not in recipients:
|
if recipient_actor not in recipients:
|
||||||
recipients.append(recipient_actor)
|
recipients.append(recipient_actor)
|
||||||
tags[word_str] = {
|
tags[word_str] = {
|
||||||
|
@ -836,8 +860,9 @@ def _add_mention(word_str: str, http_prefix: str, following: [],
|
||||||
# @nick@domain
|
# @nick@domain
|
||||||
if not (possible_domain == 'localhost' or '.' in possible_domain):
|
if not (possible_domain == 'localhost' or '.' in possible_domain):
|
||||||
return False
|
return False
|
||||||
recipient_actor = http_prefix + "://" + \
|
recipient_actor = \
|
||||||
possible_domain + "/@" + possible_nickname
|
_mention_to_url(base_dir, http_prefix,
|
||||||
|
possible_domain, possible_nickname)
|
||||||
if recipient_actor not in recipients:
|
if recipient_actor not in recipients:
|
||||||
recipients.append(recipient_actor)
|
recipients.append(recipient_actor)
|
||||||
tags[word_str] = {
|
tags[word_str] = {
|
||||||
|
@ -1221,8 +1246,9 @@ def add_html_tags(base_dir: str, http_prefix: str,
|
||||||
long_words_list.append(word_str)
|
long_words_list.append(word_str)
|
||||||
first_char = word_str[0]
|
first_char = word_str[0]
|
||||||
if first_char == '@':
|
if first_char == '@':
|
||||||
if _add_mention(word_str, http_prefix, following, petnames,
|
if _add_mention(base_dir, word_str, http_prefix, following,
|
||||||
replace_mentions, recipients, hashtags):
|
petnames, replace_mentions, recipients,
|
||||||
|
hashtags):
|
||||||
prev_word_str = ''
|
prev_word_str = ''
|
||||||
continue
|
continue
|
||||||
elif first_char == '#':
|
elif first_char == '#':
|
||||||
|
|
5
tests.py
5
tests.py
|
@ -4697,7 +4697,7 @@ def _test_reply_to_public_post(base_dir: str) -> None:
|
||||||
# print(str(reply))
|
# print(str(reply))
|
||||||
expected_str = \
|
expected_str = \
|
||||||
'<p><span class=\"h-card\">' + \
|
'<p><span class=\"h-card\">' + \
|
||||||
'<a href=\"https://rat.site/@ninjarodent\" tabindex="10" ' + \
|
'<a href=\"https://rat.site/users/ninjarodent\" tabindex="10" ' + \
|
||||||
'class=\"u-url mention\">@<span>ninjarodent</span>' + \
|
'class=\"u-url mention\">@<span>ninjarodent</span>' + \
|
||||||
'</a></span> This is a test.</p>'
|
'</a></span> This is a test.</p>'
|
||||||
if reply['object']['content'] != expected_str:
|
if reply['object']['content'] != expected_str:
|
||||||
|
@ -4707,7 +4707,8 @@ def _test_reply_to_public_post(base_dir: str) -> None:
|
||||||
reply['object']['contentMap'][system_language] = reply['object']['content']
|
reply['object']['contentMap'][system_language] = reply['object']['content']
|
||||||
assert reply['object']['tag'][0]['type'] == 'Mention'
|
assert reply['object']['tag'][0]['type'] == 'Mention'
|
||||||
assert reply['object']['tag'][0]['name'] == '@ninjarodent@rat.site'
|
assert reply['object']['tag'][0]['name'] == '@ninjarodent@rat.site'
|
||||||
assert reply['object']['tag'][0]['href'] == 'https://rat.site/@ninjarodent'
|
assert reply['object']['tag'][0]['href'] == \
|
||||||
|
'https://rat.site/users/ninjarodent'
|
||||||
assert len(reply['object']['to']) == 1
|
assert len(reply['object']['to']) == 1
|
||||||
assert reply['object']['to'][0].endswith('#Public')
|
assert reply['object']['to'][0].endswith('#Public')
|
||||||
assert len(reply['object']['cc']) >= 1
|
assert len(reply['object']['cc']) >= 1
|
||||||
|
|
Loading…
Reference in New Issue