mirror of https://gitlab.com/bashrc2/epicyon
Function to show edits to a post
parent
e286cf8661
commit
c4fbdda58d
50
content.py
50
content.py
|
@ -14,6 +14,9 @@ import os
|
|||
import email.parser
|
||||
import urllib.parse
|
||||
from shutil import copyfile
|
||||
from dateutil.parser import parse
|
||||
from utils import convert_published_to_local_timezone
|
||||
from utils import has_object_dict
|
||||
from utils import valid_hash_tag
|
||||
from utils import dangerous_svg
|
||||
from utils import remove_domain_port
|
||||
|
@ -1460,8 +1463,55 @@ def content_diff(content: str, prev_content: str) -> str:
|
|||
diff_text += reference_text[ctr]
|
||||
ctr += 1
|
||||
|
||||
if state == 1:
|
||||
diff_text += '</label>'
|
||||
|
||||
while ctr < len(reference_text):
|
||||
diff_text += reference_text[ctr]
|
||||
ctr += 1
|
||||
diff_content = diff_content.replace(reference_text, diff_text)
|
||||
return diff_content
|
||||
|
||||
|
||||
def create_edits_html(edits_json: {}, post_json_object: {},
|
||||
translate: {}, timezone: str) -> str:
|
||||
""" Creates html showing historical edits made to a post
|
||||
"""
|
||||
if not edits_json:
|
||||
return ''
|
||||
if not has_object_dict(post_json_object):
|
||||
return ''
|
||||
if not post_json_object['object'].get('content'):
|
||||
return ''
|
||||
edit_dates_list = []
|
||||
for modified, item in edits_json.items():
|
||||
edit_dates_list.append(modified)
|
||||
edit_dates_list.sort(reverse=True)
|
||||
edits_str = ''
|
||||
content = remove_html(post_json_object['object']['content'])
|
||||
for modified in edit_dates_list:
|
||||
prev_json = edits_json[modified]
|
||||
if not has_object_dict(prev_json):
|
||||
continue
|
||||
if not prev_json['object'].get('content'):
|
||||
continue
|
||||
prev_content = remove_html(prev_json['object']['content'])
|
||||
if content == prev_content:
|
||||
continue
|
||||
diff = content_diff(content, prev_content)
|
||||
if not diff:
|
||||
continue
|
||||
diff = diff.replace('\n', '</p><p>')
|
||||
# convert to local time
|
||||
datetime_object = parse(modified)
|
||||
datetime_object = \
|
||||
convert_published_to_local_timezone(datetime_object, timezone)
|
||||
modified_str = datetime_object.strftime("%a %b %d, %H:%M")
|
||||
diff = '<p><b>' + modified_str + '</b></p><p>' + diff + '</p>'
|
||||
edits_str += diff
|
||||
content = prev_content
|
||||
if not edits_str:
|
||||
return ''
|
||||
return '<br><details><summary class="cw">' + \
|
||||
translate['SHOW EDITS'] + '</summary>' + \
|
||||
edits_str + '</details>\n'
|
||||
|
|
|
@ -262,6 +262,16 @@ mark {
|
|||
font-weight: bold;
|
||||
}
|
||||
|
||||
.diff_add {
|
||||
color: var(--main-link-color);
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.diff_remove {
|
||||
color: var(--title-color);
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.accesskeys {
|
||||
border: 0;
|
||||
width: 100%;
|
||||
|
|
|
@ -519,5 +519,6 @@
|
|||
"Web Bots Allowed": "مسموح روبوتات الويب",
|
||||
"Known Search Bots": "روبوتات بحث الويب المعروفة",
|
||||
"mitm": "يمكن قراءة الرسالة أو تعديلها من قبل طرف ثالث",
|
||||
"Bold reading": "قراءة جريئة"
|
||||
"Bold reading": "قراءة جريئة",
|
||||
"SHOW EDITS": "عرض التعديلات"
|
||||
}
|
||||
|
|
|
@ -519,5 +519,6 @@
|
|||
"Web Bots Allowed": "Bots web permesos",
|
||||
"Known Search Bots": "Bots de cerca web coneguts",
|
||||
"mitm": "El missatge podria haver estat llegit o modificat per un tercer",
|
||||
"Bold reading": "Lectura atrevida"
|
||||
"Bold reading": "Lectura atrevida",
|
||||
"SHOW EDITS": "MOSTRA EDICIONS"
|
||||
}
|
||||
|
|
|
@ -519,5 +519,6 @@
|
|||
"Web Bots Allowed": "Web Bots a Ganiateir",
|
||||
"Known Search Bots": "Bots Chwilio Gwe Hysbys",
|
||||
"mitm": "Gallai'r neges fod wedi cael ei darllen neu ei haddasu gan drydydd parti",
|
||||
"Bold reading": "Darllen beiddgar"
|
||||
"Bold reading": "Darllen beiddgar",
|
||||
"SHOW EDITS": "GOLYGIADAU SIOE"
|
||||
}
|
||||
|
|
|
@ -519,5 +519,6 @@
|
|||
"Web Bots Allowed": "Webbots erlaubt",
|
||||
"Known Search Bots": "Bekannte Bots für die Websuche",
|
||||
"mitm": "Die Nachricht könnte von einem Dritten gelesen oder geändert worden sein",
|
||||
"Bold reading": "Mutige Lektüre"
|
||||
"Bold reading": "Mutige Lektüre",
|
||||
"SHOW EDITS": "BEARBEITUNGEN ZEIGEN"
|
||||
}
|
||||
|
|
|
@ -519,5 +519,6 @@
|
|||
"Web Bots Allowed": "Web Search Bots Allowed",
|
||||
"Known Search Bots": "Known Web Search Bots",
|
||||
"mitm": "Message could have been read or modified by a third party",
|
||||
"Bold reading": "Bold reading"
|
||||
"Bold reading": "Bold reading",
|
||||
"SHOW EDITS": "SHOW EDITS"
|
||||
}
|
||||
|
|
|
@ -519,5 +519,6 @@
|
|||
"Web Bots Allowed": "Bots web permitidos",
|
||||
"Known Search Bots": "Bots de búsqueda web conocidos",
|
||||
"mitm": "El mensaje podría haber sido leído o modificado por un tercero",
|
||||
"Bold reading": "Lectura en negrita"
|
||||
"Bold reading": "Lectura en negrita",
|
||||
"SHOW EDITS": "MOSTRAR EDICIONES"
|
||||
}
|
||||
|
|
|
@ -519,5 +519,6 @@
|
|||
"Web Bots Allowed": "Robots Web autorisés",
|
||||
"Known Search Bots": "Robots de recherche Web connus",
|
||||
"mitm": "Le message a pu être lu ou modifié par un tiers",
|
||||
"Bold reading": "Lecture audacieuse"
|
||||
"Bold reading": "Lecture audacieuse",
|
||||
"SHOW EDITS": "AFFICHER LES MODIFICATIONS"
|
||||
}
|
||||
|
|
|
@ -519,5 +519,6 @@
|
|||
"Web Bots Allowed": "Róbónna Gréasáin Ceadaithe",
|
||||
"Known Search Bots": "Róbónna Cuardach Gréasáin Aitheanta",
|
||||
"mitm": "D'fhéadfadh tríú páirtí an teachtaireacht a léamh nó a mhodhnú",
|
||||
"Bold reading": "Léamh trom"
|
||||
"Bold reading": "Léamh trom",
|
||||
"SHOW EDITS": "EAGARTHÓIRÍ TAISPEÁINT"
|
||||
}
|
||||
|
|
|
@ -519,5 +519,6 @@
|
|||
"Web Bots Allowed": "वेब बॉट्स की अनुमति है",
|
||||
"Known Search Bots": "ज्ञात वेब खोज बॉट्स",
|
||||
"mitm": "संदेश किसी तीसरे पक्ष द्वारा पढ़ा या संशोधित किया जा सकता था",
|
||||
"Bold reading": "बोल्ड रीडिंग"
|
||||
"Bold reading": "बोल्ड रीडिंग",
|
||||
"SHOW EDITS": "संपादन दिखाएं"
|
||||
}
|
||||
|
|
|
@ -519,5 +519,6 @@
|
|||
"Web Bots Allowed": "Web bot consentiti",
|
||||
"Known Search Bots": "Bot di ricerca Web noti",
|
||||
"mitm": "Il messaggio potrebbe essere stato letto o modificato da terzi",
|
||||
"Bold reading": "Lettura audace"
|
||||
"Bold reading": "Lettura audace",
|
||||
"SHOW EDITS": "MOSTRA MODIFICHE"
|
||||
}
|
||||
|
|
|
@ -519,5 +519,6 @@
|
|||
"Web Bots Allowed": "許可されたWebボット",
|
||||
"Known Search Bots": "既知のWeb検索ボット",
|
||||
"mitm": "メッセージが第三者によって読み取られたり変更されたりした可能性があります",
|
||||
"Bold reading": "大胆な読書"
|
||||
"Bold reading": "大胆な読書",
|
||||
"SHOW EDITS": "編集を表示"
|
||||
}
|
||||
|
|
|
@ -519,5 +519,6 @@
|
|||
"Web Bots Allowed": "웹 봇 허용",
|
||||
"Known Search Bots": "알려진 웹 검색 봇",
|
||||
"mitm": "제3자가 메시지를 읽거나 수정했을 수 있습니다.",
|
||||
"Bold reading": "굵은 글씨"
|
||||
"Bold reading": "굵은 글씨",
|
||||
"SHOW EDITS": "수정사항 보기"
|
||||
}
|
||||
|
|
|
@ -519,5 +519,6 @@
|
|||
"Web Bots Allowed": "Web Bots Destûrdar in",
|
||||
"Known Search Bots": "Botên Lêgerîna Webê yên naskirî",
|
||||
"mitm": "Peyam dikaribû ji hêla aliyek sêyemîn ve were xwendin an guhertin",
|
||||
"Bold reading": "Xwendina qelew"
|
||||
"Bold reading": "Xwendina qelew",
|
||||
"SHOW EDITS": "GERÎŞTAN NÎŞAN DE"
|
||||
}
|
||||
|
|
|
@ -515,5 +515,6 @@
|
|||
"Web Bots Allowed": "Web Search Bots Allowed",
|
||||
"Known Search Bots": "Known Web Search Bots",
|
||||
"mitm": "Message could have been read or modified by a third party",
|
||||
"Bold reading": "Bold reading"
|
||||
"Bold reading": "Bold reading",
|
||||
"SHOW EDITS": "SHOW EDITS"
|
||||
}
|
||||
|
|
|
@ -519,5 +519,6 @@
|
|||
"Web Bots Allowed": "Dozwolone boty internetowe",
|
||||
"Known Search Bots": "Znane boty wyszukiwania w sieci",
|
||||
"mitm": "Wiadomość mogła zostać przeczytana lub zmodyfikowana przez osobę trzecią",
|
||||
"Bold reading": "Odważne czytanie"
|
||||
"Bold reading": "Odważne czytanie",
|
||||
"SHOW EDITS": "POKAŻ EDYCJE"
|
||||
}
|
||||
|
|
|
@ -519,5 +519,6 @@
|
|||
"Web Bots Allowed": "Webbots permitidos",
|
||||
"Known Search Bots": "Bots de pesquisa na Web conhecidos",
|
||||
"mitm": "A mensagem pode ter sido lida ou modificada por terceiros",
|
||||
"Bold reading": "Leitura em negrito"
|
||||
"Bold reading": "Leitura em negrito",
|
||||
"SHOW EDITS": "MOSTRAR EDIÇÕES"
|
||||
}
|
||||
|
|
|
@ -519,5 +519,6 @@
|
|||
"Web Bots Allowed": "Веб-боты разрешены",
|
||||
"Known Search Bots": "Известные боты веб-поиска",
|
||||
"mitm": "Сообщение могло быть прочитано или изменено третьим лицом",
|
||||
"Bold reading": "Смелое чтение"
|
||||
"Bold reading": "Смелое чтение",
|
||||
"SHOW EDITS": "ПОКАЗАТЬ РЕДАКТИРОВАНИЕ"
|
||||
}
|
||||
|
|
|
@ -519,5 +519,6 @@
|
|||
"Web Bots Allowed": "Mtandao wa Boti Unaruhusiwa",
|
||||
"Known Search Bots": "Vijibu vya Utafutaji wa Wavuti vinavyojulikana",
|
||||
"mitm": "Ujumbe ungeweza kusomwa au kurekebishwa na mtu mwingine",
|
||||
"Bold reading": "Kusoma kwa ujasiri"
|
||||
"Bold reading": "Kusoma kwa ujasiri",
|
||||
"SHOW EDITS": "ONYESHA MABADILIKO"
|
||||
}
|
||||
|
|
|
@ -519,5 +519,6 @@
|
|||
"Web Bots Allowed": "Веб-боти дозволені",
|
||||
"Known Search Bots": "Відомі пошукові роботи в Інтернеті",
|
||||
"mitm": "Повідомлення могло бути прочитане або змінене третьою стороною",
|
||||
"Bold reading": "Сміливе читання"
|
||||
"Bold reading": "Сміливе читання",
|
||||
"SHOW EDITS": "ПОКАЗАТИ ЗМІНИ"
|
||||
}
|
||||
|
|
|
@ -519,5 +519,6 @@
|
|||
"Web Bots Allowed": "允许网络机器人",
|
||||
"Known Search Bots": "已知的网络搜索机器人",
|
||||
"mitm": "消息可能已被第三方阅读或修改",
|
||||
"Bold reading": "大胆阅读"
|
||||
"Bold reading": "大胆阅读",
|
||||
"SHOW EDITS": "显示编辑"
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ from utils import get_domain_from_actor
|
|||
from utils import acct_dir
|
||||
from utils import local_actor_url
|
||||
from utils import is_unlisted_post
|
||||
from content import create_edits_html
|
||||
from content import bold_reading_string
|
||||
from content import limit_repeated_words
|
||||
from content import replace_emoji_from_tags
|
||||
|
@ -1479,6 +1480,18 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
|||
|
||||
_log_post_timing(enable_timing_log, post_start_time, '2')
|
||||
|
||||
# does this post have edits?
|
||||
edits_post_url = \
|
||||
remove_id_ending(message_id.strip()).replace('/', '#') + '.edits'
|
||||
account_dir = acct_dir(base_dir, nickname, domain) + '/'
|
||||
edits_filename = account_dir + box_name + '/' + edits_post_url
|
||||
edits_str = ''
|
||||
if os.path.isfile(edits_filename):
|
||||
edits_json = load_json(edits_filename, 0, 1)
|
||||
if edits_json:
|
||||
edits_str = create_edits_html(edits_json, post_json_object,
|
||||
translate, timezone)
|
||||
|
||||
message_id_str = ''
|
||||
if message_id:
|
||||
message_id_str = ';' + message_id
|
||||
|
@ -2016,6 +2029,8 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
|||
|
||||
if not is_pgp_encrypted(content_str):
|
||||
if not is_patch:
|
||||
# append any edits
|
||||
content_str += edits_str
|
||||
# Add bold text
|
||||
if bold_reading and \
|
||||
not displaying_ciphertext and \
|
||||
|
|
Loading…
Reference in New Issue