From c4fbdda58d88140fa9f3104ddc5304a54522b8e9 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 10 Apr 2022 23:50:44 +0100 Subject: [PATCH] Function to show edits to a post --- content.py | 50 ++++++++++++++++++++++++++++++++++++++++++++ epicyon-profile.css | 10 +++++++++ translations/ar.json | 3 ++- translations/ca.json | 3 ++- translations/cy.json | 3 ++- translations/de.json | 3 ++- translations/en.json | 3 ++- translations/es.json | 3 ++- translations/fr.json | 3 ++- translations/ga.json | 3 ++- translations/hi.json | 3 ++- translations/it.json | 3 ++- translations/ja.json | 3 ++- translations/ko.json | 3 ++- translations/ku.json | 3 ++- translations/oc.json | 3 ++- translations/pl.json | 3 ++- translations/pt.json | 3 ++- translations/ru.json | 3 ++- translations/sw.json | 3 ++- translations/uk.json | 3 ++- translations/zh.json | 3 ++- webapp_post.py | 15 +++++++++++++ 23 files changed, 115 insertions(+), 20 deletions(-) diff --git a/content.py b/content.py index 4a4f2990d..81c85631f 100644 --- a/content.py +++ b/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 += '' + 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', '

') + # 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 = '

' + modified_str + '

' + diff + '

' + edits_str += diff + content = prev_content + if not edits_str: + return '' + return '
' + \ + translate['SHOW EDITS'] + '' + \ + edits_str + '
\n' diff --git a/epicyon-profile.css b/epicyon-profile.css index 6c44a8101..4062d2729 100644 --- a/epicyon-profile.css +++ b/epicyon-profile.css @@ -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%; diff --git a/translations/ar.json b/translations/ar.json index 6f6f4ce23..e37a219e9 100644 --- a/translations/ar.json +++ b/translations/ar.json @@ -519,5 +519,6 @@ "Web Bots Allowed": "مسموح روبوتات الويب", "Known Search Bots": "روبوتات بحث الويب المعروفة", "mitm": "يمكن قراءة الرسالة أو تعديلها من قبل طرف ثالث", - "Bold reading": "قراءة جريئة" + "Bold reading": "قراءة جريئة", + "SHOW EDITS": "عرض التعديلات" } diff --git a/translations/ca.json b/translations/ca.json index 86651c8ae..543178e8a 100644 --- a/translations/ca.json +++ b/translations/ca.json @@ -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" } diff --git a/translations/cy.json b/translations/cy.json index 8bc01bdec..6ee8d7df8 100644 --- a/translations/cy.json +++ b/translations/cy.json @@ -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" } diff --git a/translations/de.json b/translations/de.json index c2fe3ff2d..93037f42a 100644 --- a/translations/de.json +++ b/translations/de.json @@ -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" } diff --git a/translations/en.json b/translations/en.json index d70f59477..024f4573f 100644 --- a/translations/en.json +++ b/translations/en.json @@ -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" } diff --git a/translations/es.json b/translations/es.json index 3c3673ee3..b009522af 100644 --- a/translations/es.json +++ b/translations/es.json @@ -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" } diff --git a/translations/fr.json b/translations/fr.json index a553b49b8..f932bd705 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -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" } diff --git a/translations/ga.json b/translations/ga.json index c1f065901..a5c8836cb 100644 --- a/translations/ga.json +++ b/translations/ga.json @@ -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" } diff --git a/translations/hi.json b/translations/hi.json index 6845d4d27..f97bfe869 100644 --- a/translations/hi.json +++ b/translations/hi.json @@ -519,5 +519,6 @@ "Web Bots Allowed": "वेब बॉट्स की अनुमति है", "Known Search Bots": "ज्ञात वेब खोज बॉट्स", "mitm": "संदेश किसी तीसरे पक्ष द्वारा पढ़ा या संशोधित किया जा सकता था", - "Bold reading": "बोल्ड रीडिंग" + "Bold reading": "बोल्ड रीडिंग", + "SHOW EDITS": "संपादन दिखाएं" } diff --git a/translations/it.json b/translations/it.json index d6bd3418f..2e47edd74 100644 --- a/translations/it.json +++ b/translations/it.json @@ -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" } diff --git a/translations/ja.json b/translations/ja.json index 0d6fe2b7e..a4e390b59 100644 --- a/translations/ja.json +++ b/translations/ja.json @@ -519,5 +519,6 @@ "Web Bots Allowed": "許可されたWebボット", "Known Search Bots": "既知のWeb検索ボット", "mitm": "メッセージが第三者によって読み取られたり変更されたりした可能性があります", - "Bold reading": "大胆な読書" + "Bold reading": "大胆な読書", + "SHOW EDITS": "編集を表示" } diff --git a/translations/ko.json b/translations/ko.json index 96b6e038a..e32e293a1 100644 --- a/translations/ko.json +++ b/translations/ko.json @@ -519,5 +519,6 @@ "Web Bots Allowed": "웹 봇 허용", "Known Search Bots": "알려진 웹 검색 봇", "mitm": "제3자가 메시지를 읽거나 수정했을 수 있습니다.", - "Bold reading": "굵은 글씨" + "Bold reading": "굵은 글씨", + "SHOW EDITS": "수정사항 보기" } diff --git a/translations/ku.json b/translations/ku.json index 2aa459238..54ecfdca6 100644 --- a/translations/ku.json +++ b/translations/ku.json @@ -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" } diff --git a/translations/oc.json b/translations/oc.json index c6e69765c..0715ea292 100644 --- a/translations/oc.json +++ b/translations/oc.json @@ -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" } diff --git a/translations/pl.json b/translations/pl.json index fb6e675b1..76d0279fd 100644 --- a/translations/pl.json +++ b/translations/pl.json @@ -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" } diff --git a/translations/pt.json b/translations/pt.json index 98a6db584..dfca1a257 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -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" } diff --git a/translations/ru.json b/translations/ru.json index e8d906959..697040b14 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -519,5 +519,6 @@ "Web Bots Allowed": "Веб-боты разрешены", "Known Search Bots": "Известные боты веб-поиска", "mitm": "Сообщение могло быть прочитано или изменено третьим лицом", - "Bold reading": "Смелое чтение" + "Bold reading": "Смелое чтение", + "SHOW EDITS": "ПОКАЗАТЬ РЕДАКТИРОВАНИЕ" } diff --git a/translations/sw.json b/translations/sw.json index 39e466044..f2666243e 100644 --- a/translations/sw.json +++ b/translations/sw.json @@ -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" } diff --git a/translations/uk.json b/translations/uk.json index 009245795..081e7ba6d 100644 --- a/translations/uk.json +++ b/translations/uk.json @@ -519,5 +519,6 @@ "Web Bots Allowed": "Веб-боти дозволені", "Known Search Bots": "Відомі пошукові роботи в Інтернеті", "mitm": "Повідомлення могло бути прочитане або змінене третьою стороною", - "Bold reading": "Сміливе читання" + "Bold reading": "Сміливе читання", + "SHOW EDITS": "ПОКАЗАТИ ЗМІНИ" } diff --git a/translations/zh.json b/translations/zh.json index c9624fce1..114885e74 100644 --- a/translations/zh.json +++ b/translations/zh.json @@ -519,5 +519,6 @@ "Web Bots Allowed": "允许网络机器人", "Known Search Bots": "已知的网络搜索机器人", "mitm": "消息可能已被第三方阅读或修改", - "Bold reading": "大胆阅读" + "Bold reading": "大胆阅读", + "SHOW EDITS": "显示编辑" } diff --git a/webapp_post.py b/webapp_post.py index 61fbf0fae..448a73f85 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -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 \