mirror of https://gitlab.com/bashrc2/epicyon
Display quote toots if permitted
parent
d7e79c7761
commit
b97d35d07e
39
utils.py
39
utils.py
|
@ -4755,16 +4755,16 @@ def save_reverse_timeline(base_dir: str, reverse_sequence: []) -> []:
|
|||
break
|
||||
|
||||
|
||||
def is_quote_toot(post_json_object: str, content: str) -> bool:
|
||||
"""Returns true if the given post is a quote toot / quote tweet
|
||||
def get_quote_toot_url(post_json_object: str) -> str:
|
||||
"""
|
||||
# Pleroma/Misskey implementations
|
||||
if post_json_object['object'].get('quoteUri') or \
|
||||
post_json_object['object'].get('quoteUrl') or \
|
||||
post_json_object['object'].get('quoteReply') or \
|
||||
post_json_object['object'].get('toot:quoteReply') or \
|
||||
post_json_object['object'].get('_misskey_quote'):
|
||||
return True
|
||||
"""
|
||||
# adhoc quote toot implementations
|
||||
object_quote_url_fields = ('quoteUri', 'quoteUrl', 'quoteReply',
|
||||
'toot:quoteReply', '_misskey_quote')
|
||||
for fieldname in object_quote_url_fields:
|
||||
if post_json_object['object'].get(fieldname):
|
||||
return post_json_object['object'][fieldname]
|
||||
|
||||
# More correct ActivityPub implementation - adding a Link tag
|
||||
if post_json_object['object'].get('tag'):
|
||||
if isinstance(post_json_object['object']['tag'], list):
|
||||
|
@ -4772,15 +4772,21 @@ def is_quote_toot(post_json_object: str, content: str) -> bool:
|
|||
if not isinstance(item, dict):
|
||||
continue
|
||||
if item.get('rel'):
|
||||
mk_quote = False
|
||||
if isinstance(item['rel'], list):
|
||||
for rel_str in item['rel']:
|
||||
if not isinstance(rel_str, str):
|
||||
continue
|
||||
if '_misskey_quote' in rel_str:
|
||||
return True
|
||||
mk_quote = True
|
||||
elif isinstance(item['rel'], str):
|
||||
if '_misskey_quote' in item['rel']:
|
||||
return True
|
||||
mk_quote = True
|
||||
if mk_quote:
|
||||
if item.get('href'):
|
||||
if isinstance(item['href'], str):
|
||||
if resembles_url(item['href']):
|
||||
return item['href']
|
||||
if not item.get('type'):
|
||||
continue
|
||||
if not item.get('mediaType'):
|
||||
|
@ -4793,6 +4799,17 @@ def is_quote_toot(post_json_object: str, content: str) -> bool:
|
|||
continue
|
||||
if 'json' not in item['mediaType']:
|
||||
continue
|
||||
if item.get('href'):
|
||||
if isinstance(item['href'], str):
|
||||
if resembles_url(item['href']):
|
||||
return item['href']
|
||||
return ''
|
||||
|
||||
|
||||
def is_quote_toot(post_json_object: str, content: str) -> bool:
|
||||
"""Returns true if the given post is a quote toot / quote tweet
|
||||
"""
|
||||
if get_quote_toot_url(post_json_object):
|
||||
return True
|
||||
# Twitter-style indicator
|
||||
if content:
|
||||
|
|
|
@ -24,6 +24,7 @@ from posts import post_is_muted
|
|||
from posts import get_person_box
|
||||
from posts import download_announce
|
||||
from posts import populate_replies_json
|
||||
from utils import get_quote_toot_url
|
||||
from utils import get_post_attachments
|
||||
from utils import get_url_from_post
|
||||
from utils import date_from_string_format
|
||||
|
@ -2845,6 +2846,17 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
|||
object_content = html_replace_quote_marks(object_content)
|
||||
object_content = \
|
||||
format_mixed_right_to_left(object_content, system_language)
|
||||
# show quote toot link
|
||||
quote_url = get_quote_toot_url(post_json_object)
|
||||
if quote_url:
|
||||
quote_url = quote_url.replace('.json', '')
|
||||
quote_url_shown = quote_url
|
||||
if len(quote_url_shown) > 40:
|
||||
quote_url_shown = quote_url_shown[:40]
|
||||
object_content += '<p>💬 <a href="' + quote_url + \
|
||||
'" target="_blank" ' + \
|
||||
'rel="nofollow noopener noreferrer">' + \
|
||||
quote_url_shown + '</a></p>\n'
|
||||
# append any edits
|
||||
object_content += edits_str
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue