From 19a1676ee82c6d203cf0d4f8326ef583c078cb78 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 13 Nov 2022 19:45:34 +0000 Subject: [PATCH] Minimize all images on edit profile screen --- daemon.py | 26 ++++++++++++++++++++++++-- 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 ++- utils.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ webapp_profile.py | 18 +++++++++++++++--- 28 files changed, 133 insertions(+), 30 deletions(-) diff --git a/daemon.py b/daemon.py index 3f95335df..4255e5d02 100644 --- a/daemon.py +++ b/daemon.py @@ -264,6 +264,8 @@ from languages import set_actor_languages from languages import get_understood_languages from like import update_likes_collection from reaction import update_reaction_collection +from utils import load_min_images_for_accounts +from utils import set_minimize_all_images from utils import get_json_content_from_accept from utils import remove_eol from utils import text_in_file @@ -6961,6 +6963,25 @@ class PubServer(BaseHTTPRequestHandler): 'unable to delete ' + hide_like_button_file) + # Minimize all images from edit profile screen + minimize_all_images = False + if fields.get('minimizeAllImages'): + if fields['minimizeAllImages'] == 'on': + minimize_all_images = True + min_img_acct = self.server.min_images_for_accounts + set_minimize_all_images(base_dir, + nickname, domain, + True, min_img_acct) + print('min_images_for_accounts: ' + + str(min_img_acct)) + if not minimize_all_images: + min_img_acct = self.server.min_images_for_accounts + set_minimize_all_images(base_dir, + nickname, domain, + False, min_img_acct) + print('min_images_for_accounts: ' + + str(min_img_acct)) + # hide Reaction button hide_reaction_button_file = \ acct_dir(base_dir, nickname, domain) + \ @@ -15197,7 +15218,8 @@ class PubServer(BaseHTTPRequestHandler): default_reply_interval_hrs, self.server.cw_lists, self.server.lists_enabled, - self.server.system_language) + self.server.system_language, + self.server.min_images_for_accounts) if msg: msg = msg.encode('utf-8') msglen = len(msg) @@ -21334,7 +21356,7 @@ def run_daemon(map_format: str, assert not scan_themes_for_scripts(base_dir) # which accounts should minimize all attached images by default - httpd.min_images_for_accounts = [] + httpd.min_images_for_accounts = load_min_images_for_accounts(base_dir) # caches css files httpd.css_cache = {} diff --git a/translations/ar.json b/translations/ar.json index 33257ce21..0d9595fc7 100644 --- a/translations/ar.json +++ b/translations/ar.json @@ -597,5 +597,6 @@ "Reject spam accounts": "رفض حسابات البريد العشوائي", "User Manual": "دليل الاستخدام", "Allow announces": "تعلن السماح", - "Send": "إرسال" + "Send": "إرسال", + "Minimize all images": "تصغير كل الصور" } diff --git a/translations/bn.json b/translations/bn.json index 8931ea853..d14b7daab 100644 --- a/translations/bn.json +++ b/translations/bn.json @@ -597,5 +597,6 @@ "Reject spam accounts": "স্প্যাম অ্যাকাউন্ট প্রত্যাখ্যান করুন", "User Manual": "ব্যবহার বিধি", "Allow announces": "ঘোষণার অনুমতি দিন", - "Send": "পাঠান" + "Send": "পাঠান", + "Minimize all images": "সমস্ত ছবি ছোট করুন" } diff --git a/translations/ca.json b/translations/ca.json index 82d94a1b6..1430daf12 100644 --- a/translations/ca.json +++ b/translations/ca.json @@ -597,5 +597,6 @@ "Reject spam accounts": "Rebutja els comptes de correu brossa", "User Manual": "Manual d'usuari", "Allow announces": "Permet anuncis", - "Send": "Enviar" + "Send": "Enviar", + "Minimize all images": "Minimitzar totes les imatges" } diff --git a/translations/cy.json b/translations/cy.json index 1a23578a4..c29f14fed 100644 --- a/translations/cy.json +++ b/translations/cy.json @@ -597,5 +597,6 @@ "Reject spam accounts": "Gwrthod cyfrifon sbam", "User Manual": "Llawlyfr Defnyddiwr", "Allow announces": "Caniatáu cyhoeddiadau", - "Send": "Anfon" + "Send": "Anfon", + "Minimize all images": "Lleihau pob delwedd" } diff --git a/translations/de.json b/translations/de.json index 4a4a03a1b..d98053d9c 100644 --- a/translations/de.json +++ b/translations/de.json @@ -597,5 +597,6 @@ "Reject spam accounts": "Gwrthod cyfrifon sbam", "User Manual": "Benutzerhandbuch", "Allow announces": "Zulassen kündigt an", - "Send": "Senden" + "Send": "Senden", + "Minimize all images": "Alle Bilder minimieren" } diff --git a/translations/el.json b/translations/el.json index 582241efc..178dacef0 100644 --- a/translations/el.json +++ b/translations/el.json @@ -597,5 +597,6 @@ "Reject spam accounts": "Gwrthod cyfrifon sbam", "User Manual": "Εγχειρίδιο χρήστη", "Allow announces": "Allow ανακοινώνει", - "Send": "Στείλετε" + "Send": "Στείλετε", + "Minimize all images": "Ελαχιστοποίηση όλων των εικόνων" } diff --git a/translations/en.json b/translations/en.json index f5c8d8dca..03ed8fac5 100644 --- a/translations/en.json +++ b/translations/en.json @@ -597,5 +597,6 @@ "Reject spam accounts": "Reject spam accounts", "User Manual": "User Manual", "Allow announces": "Allow announces", - "Send": "Send" + "Send": "Send", + "Minimize all images": "Minimize all images" } diff --git a/translations/es.json b/translations/es.json index 85c67e1ee..b1ae8dafd 100644 --- a/translations/es.json +++ b/translations/es.json @@ -597,5 +597,6 @@ "Reject spam accounts": "Rechazar cuentas de spam", "User Manual": "Manual de usuario", "Allow announces": "Permitir anuncios", - "Send": "Enviar" + "Send": "Enviar", + "Minimize all images": "Minimizar todas las imágenes" } diff --git a/translations/fr.json b/translations/fr.json index e3c1947f6..cac4952d0 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -597,5 +597,6 @@ "Reject spam accounts": "Rejeter les comptes de spam", "User Manual": "Manuel de l'Utilisateur", "Allow announces": "Autoriser les annonces", - "Send": "Envoyer" + "Send": "Envoyer", + "Minimize all images": "Réduire toutes les images" } diff --git a/translations/ga.json b/translations/ga.json index a6d84e9ea..c60dc0878 100644 --- a/translations/ga.json +++ b/translations/ga.json @@ -597,5 +597,6 @@ "Reject spam accounts": "Diúltaigh cuntais turscair", "User Manual": "Lámhleabhar Úsáideora", "Allow announces": "Ceadaigh fógraí", - "Send": "Seol" + "Send": "Seol", + "Minimize all images": "Íoslaghdaigh gach íomhá" } diff --git a/translations/hi.json b/translations/hi.json index b6827900e..995e314eb 100644 --- a/translations/hi.json +++ b/translations/hi.json @@ -597,5 +597,6 @@ "Reject spam accounts": "स्पैम खातों को अस्वीकार करें", "User Manual": "उपयोगकर्ता पुस्तिका", "Allow announces": "घोषणा की अनुमति दें", - "Send": "भेजना" + "Send": "भेजना", + "Minimize all images": "सभी छवियों को छोटा करें" } diff --git a/translations/it.json b/translations/it.json index 005f70ac8..37a540938 100644 --- a/translations/it.json +++ b/translations/it.json @@ -597,5 +597,6 @@ "Reject spam accounts": "Rifiuta gli account spam", "User Manual": "Manuale d'uso", "Allow announces": "Consenti annunci", - "Send": "Inviare" + "Send": "Inviare", + "Minimize all images": "Riduci a icona tutte le immagini" } diff --git a/translations/ja.json b/translations/ja.json index f156e9f74..fb4fa24bb 100644 --- a/translations/ja.json +++ b/translations/ja.json @@ -597,5 +597,6 @@ "Reject spam accounts": "スパムアカウントを拒否", "User Manual": "ユーザーマニュアル", "Allow announces": "アナウンスを許可", - "Send": "送信" + "Send": "送信", + "Minimize all images": "すべての画像を最小化" } diff --git a/translations/ko.json b/translations/ko.json index 26a01a955..2ed528e41 100644 --- a/translations/ko.json +++ b/translations/ko.json @@ -597,5 +597,6 @@ "Reject spam accounts": "스팸 계정 거부", "User Manual": "사용자 매뉴얼", "Allow announces": "공지 허용", - "Send": "보내다" + "Send": "보내다", + "Minimize all images": "모든 이미지 최소화" } diff --git a/translations/ku.json b/translations/ku.json index bd7680798..694cefa2d 100644 --- a/translations/ku.json +++ b/translations/ku.json @@ -597,5 +597,6 @@ "Reject spam accounts": "Hesabên spam red bikin", "User Manual": "Manual Bikarhêner", "Allow announces": "Destûr dide ragihandin", - "Send": "Şandin" + "Send": "Şandin", + "Minimize all images": "Hemî wêneyan kêm bikin" } diff --git a/translations/nl.json b/translations/nl.json index 1848cc074..69c034182 100644 --- a/translations/nl.json +++ b/translations/nl.json @@ -597,5 +597,6 @@ "Reject spam accounts": "Spamaccounts afwijzen", "User Manual": "Handleiding", "Allow announces": "Aankondigingen toestaan", - "Send": "Versturen" + "Send": "Versturen", + "Minimize all images": "Alle afbeeldingen minimaliseren" } diff --git a/translations/oc.json b/translations/oc.json index f7aaefda8..43aae5b1a 100644 --- a/translations/oc.json +++ b/translations/oc.json @@ -593,5 +593,6 @@ "Reject spam accounts": "Reject spam accounts", "User Manual": "User Manual", "Allow announces": "Allow announces", - "Send": "Send" + "Send": "Send", + "Minimize all images": "Minimize all images" } diff --git a/translations/pl.json b/translations/pl.json index fb71d30c1..4d33ad725 100644 --- a/translations/pl.json +++ b/translations/pl.json @@ -597,5 +597,6 @@ "Reject spam accounts": "Odrzuć konta spamowe", "User Manual": "Instrukcja obsługi", "Allow announces": "Zezwól na ogłoszenia", - "Send": "Wysłać" + "Send": "Wysłać", + "Minimize all images": "Zminimalizuj wszystkie obrazy" } diff --git a/translations/pt.json b/translations/pt.json index 8e5ff42f1..b9f0b1280 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -597,5 +597,6 @@ "Reject spam accounts": "Rejeitar contas de spam", "User Manual": "Manual do usuário", "Allow announces": "Permitir anúncios", - "Send": "Mandar" + "Send": "Mandar", + "Minimize all images": "Minimize todas as imagens" } diff --git a/translations/ru.json b/translations/ru.json index 55c8f3f6b..ea970696d 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -597,5 +597,6 @@ "Reject spam accounts": "Отклонить спам-аккаунты", "User Manual": "Руководство пользователя", "Allow announces": "Разрешить объявления", - "Send": "Отправлять" + "Send": "Отправлять", + "Minimize all images": "Свернуть все изображения" } diff --git a/translations/sw.json b/translations/sw.json index fcda7ebfa..4fb448bc9 100644 --- a/translations/sw.json +++ b/translations/sw.json @@ -597,5 +597,6 @@ "Reject spam accounts": "Kataa akaunti za barua taka", "User Manual": "Mwongozo wa mtumiaji", "Allow announces": "Ruhusu matangazo", - "Send": "Tuma" + "Send": "Tuma", + "Minimize all images": "Punguza picha zote" } diff --git a/translations/tr.json b/translations/tr.json index 36cca3993..bc39f3d88 100644 --- a/translations/tr.json +++ b/translations/tr.json @@ -597,5 +597,6 @@ "Reject spam accounts": "Spam hesapları reddet", "User Manual": "Kullanım kılavuzu", "Allow announces": "Duyurulara izin ver", - "Send": "Göndermek" + "Send": "Göndermek", + "Minimize all images": "Tüm görüntüleri simge durumuna küçült" } diff --git a/translations/uk.json b/translations/uk.json index 83cbd5b03..6bb4c90eb 100644 --- a/translations/uk.json +++ b/translations/uk.json @@ -597,5 +597,6 @@ "Reject spam accounts": "Відхилити спам-акаунти", "User Manual": "Посібник користувача", "Allow announces": "Дозволити оголошення", - "Send": "Надіслати" + "Send": "Надіслати", + "Minimize all images": "Згорнути всі зображення" } diff --git a/translations/yi.json b/translations/yi.json index 1cb086745..e6375630e 100644 --- a/translations/yi.json +++ b/translations/yi.json @@ -597,5 +597,6 @@ "Reject spam accounts": "אָפּוואַרפן ספּאַם אַקאַונץ", "User Manual": "באנוצער אנווייזער", "Allow announces": "לאָזן אַנאַונסיז", - "Send": "שיקן" + "Send": "שיקן", + "Minimize all images": "מינאַמייז אַלע בילדער" } diff --git a/translations/zh.json b/translations/zh.json index 1a9b1bbe6..6d0c07114 100644 --- a/translations/zh.json +++ b/translations/zh.json @@ -597,5 +597,6 @@ "Reject spam accounts": "拒绝垃圾邮件帐户", "User Manual": "用户手册", "Allow announces": "לאָזן אַנאַונסיז", - "Send": "发送" + "Send": "发送", + "Minimize all images": "最小化所有图像" } diff --git a/utils.py b/utils.py index 93f953fc6..e5301ac39 100644 --- a/utils.py +++ b/utils.py @@ -3951,3 +3951,47 @@ def dont_speak_hashtags(content: str) -> str: return content return content.replace('># []: + """Loads a list of nicknames for accounts where all images should + be minimized by default + """ + min_images_for_accounts = [] + for subdir, dirs, _ in os.walk(base_dir + '/accounts'): + for account in dirs: + if not is_account_dir(account): + continue + filename = os.path.join(subdir, account) + '/.minimize_all_images' + if os.path.isfile(filename): + min_images_for_accounts.append(account.split('@')[0]) + break + return min_images_for_accounts + + +def set_minimize_all_images(base_dir: str, + nickname: str, domain: str, + minimize: bool, + min_images_for_accounts: []) -> None: + """Add of remove a file indicating that all images for an account + should be minimized by default + """ + filename = acct_dir(base_dir, nickname, domain) + '/.minimize_all_images' + if minimize: + if nickname not in min_images_for_accounts: + min_images_for_accounts.append(nickname) + if not os.path.isfile(filename): + try: + with open(filename, 'w+', encoding='utf-8') as fp_min: + fp_min.write('\n') + except OSError: + print('EX: unable to write ' + filename) + return + + if nickname in min_images_for_accounts: + min_images_for_accounts.remove(nickname) + if os.path.isfile(filename): + try: + os.remove(filename) + except OSError: + print('EX: unable to delete ' + filename) diff --git a/webapp_profile.py b/webapp_profile.py index dd6cc6b63..5a4167147 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -2154,7 +2154,9 @@ def _html_edit_profile_options(is_admin: bool, notify_likes: str, notify_reactions: str, hide_like_button: str, hide_reaction_button: str, - translate: {}, bold_reading: bool) -> str: + translate: {}, bold_reading: bool, + nickname: str, + min_images_for_accounts: []) -> str: """option checkboxes section of edit profile screen """ edit_profile_form = '
\n' @@ -2192,6 +2194,14 @@ def _html_edit_profile_options(is_admin: bool, bold_str = bold_reading_string(translate['Bold reading']) edit_profile_form += \ edit_check_box(bold_str, 'boldReading', bold_reading) + minimize_all_images = False + if nickname in min_images_for_accounts: + minimize_all_images = True + minimize_all_images_str = \ + bold_reading_string(translate['Minimize all images']) + edit_profile_form += \ + edit_check_box(minimize_all_images_str, 'minimizeAllImages', + minimize_all_images) edit_profile_form += '
\n' return edit_profile_form @@ -2353,7 +2363,8 @@ def html_edit_profile(server, translate: {}, access_keys: {}, default_reply_interval_hrs: int, cw_lists: {}, lists_enabled: str, - system_language: str) -> str: + system_language: str, + min_images_for_accounts: []) -> str: """Shows the edit profile screen """ path = path.replace('/inbox', '').replace('/outbox', '') @@ -2547,7 +2558,8 @@ def html_edit_profile(server, translate: {}, remove_twitter, notify_likes, notify_reactions, hide_like_button, hide_reaction_button, - translate, bold_reading) + translate, bold_reading, + nickname, min_images_for_accounts) # Contact information edit_profile_form += \