Ability to minimize images shown from followed accounts

merge-requests/25/head
Bob Mottram 2022-06-11 17:14:16 +01:00
parent a057d980cf
commit cae927c91d
31 changed files with 318 additions and 33 deletions

View File

@ -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,

View File

@ -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:

View File

@ -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

View File

@ -562,5 +562,7 @@
"End Time": "وقت النهاية",
"Switch to calendar view": "قم بالتبديل إلى عرض التقويم",
"Save": "يحفظ",
"Switch to moderation view": "قم بالتبديل إلى عرض الاعتدال"
"Switch to moderation view": "قم بالتبديل إلى عرض الاعتدال",
"Minimize attached images": "تصغير الصور المرفقة",
"SHOW MEDIA": "عرض الوسائط"
}

View File

@ -562,5 +562,7 @@
"End Time": "শেষ সময়",
"Switch to calendar view": "ক্যালেন্ডার ভিউতে স্যুইচ করুন",
"Save": "সংরক্ষণ",
"Switch to moderation view": "সংযম দৃশ্যে স্যুইচ করুন"
"Switch to moderation view": "সংযম দৃশ্যে স্যুইচ করুন",
"Minimize attached images": "সংযুক্ত ছবি ছোট করুন",
"SHOW MEDIA": "মিডিয়া দেখান"
}

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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"
}

View File

@ -562,5 +562,7 @@
"End Time": "Τέλος χρόνου",
"Switch to calendar view": "Μετάβαση σε προβολή ημερολογίου",
"Save": "Αποθηκεύσετε",
"Switch to moderation view": "Μετάβαση σε προβολή εποπτείας"
"Switch to moderation view": "Μετάβαση σε προβολή εποπτείας",
"Minimize attached images": "Ελαχιστοποιήστε τις συνημμένες εικόνες",
"SHOW MEDIA": "ΔΕΙΤΕ ΜΕΣΑ"
}

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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"
}

View File

@ -562,5 +562,7 @@
"End Time": "अंत समय",
"Switch to calendar view": "कैलेंडर दृश्य पर स्विच करें",
"Save": "बचाना",
"Switch to moderation view": "मॉडरेशन दृश्य पर स्विच करें"
"Switch to moderation view": "मॉडरेशन दृश्य पर स्विच करें",
"Minimize attached images": "संलग्न छवियों को छोटा करें",
"SHOW MEDIA": "मीडिया दिखाएं"
}

View File

@ -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"
}

View File

@ -562,5 +562,7 @@
"End Time": "終了時間",
"Switch to calendar view": "カレンダービューに切り替えます",
"Save": "保存",
"Switch to moderation view": "モデレートビューに切り替えます"
"Switch to moderation view": "モデレートビューに切り替えます",
"Minimize attached images": "添付画像を最小限に抑える",
"SHOW MEDIA": "メディアを表示"
}

View File

@ -562,5 +562,7 @@
"End Time": "종료 시간",
"Switch to calendar view": "캘린더 보기로 전환",
"Save": "구하다",
"Switch to moderation view": "검토 보기로 전환"
"Switch to moderation view": "검토 보기로 전환",
"Minimize attached images": "첨부된 이미지 최소화",
"SHOW MEDIA": "미디어 표시"
}

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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"
}

View File

@ -562,5 +562,7 @@
"End Time": "Время окончания",
"Switch to calendar view": "Переключиться на представление календаря",
"Save": "Сохранять",
"Switch to moderation view": "Перейти в режим модерации"
"Switch to moderation view": "Перейти в режим модерации",
"Minimize attached images": "Свернуть прикрепленные изображения",
"SHOW MEDIA": "ПОКАЗАТЬ МЕДИА"
}

View File

@ -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"
}

View File

@ -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"
}

View File

@ -562,5 +562,7 @@
"End Time": "Час закінчення",
"Switch to calendar view": "Перейти до перегляду календаря",
"Save": "Зберегти",
"Switch to moderation view": "Перейти до режиму модерації"
"Switch to moderation view": "Перейти до режиму модерації",
"Minimize attached images": "Мінімізуйте вкладені зображення",
"SHOW MEDIA": "ПОКАЗАТИ ЗМІ"
}

View File

@ -562,5 +562,7 @@
"End Time": "סוף צייט",
"Switch to calendar view": "באַשטימען צו די קאַלענדאַר מיינונג",
"Save": "היט",
"Switch to moderation view": "באַשטימען צו מאַדעריישאַן מיינונג"
"Switch to moderation view": "באַשטימען צו מאַדעריישאַן מיינונג",
"Minimize attached images": "מינאַמייז אַטאַטשט בילדער",
"SHOW MEDIA": "ווייַז מעדיע"
}

View File

@ -562,5 +562,7 @@
"End Time": "时间结束",
"Switch to calendar view": "切换到日历视图",
"Save": "节省",
"Switch to moderation view": "切换到审核视图"
"Switch to moderation view": "切换到审核视图",
"Minimize attached images": "最小化附加图像",
"SHOW MEDIA": "展示媒体"
}

View File

@ -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 = \
' <input type="checkbox" class="profilecheckbox" ' + \
'name="minimizeImages" checked> ' + \
translate['Minimize attached images'] + \
'\n <button type="submit" class="buttonsmall" ' + \
'name="submitMinimizeImages">' + \
translate['Save'] + '</button><br>\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:

View File

@ -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,

View File

@ -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 += ' </div>\n'
gallery_str += '</div>\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 += \
'<details><summary class="cw" tabindex="10">' + \
show_img_str + '</summary>' + \
'<div id="' + post_id + '">\n'
attachment_str += '<a href="' + image_url + '" tabindex="10">'
attachment_str += \
'<img loading="lazy" decoding="async" ' + \
'src="' + image_url + \
'" alt="' + image_description + '" title="' + \
image_description + '" class="attachment"></a>\n'
if minimize_images:
attachment_str += '</div></details>\n'
attachment_ctr += 1
elif _is_video_mime_type(media_type):
if _is_attached_video(attach['url']):