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