From 504bd5e4ea78fa33c42acf461e33aea6ba2a9244 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 10 Aug 2022 21:38:52 +0100 Subject: [PATCH] Option to keep dms during post expiry on edit profile screen --- daemon.py | 14 ++++++++++++++ posts.py | 41 ++++++++++++++++++++++++++++++++++++----- translations/ar.json | 3 ++- translations/bn.json | 3 ++- translations/ca.json | 3 ++- translations/cy.json | 3 ++- translations/de.json | 3 ++- translations/el.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/nl.json | 3 ++- translations/oc.json | 3 ++- translations/pl.json | 3 ++- translations/pt.json | 3 ++- translations/ru.json | 3 ++- translations/sw.json | 3 ++- translations/tr.json | 3 ++- translations/uk.json | 3 ++- translations/yi.json | 3 ++- translations/zh.json | 3 ++- webapp_profile.py | 5 +++++ 28 files changed, 105 insertions(+), 30 deletions(-) diff --git a/daemon.py b/daemon.py index b6380d60d..1f2fd5104 100644 --- a/daemon.py +++ b/daemon.py @@ -80,6 +80,8 @@ from person import remove_account from person import can_remove_post from person import person_snooze from person import person_unsnooze +from posts import get_post_expiry_keep_dms +from posts import set_post_expiry_keep_dms from posts import get_post_expiry_days from posts import set_post_expiry_days from posts import get_original_post_from_announce_url @@ -6730,6 +6732,18 @@ class PubServer(BaseHTTPRequestHandler): approve_followers actor_changed = True + # keep DMs during post expiry + expire_keep_dms = False + if fields.get('expiryKeepDMs'): + if fields['expiryKeepDMs'] == 'on': + expire_keep_dms = True + curr_keep_dms = \ + get_post_expiry_keep_dms(base_dir, nickname, domain) + if curr_keep_dms != expire_keep_dms: + set_post_expiry_keep_dms(base_dir, nickname, domain, + expire_keep_dms) + actor_changed = True + # remove a custom font if fields.get('removeCustomFont'): if (fields['removeCustomFont'] == 'on' and diff --git a/posts.py b/posts.py index 7af688771..da4b1b274 100644 --- a/posts.py +++ b/posts.py @@ -4286,6 +4286,41 @@ def _expire_posts_for_person(http_prefix: str, nickname: str, domain: str, return expired_post_count +def get_post_expiry_keep_dms(base_dir: str, nickname: str, domain: str) -> int: + """Returns true if dms should expire + """ + keep_dms = True + handle = nickname + '@' + domain + expire_dms_filename = \ + base_dir + '/accounts/' + handle + '/.expire_posts_dms' + if os.path.isfile(expire_dms_filename): + keep_dms = False + return keep_dms + + +def set_post_expiry_keep_dms(base_dir: str, nickname: str, domain: str, + keep_dms: bool) -> None: + """Sets whether to keep DMs during post expiry for an account + """ + handle = nickname + '@' + domain + expire_dms_filename = \ + base_dir + '/accounts/' + handle + '/.expire_posts_dms' + if keep_dms: + if os.path.isfile(expire_dms_filename): + try: + os.remove(expire_dms_filename) + except OSError: + print('EX: unable to write set_post_expiry_keep_dms False ' + + expire_dms_filename) + return + try: + with open(expire_dms_filename, 'w+', encoding='utf-8') as fp_expire: + fp_expire.write('\n') + except OSError: + print('EX: unable to write set_post_expiry_keep_dms True ' + + expire_dms_filename) + + def expire_posts(base_dir: str, http_prefix: str, recent_posts_cache: {}, debug: bool) -> int: """Expires posts for instance accounts @@ -4301,11 +4336,7 @@ def expire_posts(base_dir: str, http_prefix: str, base_dir + '/accounts/' + handle + '/.expire_posts_days' if not os.path.isfile(expire_posts_filename): continue - keep_dms = True - expire_dms_filename = \ - base_dir + '/accounts/' + handle + '/.expire_posts_dms' - if os.path.isfile(expire_dms_filename): - keep_dms = False + keep_dms = get_post_expiry_keep_dms(base_dir, nickname, domain) expire_days_str = None try: with open(expire_posts_filename, 'r', diff --git a/translations/ar.json b/translations/ar.json index 845a88a82..778018259 100644 --- a/translations/ar.json +++ b/translations/ar.json @@ -572,5 +572,6 @@ "NowPlaying": "الان العب", "Import and Export": "استيراد وتصدير", "Import Follows": "يتبع الاستيراد", - "Post expiry period in days": "فترة ما بعد انتهاء الصلاحية بالأيام" + "Post expiry period in days": "فترة ما بعد انتهاء الصلاحية بالأيام", + "Keep DMs during post expiry": "احتفظ بالرسائل الخاصّة أثناء انتهاء صلاحية النشر" } diff --git a/translations/bn.json b/translations/bn.json index 566c99393..7337b1fb6 100644 --- a/translations/bn.json +++ b/translations/bn.json @@ -572,5 +572,6 @@ "NowPlaying": "এখন চলছে", "Import and Export": "আমদানি এবং রপ্তানি", "Import Follows": "আমদানি অনুসরণ করে", - "Post expiry period in days": "দিনের মধ্যে মেয়াদ শেষ হওয়ার পরে" + "Post expiry period in days": "দিনের মধ্যে মেয়াদ শেষ হওয়ার পরে", + "Keep DMs during post expiry": "পোস্টের মেয়াদ শেষ হওয়ার সময় সরাসরি বার্তা রাখুন" } diff --git a/translations/ca.json b/translations/ca.json index 24bd55a0d..0397a0a9f 100644 --- a/translations/ca.json +++ b/translations/ca.json @@ -572,5 +572,6 @@ "NowPlaying": "AraJugant", "Import and Export": "Importació i Exportació", "Import Follows": "Segueix la importació", - "Post expiry period in days": "Període posterior a la caducitat en dies" + "Post expiry period in days": "Període posterior a la caducitat en dies", + "Keep DMs during post expiry": "Conserveu els missatges directes durant la caducitat posterior" } diff --git a/translations/cy.json b/translations/cy.json index 41364f647..88f200198 100644 --- a/translations/cy.json +++ b/translations/cy.json @@ -572,5 +572,6 @@ "NowPlaying": "NawrYnChwarae", "Import and Export": "Mewnforio ac Allforio", "Import Follows": "Mewnforio Dilyn", - "Post expiry period in days": "Cyfnod ar ôl dod i ben mewn dyddiau" + "Post expiry period in days": "Cyfnod ar ôl dod i ben mewn dyddiau", + "Keep DMs during post expiry": "Cadwch Negeseuon Uniongyrchol pan ddaw'r post i ben" } diff --git a/translations/de.json b/translations/de.json index 830958570..2fa28efb9 100644 --- a/translations/de.json +++ b/translations/de.json @@ -572,5 +572,6 @@ "NowPlaying": "LäuftGerade", "Import and Export": "Import und Export", "Import Follows": "Import folgt", - "Post expiry period in days": "Nachablaufzeitraum in Tagen" + "Post expiry period in days": "Nachablaufzeitraum in Tagen", + "Keep DMs during post expiry": "Bewahren Sie Direktnachrichten während des Ablaufs auf" } diff --git a/translations/el.json b/translations/el.json index d16771102..803dcc6eb 100644 --- a/translations/el.json +++ b/translations/el.json @@ -572,5 +572,6 @@ "NowPlaying": "ΤώραΠαίζει", "Import and Export": "Εισάγω και εξάγω", "Import Follows": "Ακολουθεί εισαγωγή", - "Post expiry period in days": "Η περίοδος μετά τη λήξη σε ημέρες" + "Post expiry period in days": "Η περίοδος μετά τη λήξη σε ημέρες", + "Keep DMs during post expiry": "Διατηρήστε τα άμεσα μηνύματα κατά τη λήξη της ανάρτησης" } diff --git a/translations/en.json b/translations/en.json index 11b63698a..98baeccd4 100644 --- a/translations/en.json +++ b/translations/en.json @@ -572,5 +572,6 @@ "NowPlaying": "NowPlaying", "Import and Export": "Import and Export", "Import Follows": "Import Follows", - "Post expiry period in days": "Post expiry period in days" + "Post expiry period in days": "Post expiry period in days", + "Keep DMs during post expiry": "Keep DMs during post expiry" } diff --git a/translations/es.json b/translations/es.json index 5303eb936..a8edbbca6 100644 --- a/translations/es.json +++ b/translations/es.json @@ -572,5 +572,6 @@ "NowPlaying": "JugandoAhora", "Import and Export": "Importar y exportar", "Import Follows": "Importar seguimientos", - "Post expiry period in days": "Período de vencimiento posterior en días" + "Post expiry period in days": "Período de vencimiento posterior en días", + "Keep DMs during post expiry": "Conservar los mensajes directos durante el vencimiento de la publicación" } diff --git a/translations/fr.json b/translations/fr.json index 403a86c1b..09281533b 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -572,5 +572,6 @@ "NowPlaying": "LectureEnCours", "Import and Export": "Importer et exporter", "Import Follows": "Importer suit", - "Post expiry period in days": "Délai après expiration en jours" + "Post expiry period in days": "Délai après expiration en jours", + "Keep DMs during post expiry": "Conserver les messages directs après l'expiration" } diff --git a/translations/ga.json b/translations/ga.json index 7ad698897..40ef0a67c 100644 --- a/translations/ga.json +++ b/translations/ga.json @@ -572,5 +572,6 @@ "NowPlaying": "AnoisAgImirt", "Import and Export": "Iompórtáil agus Easpórtáil", "Import Follows": "Leanann Iompórtáil", - "Post expiry period in days": "Tréimhse iar-éagtha i laethanta" + "Post expiry period in days": "Tréimhse iar-éagtha i laethanta", + "Keep DMs during post expiry": "Coinnigh Teachtaireachtaí Díreacha nuair a rachaidh postáil in éag" } diff --git a/translations/hi.json b/translations/hi.json index 217b8c658..2e5bd882e 100644 --- a/translations/hi.json +++ b/translations/hi.json @@ -572,5 +572,6 @@ "NowPlaying": "अब खेल रहे हैं", "Import and Export": "आयात और निर्यात", "Import Follows": "आयात का अनुसरण करता है", - "Post expiry period in days": "दिनों में समाप्ति अवधि पोस्ट करें" + "Post expiry period in days": "दिनों में समाप्ति अवधि पोस्ट करें", + "Keep DMs during post expiry": "समाप्ति के बाद सीधे संदेश रखें" } diff --git a/translations/it.json b/translations/it.json index 1f8cbec70..3dc18be99 100644 --- a/translations/it.json +++ b/translations/it.json @@ -572,5 +572,6 @@ "NowPlaying": "OraGiocando", "Import and Export": "Importazione e esportazione", "Import Follows": "Importa segue", - "Post expiry period in days": "Scadenza post in giorni" + "Post expiry period in days": "Scadenza post in giorni", + "Keep DMs during post expiry": "Conserva i messaggi diretti durante la scadenza successiva" } diff --git a/translations/ja.json b/translations/ja.json index 900c18d1e..88efc9f52 100644 --- a/translations/ja.json +++ b/translations/ja.json @@ -572,5 +572,6 @@ "NowPlaying": "再生中", "Import and Export": "インポートとエクスポート", "Import Follows": "インポートフォロー", - "Post expiry period in days": "投稿の有効期限 (日数)" + "Post expiry period in days": "投稿の有効期限 (日数)", + "Keep DMs during post expiry": "投稿の有効期限が切れるまでダイレクト メッセージを保持する" } diff --git a/translations/ko.json b/translations/ko.json index d88f3c093..979a70bf3 100644 --- a/translations/ko.json +++ b/translations/ko.json @@ -572,5 +572,6 @@ "NowPlaying": "지금 재생", "Import and Export": "가져오기 및 내보내기", "Import Follows": "가져오기 팔로우", - "Post expiry period in days": "사후 만료 기간(일)" + "Post expiry period in days": "사후 만료 기간(일)", + "Keep DMs during post expiry": "만료 후 쪽지 보관" } diff --git a/translations/ku.json b/translations/ku.json index 93ac76e7d..ac561e035 100644 --- a/translations/ku.json +++ b/translations/ku.json @@ -572,5 +572,6 @@ "NowPlaying": "NihaDilîze", "Import and Export": "Import û Export", "Import Follows": "Import Follows", - "Post expiry period in days": "Demjimêra qedandinê di çend rojan de" + "Post expiry period in days": "Demjimêra qedandinê di çend rojan de", + "Keep DMs during post expiry": "Di dema qedandina postê de Peyamên Rasterast biparêzin" } diff --git a/translations/nl.json b/translations/nl.json index 4e82c0e7e..b1b25c01b 100644 --- a/translations/nl.json +++ b/translations/nl.json @@ -572,5 +572,6 @@ "NowPlaying": "NuAanHetSpelen", "Import and Export": "Importeren en exporteren", "Import Follows": "Volgt importeren", - "Post expiry period in days": "Na afloopperiode in dagen" + "Post expiry period in days": "Na afloopperiode in dagen", + "Keep DMs during post expiry": "Directe berichten bewaren tijdens de vervaldatum" } diff --git a/translations/oc.json b/translations/oc.json index 52240d118..0415c4a2a 100644 --- a/translations/oc.json +++ b/translations/oc.json @@ -568,5 +568,6 @@ "NowPlaying": "NowPlaying", "Import and Export": "Import and Export", "Import Follows": "Import Follows", - "Post expiry period in days": "Post expiry period in days" + "Post expiry period in days": "Post expiry period in days", + "Keep DMs during post expiry": "Keep DMs during post expiry" } diff --git a/translations/pl.json b/translations/pl.json index b62e49b43..ac2f0ce92 100644 --- a/translations/pl.json +++ b/translations/pl.json @@ -572,5 +572,6 @@ "NowPlaying": "TerazGra", "Import and Export": "Importuj i eksportuj", "Import Follows": "Importuj obserwuje", - "Post expiry period in days": "Okres po wygaśnięciu w dniach" + "Post expiry period in days": "Okres po wygaśnięciu w dniach", + "Keep DMs during post expiry": "Zachowaj bezpośrednie wiadomości po wygaśnięciu" } diff --git a/translations/pt.json b/translations/pt.json index 24fb95c72..684863d8a 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -572,5 +572,6 @@ "NowPlaying": "AgoraJogando", "Import and Export": "Importar e exportar", "Import Follows": "Importar seguidores", - "Post expiry period in days": "Prazo de expiração em dias" + "Post expiry period in days": "Prazo de expiração em dias", + "Keep DMs during post expiry": "Manter mensagens diretas durante a expiração da postagem" } diff --git a/translations/ru.json b/translations/ru.json index 0d57ba73f..d9f2ecba4 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -572,5 +572,6 @@ "NowPlaying": "СейчасИграет", "Import and Export": "Импорт и экспорт", "Import Follows": "Импорт подписок", - "Post expiry period in days": "Срок действия в днях" + "Post expiry period in days": "Срок действия в днях", + "Keep DMs during post expiry": "Сохраняйте личные сообщения в течение срока действия после истечения срока действия" } diff --git a/translations/sw.json b/translations/sw.json index 1096c9db1..aa4871bfd 100644 --- a/translations/sw.json +++ b/translations/sw.json @@ -572,5 +572,6 @@ "NowPlaying": "InachezaSasa", "Import and Export": "Ingiza na Hamisha", "Import Follows": "Ingiza Inafuata", - "Post expiry period in days": "Kipindi cha baada ya kumalizika kwa siku" + "Post expiry period in days": "Kipindi cha baada ya kumalizika kwa siku", + "Keep DMs during post expiry": "Weka Ujumbe wa Moja kwa Moja wakati wa kuisha kwa chapisho" } diff --git a/translations/tr.json b/translations/tr.json index e9946fdeb..e534302d2 100644 --- a/translations/tr.json +++ b/translations/tr.json @@ -572,5 +572,6 @@ "NowPlaying": "ŞimdiOynuyor", "Import and Export": "İthalat ve ihracat", "Import Follows": "Takipleri İçe Aktar", - "Post expiry period in days": "Gün olarak sona erme süresi" + "Post expiry period in days": "Gün olarak sona erme süresi", + "Keep DMs during post expiry": "Direkt Mesajları sona erme süresi boyunca saklayın" } diff --git a/translations/uk.json b/translations/uk.json index 7229e6956..b872e4018 100644 --- a/translations/uk.json +++ b/translations/uk.json @@ -572,5 +572,6 @@ "NowPlaying": "ЗаразГрає", "Import and Export": "Імпорт та експорт", "Import Follows": "Імпорт слідує", - "Post expiry period in days": "Термін після закінчення терміну дії в днях" + "Post expiry period in days": "Термін після закінчення терміну дії в днях", + "Keep DMs during post expiry": "Зберігайте прямі повідомлення протягом терміну дії" } diff --git a/translations/yi.json b/translations/yi.json index ce96cc884..7f235498d 100644 --- a/translations/yi.json +++ b/translations/yi.json @@ -572,5 +572,6 @@ "NowPlaying": "איצט פּלייַינג", "Import and Export": "אַרייַנפיר און עקספּאָרט", "Import Follows": "אַרייַנפיר גייט", - "Post expiry period in days": "פּאָסטן עקספּיירי צייַט אין טעג" + "Post expiry period in days": "פּאָסטן עקספּיירי צייַט אין טעג", + "Keep DMs during post expiry": "האַלטן דירעקט אַרטיקלען בעשאַס פּאָסטן עקספּיירי" } diff --git a/translations/zh.json b/translations/zh.json index e33645ec2..eb560023f 100644 --- a/translations/zh.json +++ b/translations/zh.json @@ -572,5 +572,6 @@ "NowPlaying": "现在玩", "Import and Export": "进出口", "Import Follows": "导入关注", - "Post expiry period in days": "到期后天数" + "Post expiry period in days": "到期后天数", + "Keep DMs during post expiry": "在帖子到期期间保留直接消息" } diff --git a/webapp_profile.py b/webapp_profile.py index 17ad8eaca..43b66cda6 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -38,6 +38,7 @@ from theme import get_themes_list from person import person_box_json from person import get_actor_json from person import get_person_avatar_url +from posts import get_post_expiry_keep_dms from posts import get_post_expiry_days from posts import get_person_box from posts import is_moderator @@ -2191,6 +2192,10 @@ def _html_edit_profile_main(base_dir: str, display_nickname: str, bio_str: str, edit_number_field(translate['Post expiry period in days'], 'postExpiryPeriod', post_expiry_period_days, 0, 9999999999999999999999, 0) + keep_dms = get_post_expiry_keep_dms(base_dir, nickname, domain) + edit_profile_form += \ + edit_check_box(translate['Keep DMs during post expiry'], + 'expiryKeepDMs', keep_dms) edit_profile_form += ' \n' return edit_profile_form