From cae927c91de149646516736db25abd0a1b7529fc Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 11 Jun 2022 17:14:16 +0100 Subject: [PATCH] Ability to minimize images shown from followed accounts --- blog.py | 4 +- daemon.py | 31 +++++++++++ followingCalendar.py | 25 +++++++-- translations/ar.json | 4 +- translations/bn.json | 4 +- translations/ca.json | 4 +- translations/cy.json | 4 +- translations/de.json | 4 +- translations/el.json | 4 +- translations/en.json | 4 +- translations/es.json | 4 +- translations/fr.json | 4 +- translations/ga.json | 4 +- translations/hi.json | 4 +- translations/it.json | 4 +- translations/ja.json | 4 +- translations/ko.json | 4 +- translations/ku.json | 4 +- translations/nl.json | 4 +- translations/oc.json | 4 +- translations/pl.json | 4 +- translations/pt.json | 4 +- translations/ru.json | 4 +- translations/sw.json | 4 +- translations/tr.json | 4 +- translations/uk.json | 4 +- translations/yi.json | 4 +- translations/zh.json | 4 +- webapp_person_options.py | 117 +++++++++++++++++++++++++++++++++++++++ webapp_post.py | 3 +- webapp_utils.py | 71 +++++++++++++++++++++++- 31 files changed, 318 insertions(+), 33 deletions(-) diff --git a/blog.py b/blog.py index 1cdb1d12f..6fa61165e 100644 --- a/blog.py +++ b/blog.py @@ -261,8 +261,8 @@ def _html_blog_post_content(debug: bool, session, authorized: bool, mute_str = '' is_muted = False attachment_str, _ = \ - get_post_attachments_as_html(base_dir, domain_full, - post_json_object, + get_post_attachments_as_html(base_dir, nickname, domain, + domain_full, post_json_object, 'tlblogs', translate, is_muted, avatar_link, reply_str, announce_str, diff --git a/daemon.py b/daemon.py index 943bc06b7..dc1adc59c 100644 --- a/daemon.py +++ b/daemon.py @@ -179,6 +179,8 @@ from webapp_accesskeys import load_access_keys_for_accounts from webapp_confirm import html_confirm_delete from webapp_confirm import html_confirm_remove_shared_item from webapp_confirm import html_confirm_unblock +from webapp_person_options import person_minimize_images +from webapp_person_options import person_undo_minimize_images from webapp_person_options import html_person_options from webapp_timeline import html_shares from webapp_timeline import html_wanted @@ -2864,6 +2866,35 @@ class PubServer(BaseHTTPRequestHandler): self.server.postreq_busy = False return + # person options screen, minimize images checkbox + # See html_person_options + if '&submitMinimizeImages=' in options_confirm_params: + minimize_images = None + if 'minimizeImages=' in options_confirm_params: + minimize_images = \ + options_confirm_params.split('minimizeImages=')[1] + if '&' in minimize_images: + minimize_images = minimize_images.split('&')[0] + if minimize_images == 'on': + person_minimize_images(base_dir, + chooser_nickname, + domain, + options_nickname, + options_domain_full) + else: + person_undo_minimize_images(base_dir, + chooser_nickname, + domain, + options_nickname, + options_domain_full) + users_path_str = \ + users_path + '/' + self.server.default_timeline + \ + '?page=' + str(page_number) + self._redirect_headers(users_path_str, cookie, + calling_domain) + self.server.postreq_busy = False + return + # person options screen, on notify checkbox # See html_person_options if '&submitNotifyOnPost=' in options_confirm_params: diff --git a/followingCalendar.py b/followingCalendar.py index aae78b974..5e368a960 100644 --- a/followingCalendar.py +++ b/followingCalendar.py @@ -10,6 +10,25 @@ __module_group__ = "Calendar" import os +def _text_in_file2(text: str, filename: str, + case_sensitive: bool = True) -> bool: + """is the given text in the given file? + """ + if not case_sensitive: + text = text.lower() + try: + with open(filename, 'r', encoding='utf-8') as file: + content = file.read() + if content: + if not case_sensitive: + content = content.lower() + if text in content: + return True + except OSError: + print('EX: unable to find text in missing file ' + filename) + return False + + def _dir_acct(base_dir: str, nickname: str, domain: str) -> str: """Returns the directory of an account """ @@ -60,8 +79,7 @@ def receiving_calendar_events(base_dir: str, nickname: str, domain: str, fp_cal.write(following_handles) except OSError: print('EX: receiving_calendar_events 2 ' + calendar_filename) - return handle + '\n' in open(calendar_filename, - encoding='utf-8').read() + return _text_in_file2(handle + '\n', calendar_filename) def _receive_calendar_events(base_dir: str, nickname: str, domain: str, @@ -82,8 +100,7 @@ def _receive_calendar_events(base_dir: str, nickname: str, domain: str, handle = following_nickname + '@' + following_domain # check that you are following this handle - if handle + '\n' not in open(following_filename, - encoding='utf-8').read(): + if not _text_in_file2(handle + '\n', following_filename): print('WARN: ' + handle + ' is not in ' + following_filename) return diff --git a/translations/ar.json b/translations/ar.json index ea8a1afd3..2627fa355 100644 --- a/translations/ar.json +++ b/translations/ar.json @@ -562,5 +562,7 @@ "End Time": "وقت النهاية", "Switch to calendar view": "قم بالتبديل إلى عرض التقويم", "Save": "يحفظ", - "Switch to moderation view": "قم بالتبديل إلى عرض الاعتدال" + "Switch to moderation view": "قم بالتبديل إلى عرض الاعتدال", + "Minimize attached images": "تصغير الصور المرفقة", + "SHOW MEDIA": "عرض الوسائط" } diff --git a/translations/bn.json b/translations/bn.json index 7d5861833..f572a1d96 100644 --- a/translations/bn.json +++ b/translations/bn.json @@ -562,5 +562,7 @@ "End Time": "শেষ সময়", "Switch to calendar view": "ক্যালেন্ডার ভিউতে স্যুইচ করুন", "Save": "সংরক্ষণ", - "Switch to moderation view": "সংযম দৃশ্যে স্যুইচ করুন" + "Switch to moderation view": "সংযম দৃশ্যে স্যুইচ করুন", + "Minimize attached images": "সংযুক্ত ছবি ছোট করুন", + "SHOW MEDIA": "মিডিয়া দেখান" } diff --git a/translations/ca.json b/translations/ca.json index 29f86699e..eddad3773 100644 --- a/translations/ca.json +++ b/translations/ca.json @@ -562,5 +562,7 @@ "End Time": "Temps esgotat", "Switch to calendar view": "Canvia a la vista del calendari", "Save": "Desa", - "Switch to moderation view": "Canvia a la visualització de moderació" + "Switch to moderation view": "Canvia a la visualització de moderació", + "Minimize attached images": "Minimitzar les imatges adjuntes", + "SHOW MEDIA": "MOSTRA ELS MITJANS" } diff --git a/translations/cy.json b/translations/cy.json index cb9da1569..d35db8933 100644 --- a/translations/cy.json +++ b/translations/cy.json @@ -562,5 +562,7 @@ "End Time": "Amser Gorffen", "Switch to calendar view": "Newid i wedd calendr", "Save": "Arbed", - "Switch to moderation view": "Newid i wedd safoni" + "Switch to moderation view": "Newid i wedd safoni", + "Minimize attached images": "Lleihau delweddau sydd ynghlwm", + "SHOW MEDIA": "DANGOS CYFRYNGAU" } diff --git a/translations/de.json b/translations/de.json index 8b39fa20b..2e92b79fd 100644 --- a/translations/de.json +++ b/translations/de.json @@ -562,5 +562,7 @@ "End Time": "Endzeit", "Switch to calendar view": "Zur Kalenderansicht wechseln", "Save": "Speichern", - "Switch to moderation view": "Wechseln Sie zur Moderationsansicht" + "Switch to moderation view": "Wechseln Sie zur Moderationsansicht", + "Minimize attached images": "Angehängte Bilder minimieren", + "SHOW MEDIA": "MEDIEN ZEIGEN" } diff --git a/translations/el.json b/translations/el.json index 92b028d75..fc46705aa 100644 --- a/translations/el.json +++ b/translations/el.json @@ -562,5 +562,7 @@ "End Time": "Τέλος χρόνου", "Switch to calendar view": "Μετάβαση σε προβολή ημερολογίου", "Save": "Αποθηκεύσετε", - "Switch to moderation view": "Μετάβαση σε προβολή εποπτείας" + "Switch to moderation view": "Μετάβαση σε προβολή εποπτείας", + "Minimize attached images": "Ελαχιστοποιήστε τις συνημμένες εικόνες", + "SHOW MEDIA": "ΔΕΙΤΕ ΜΕΣΑ" } diff --git a/translations/en.json b/translations/en.json index e34154130..a8be883de 100644 --- a/translations/en.json +++ b/translations/en.json @@ -562,5 +562,7 @@ "End Time": "End Time", "Switch to calendar view": "Switch to calendar view", "Save": "Save", - "Switch to moderation view": "Switch to moderation view" + "Switch to moderation view": "Switch to moderation view", + "Minimize attached images": "Minimize attached images", + "SHOW MEDIA": "SHOW MEDIA" } diff --git a/translations/es.json b/translations/es.json index 04bd15293..e494d714a 100644 --- a/translations/es.json +++ b/translations/es.json @@ -562,5 +562,7 @@ "End Time": "Hora de finalización", "Switch to calendar view": "Cambiar a vista de calendario", "Save": "Ahorrar", - "Switch to moderation view": "Cambiar a la vista de moderación" + "Switch to moderation view": "Cambiar a la vista de moderación", + "Minimize attached images": "Minimizar imágenes adjuntas", + "SHOW MEDIA": "MOSTRAR MEDIOS" } diff --git a/translations/fr.json b/translations/fr.json index f7dcfffc2..c4aa74344 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -562,5 +562,7 @@ "End Time": "Heure de fin", "Switch to calendar view": "Basculer vers la vue calendrier", "Save": "Sauvegarder", - "Switch to moderation view": "Passer en mode modération" + "Switch to moderation view": "Passer en mode modération", + "Minimize attached images": "Réduire les images jointes", + "SHOW MEDIA": "AFFICHER LES MÉDIAS" } diff --git a/translations/ga.json b/translations/ga.json index acda3dac8..f56c56c60 100644 --- a/translations/ga.json +++ b/translations/ga.json @@ -562,5 +562,7 @@ "End Time": "Am Deiridh", "Switch to calendar view": "Athraigh go hamharc féilire", "Save": "Sábháil", - "Switch to moderation view": "Athraigh go dtí an t-amharc modhnóireachta" + "Switch to moderation view": "Athraigh go dtí an t-amharc modhnóireachta", + "Minimize attached images": "Íoslaghdaigh íomhánna ceangailte", + "SHOW MEDIA": "Taispeáin MEÁIN" } diff --git a/translations/hi.json b/translations/hi.json index 5aa2d15a7..c7766c1f4 100644 --- a/translations/hi.json +++ b/translations/hi.json @@ -562,5 +562,7 @@ "End Time": "अंत समय", "Switch to calendar view": "कैलेंडर दृश्य पर स्विच करें", "Save": "बचाना", - "Switch to moderation view": "मॉडरेशन दृश्य पर स्विच करें" + "Switch to moderation view": "मॉडरेशन दृश्य पर स्विच करें", + "Minimize attached images": "संलग्न छवियों को छोटा करें", + "SHOW MEDIA": "मीडिया दिखाएं" } diff --git a/translations/it.json b/translations/it.json index c0820e3dd..52f0c0e1b 100644 --- a/translations/it.json +++ b/translations/it.json @@ -562,5 +562,7 @@ "End Time": "Tempo scaduto", "Switch to calendar view": "Passa alla visualizzazione del calendario", "Save": "Salva", - "Switch to moderation view": "Passa alla visualizzazione moderazione" + "Switch to moderation view": "Passa alla visualizzazione moderazione", + "Minimize attached images": "Riduci al minimo le immagini allegate", + "SHOW MEDIA": "MOSTRA MEDIA" } diff --git a/translations/ja.json b/translations/ja.json index b3d5f598f..f751136be 100644 --- a/translations/ja.json +++ b/translations/ja.json @@ -562,5 +562,7 @@ "End Time": "終了時間", "Switch to calendar view": "カレンダービューに切り替えます", "Save": "保存", - "Switch to moderation view": "モデレートビューに切り替えます" + "Switch to moderation view": "モデレートビューに切り替えます", + "Minimize attached images": "添付画像を最小限に抑える", + "SHOW MEDIA": "メディアを表示" } diff --git a/translations/ko.json b/translations/ko.json index 8384c1138..503175277 100644 --- a/translations/ko.json +++ b/translations/ko.json @@ -562,5 +562,7 @@ "End Time": "종료 시간", "Switch to calendar view": "캘린더 보기로 전환", "Save": "구하다", - "Switch to moderation view": "검토 보기로 전환" + "Switch to moderation view": "검토 보기로 전환", + "Minimize attached images": "첨부된 이미지 최소화", + "SHOW MEDIA": "미디어 표시" } diff --git a/translations/ku.json b/translations/ku.json index df0e1b7af..9e5b086e6 100644 --- a/translations/ku.json +++ b/translations/ku.json @@ -562,5 +562,7 @@ "End Time": "Dema Dawî", "Switch to calendar view": "Biguherîne bo dîtina salnameyê", "Save": "Rizgarkirin", - "Switch to moderation view": "Biguherîne bo dîtina moderatoriyê" + "Switch to moderation view": "Biguherîne bo dîtina moderatoriyê", + "Minimize attached images": "Wêneyên pêvekirî kêm bikin", + "SHOW MEDIA": "MEDYA NÎŞAN DE" } diff --git a/translations/nl.json b/translations/nl.json index fa41b4491..3cd5a13e2 100644 --- a/translations/nl.json +++ b/translations/nl.json @@ -562,5 +562,7 @@ "End Time": "Eindtijd", "Switch to calendar view": "Overschakelen naar kalenderweergave", "Save": "Opslaan", - "Switch to moderation view": "Overschakelen naar moderatieweergave" + "Switch to moderation view": "Overschakelen naar moderatieweergave", + "Minimize attached images": "Bijgevoegde afbeeldingen minimaliseren", + "SHOW MEDIA": "TOON MEDIA" } diff --git a/translations/oc.json b/translations/oc.json index 3bcc7f645..46cdd9ae2 100644 --- a/translations/oc.json +++ b/translations/oc.json @@ -558,5 +558,7 @@ "End Time": "End Time", "Switch to calendar view": "Switch to calendar view", "Save": "Save", - "Switch to moderation view": "Switch to moderation view" + "Switch to moderation view": "Switch to moderation view", + "Minimize attached images": "Minimize attached images", + "SHOW MEDIA": "SHOW MEDIA" } diff --git a/translations/pl.json b/translations/pl.json index 9ec023841..e8b6f4a9e 100644 --- a/translations/pl.json +++ b/translations/pl.json @@ -562,5 +562,7 @@ "End Time": "Koniec czasu", "Switch to calendar view": "Przełącz na widok kalendarza", "Save": "Ratować", - "Switch to moderation view": "Przełącz na widok moderacji" + "Switch to moderation view": "Przełącz na widok moderacji", + "Minimize attached images": "Zminimalizuj załączone obrazy", + "SHOW MEDIA": "POKAŻ MEDIA" } diff --git a/translations/pt.json b/translations/pt.json index b92fb77fb..69c0d159c 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -562,5 +562,7 @@ "End Time": "Fim do tempo", "Switch to calendar view": "Mudar para a vista de calendário", "Save": "Salvar", - "Switch to moderation view": "Mudar para a visualização de moderação" + "Switch to moderation view": "Mudar para a visualização de moderação", + "Minimize attached images": "Minimizar imagens anexadas", + "SHOW MEDIA": "MOSTRAR MÍDIA" } diff --git a/translations/ru.json b/translations/ru.json index dee14a89d..127ce94b9 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -562,5 +562,7 @@ "End Time": "Время окончания", "Switch to calendar view": "Переключиться на представление календаря", "Save": "Сохранять", - "Switch to moderation view": "Перейти в режим модерации" + "Switch to moderation view": "Перейти в режим модерации", + "Minimize attached images": "Свернуть прикрепленные изображения", + "SHOW MEDIA": "ПОКАЗАТЬ МЕДИА" } diff --git a/translations/sw.json b/translations/sw.json index 817da5775..9cde2161a 100644 --- a/translations/sw.json +++ b/translations/sw.json @@ -562,5 +562,7 @@ "End Time": "Wakati wa Mwisho", "Switch to calendar view": "Badili hadi mwonekano wa kalenda", "Save": "Hifadhi", - "Switch to moderation view": "Badili hadi mwonekano wa udhibiti" + "Switch to moderation view": "Badili hadi mwonekano wa udhibiti", + "Minimize attached images": "Punguza picha zilizoambatishwa", + "SHOW MEDIA": "ONESHA VYOMBO VYA HABARI" } diff --git a/translations/tr.json b/translations/tr.json index 7ffa8bfd8..ffcabb55e 100644 --- a/translations/tr.json +++ b/translations/tr.json @@ -562,5 +562,7 @@ "End Time": "Bitiş zamanı", "Switch to calendar view": "Takvim görünümüne geç", "Save": "Kaydetmek", - "Switch to moderation view": "Denetleme görünümüne geç" + "Switch to moderation view": "Denetleme görünümüne geç", + "Minimize attached images": "Ekli resimleri simge durumuna küçült", + "SHOW MEDIA": "MEDYA GÖSTER" } diff --git a/translations/uk.json b/translations/uk.json index d7a64d9ed..9501a4193 100644 --- a/translations/uk.json +++ b/translations/uk.json @@ -562,5 +562,7 @@ "End Time": "Час закінчення", "Switch to calendar view": "Перейти до перегляду календаря", "Save": "Зберегти", - "Switch to moderation view": "Перейти до режиму модерації" + "Switch to moderation view": "Перейти до режиму модерації", + "Minimize attached images": "Мінімізуйте вкладені зображення", + "SHOW MEDIA": "ПОКАЗАТИ ЗМІ" } diff --git a/translations/yi.json b/translations/yi.json index 5c7a23daf..6d6b2d627 100644 --- a/translations/yi.json +++ b/translations/yi.json @@ -562,5 +562,7 @@ "End Time": "סוף צייט", "Switch to calendar view": "באַשטימען צו די קאַלענדאַר מיינונג", "Save": "היט", - "Switch to moderation view": "באַשטימען צו מאַדעריישאַן מיינונג" + "Switch to moderation view": "באַשטימען צו מאַדעריישאַן מיינונג", + "Minimize attached images": "מינאַמייז אַטאַטשט בילדער", + "SHOW MEDIA": "ווייַז מעדיע" } diff --git a/translations/zh.json b/translations/zh.json index e8e950d90..dc037c3fb 100644 --- a/translations/zh.json +++ b/translations/zh.json @@ -562,5 +562,7 @@ "End Time": "时间结束", "Switch to calendar view": "切换到日历视图", "Save": "节省", - "Switch to moderation view": "切换到审核视图" + "Switch to moderation view": "切换到审核视图", + "Minimize attached images": "最小化附加图像", + "SHOW MEDIA": "展示媒体" } diff --git a/webapp_person_options.py b/webapp_person_options.py index 23419b67f..4c8b2b19c 100644 --- a/webapp_person_options.py +++ b/webapp_person_options.py @@ -20,6 +20,8 @@ from utils import get_domain_from_actor from utils import get_nickname_from_actor from utils import is_featured_writer from utils import acct_dir +from utils import text_in_file +from utils import remove_domain_port from blocking import is_blocked from follow import is_follower_of_person from follow import is_following_actor @@ -31,6 +33,108 @@ from webapp_utils import get_broken_link_substitute from webapp_utils import html_keyboard_navigation from webapp_utils import get_banner_file from webapp_utils import html_hide_from_screen_reader +from webapp_utils import minimizing_attached_images + + +def _minimize_attached_images(base_dir: str, nickname: str, domain: str, + following_nickname: str, + following_domain: str, + add: bool) -> None: + """Adds or removes a handle from the following.txt list into a list + indicating whether to minimize images from that account + """ + # check that a following file exists + domain = remove_domain_port(domain) + following_filename = \ + acct_dir(base_dir, nickname, domain) + '/following.txt' + if not os.path.isfile(following_filename): + print("WARN: following.txt doesn't exist for " + + nickname + '@' + domain) + return + handle = following_nickname + '@' + following_domain + + # check that you are following this handle + if text_in_file(handle + '\n', following_filename): + print('WARN: ' + handle + ' is not in ' + following_filename) + return + + minimize_filename = \ + acct_dir(base_dir, nickname, domain) + '/followingMinimizeImages.txt' + + # get the contents of the minimize file, which is + # a set of handles + following_handles = '' + if os.path.isfile(minimize_filename): + print('Minimize file exists') + try: + with open(minimize_filename, 'r', + encoding='utf-8') as minimize_file: + following_handles = minimize_file.read() + except OSError: + print('EX: minimize_attached_images ' + minimize_filename) + else: + # create a new minimize file from the following file + print('Creating minimize file ' + minimize_filename) + following_handles = '' + try: + with open(following_filename, 'r', + encoding='utf-8') as following_file: + following_handles = following_file.read() + except OSError: + print('EX: minimize_attached_images 2 ' + minimize_filename) + if add: + try: + with open(minimize_filename, 'w+', + encoding='utf-8') as fp_min: + fp_min.write(following_handles + handle + '\n') + except OSError: + print('EX: minimize_attached_images unable to write ' + + minimize_filename) + + # already in the minimize file? + if handle + '\n' in following_handles: + print(handle + ' exists in followingMinimizeImages.txt') + if add: + # already added + return + # remove from minimize file + following_handles = following_handles.replace(handle + '\n', '') + try: + with open(minimize_filename, 'w+', + encoding='utf-8') as fp_min: + fp_min.write(following_handles) + except OSError: + print('EX: minimize_attached_images 3 ' + minimize_filename) + else: + print(handle + ' not in followingMinimizeImages.txt') + # not already in the minimize file + if add: + # append to the list of handles + following_handles += handle + '\n' + try: + with open(minimize_filename, 'w+', + encoding='utf-8') as fp_min: + fp_min.write(following_handles) + except OSError: + print('EX: minimize_attached_images 4 ' + minimize_filename) + + +def person_minimize_images(base_dir: str, nickname: str, domain: str, + following_nickname: str, + following_domain: str) -> None: + """Images from this person are minimized by default + """ + _minimize_attached_images(base_dir, nickname, domain, + following_nickname, following_domain, True) + + +def person_undo_minimize_images(base_dir: str, nickname: str, domain: str, + following_nickname: str, + following_domain: str) -> None: + """Images from this person are no longer minimized by default + """ + _minimize_attached_images(base_dir, nickname, domain, + following_nickname, following_domain, False) def html_person_options(default_timeline: str, @@ -336,6 +440,19 @@ def html_person_options(default_timeline: str, checkbox_str = checkbox_str.replace(' checked>', '>') options_str += checkbox_str + checkbox_str = \ + ' ' + \ + translate['Minimize attached images'] + \ + '\n
\n' + if not minimizing_attached_images(base_dir, nickname, domain, + options_nickname, + options_domain_full): + checkbox_str = checkbox_str.replace(' checked>', '>') + options_str += checkbox_str + # checkbox for permission to post to newswire newswire_posts_permitted = False if options_domain_full == domain_full: diff --git a/webapp_post.py b/webapp_post.py index 817e575d5..5625f8a8d 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -2042,7 +2042,8 @@ def individual_post_as_html(signing_priv_key_pem: str, _log_post_timing(enable_timing_log, post_start_time, '14') attachment_str, gallery_str = \ - get_post_attachments_as_html(base_dir, domain_full, + get_post_attachments_as_html(base_dir, nickname, domain, + domain_full, post_json_object, box_name, translate, is_muted, avatar_link, diff --git a/webapp_utils.py b/webapp_utils.py index f5b2725f6..b790eabff 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -21,6 +21,7 @@ from utils import get_cached_post_filename from utils import get_config_param from utils import acct_dir from utils import get_nickname_from_actor +from utils import get_domain_from_actor from utils import is_float from utils import get_audio_extensions from utils import get_video_extensions @@ -35,6 +36,41 @@ from posts import is_moderator from blocking import is_blocked +def minimizing_attached_images(base_dir: str, nickname: str, domain: str, + following_nickname: str, + following_domain: str) -> bool: + """Returns true if images from the account being followed should be + minimized by default + """ + if following_nickname == nickname and following_domain == domain: + # reminder post + return False + minimize_filename = \ + acct_dir(base_dir, nickname, domain) + '/followingMinimizeImages.txt' + handle = following_nickname + '@' + following_domain + if not os.path.isfile(minimize_filename): + following_filename = \ + acct_dir(base_dir, nickname, domain) + '/following.txt' + if not os.path.isfile(following_filename): + return False + # create a new minimize file from the following file + following_handles = None + try: + with open(following_filename, 'r', + encoding='utf-8') as following_file: + following_handles = following_file.read() + except OSError: + print('EX: minimizing_attached_images ' + following_filename) + if following_handles: + try: + with open(minimize_filename, 'w+', + encoding='utf-8') as fp_cal: + fp_cal.write(following_handles) + except OSError: + print('EX: minimizing_attached_images 2 ' + minimize_filename) + return text_in_file(handle + '\n', minimize_filename) + + def get_broken_link_substitute() -> str: """Returns html used to show a default image if the link to an image is broken @@ -1092,7 +1128,9 @@ def _is_attached_video(attachment_filename: str) -> bool: return False -def get_post_attachments_as_html(base_dir: str, domain_full: str, +def get_post_attachments_as_html(base_dir: str, + nickname: str, domain: str, + domain_full: str, post_json_object: {}, box_name: str, translate: {}, is_muted: bool, avatar_link: str, @@ -1184,12 +1222,43 @@ def get_post_attachments_as_html(base_dir: str, domain_full: str, gallery_str += ' \n' gallery_str += '\n' + # optionally hide the image + attributed_actor = None + minimize_images = False + if post_json_object['object'].get('attributedTo'): + if isinstance(post_json_object['object']['attributedTo'], + str): + attributed_actor = \ + post_json_object['object']['attributedTo'] + if attributed_actor: + following_nickname = \ + get_nickname_from_actor(attributed_actor) + following_domain, _ = \ + get_domain_from_actor(attributed_actor) + minimize_images = \ + minimizing_attached_images(base_dir, nickname, domain, + following_nickname, + following_domain) + + if minimize_images: + show_img_str = 'SHOW MEDIA' + if translate: + show_img_str = translate['SHOW MEDIA'] + attachment_str += \ + '
' + \ + show_img_str + '' + \ + '
\n' + attachment_str += '' attachment_str += \ '' + image_description + '\n' + + if minimize_images: + attachment_str += '
\n' + attachment_ctr += 1 elif _is_video_mime_type(media_type): if _is_attached_video(attach['url']):