From 11e6a89f2f13bf9be39fa5a1614279848b235917 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 24 Dec 2023 15:53:11 +0000 Subject: [PATCH] Option to now show follows on profile screen --- daemon.py | 53 ++++++++++++++++++++++++++++++++++++++++++++ person.py | 5 +++++ 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/fa.json | 3 ++- translations/fr.json | 3 ++- translations/ga.json | 3 ++- translations/he.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 | 19 ++++++++++++++++ webapp_profile.py | 18 +++++++++++++-- 31 files changed, 147 insertions(+), 29 deletions(-) diff --git a/daemon.py b/daemon.py index 5a0a8d697..1b870a711 100644 --- a/daemon.py +++ b/daemon.py @@ -347,6 +347,7 @@ from utils import get_occupation_name from utils import set_occupation_name from utils import load_translations_from_file from utils import load_bold_reading +from utils import load_hide_follows from utils import get_local_network_addresses from utils import decoded_host from utils import is_public_post @@ -8051,6 +8052,33 @@ class PubServer(BaseHTTPRequestHandler): 'repliesFromMutualsOnly file ' + show_replies_mutuals_file) + # hide follows checkbox + hide_follows_filename = \ + acct_dir(base_dir, nickname, domain) + \ + '/.bideFollows' + hide_follows = False + if fields.get('hideFollows'): + if fields['hideFollows'] == 'on': + hide_follows = True + self.server.hide_follows[nickname] = True + try: + with open(hide_follows_filename, 'w+', + encoding='utf-8') as rfile: + rfile.write('\n') + except OSError: + print('EX: unable to write hideFollows ' + + hide_follows_filename) + if not hide_follows: + if self.server.hide_follows.get(nickname): + del self.server.hide_follows[nickname] + if os.path.isfile(hide_follows_filename): + try: + os.remove(hide_follows_filename) + except OSError: + print('EX: _profile_edit ' + + 'unable to delete ' + + hide_follows_filename) + # block military instances block_mil_instances = False if fields.get('blockMilitary'): @@ -15483,6 +15511,9 @@ class PubServer(BaseHTTPRequestHandler): bold_reading = False if self.server.bold_reading.get(nickname): bold_reading = True + if not authorized and \ + self.server.hide_follows.get(nickname): + following = {} max_shares_on_profile = \ self.server.max_shares_on_profile sites_unavailable = \ @@ -15538,6 +15569,14 @@ class PubServer(BaseHTTPRequestHandler): return True else: if self._secure_mode(curr_session, proxy_type): + if '/users/' in path: + nickname = path.split('/users/')[1] + if '/' in nickname: + nickname = nickname.split('/')[0] + if nickname and not authorized and \ + self.server.hide_follows.get(nickname): + following = {} + msg_str = json.dumps(following, ensure_ascii=False) msg_str = self._convert_domains(calling_domain, @@ -15925,6 +15964,9 @@ class PubServer(BaseHTTPRequestHandler): bold_reading = False if self.server.bold_reading.get(nickname): bold_reading = True + if not authorized and \ + self.server.hide_follows.get(nickname): + followers = {} max_shares_on_profile = \ self.server.max_shares_on_profile sites_unavailable = \ @@ -15981,6 +16023,14 @@ class PubServer(BaseHTTPRequestHandler): return True else: if self._secure_mode(curr_session, proxy_type): + if '/users/' in path: + nickname = path.split('/users/')[1] + if '/' in nickname: + nickname = nickname.split('/')[0] + if nickname and not authorized and \ + self.server.hide_follows.get(nickname): + followers = {} + msg_str = json.dumps(followers, ensure_ascii=False) msg_str = self._convert_domains(calling_domain, @@ -24183,6 +24233,9 @@ def run_daemon(public_replies_unlisted: int, # for each account, whether bold reading is enabled httpd.bold_reading = load_bold_reading(base_dir) + # whether to hide follows on profile screen for each account + httpd.hide_follows = load_hide_follows(base_dir) + httpd.account_timezone = load_account_timezones(base_dir) httpd.post_to_nickname = None diff --git a/person.py b/person.py index c78db305e..9694c400c 100644 --- a/person.py +++ b/person.py @@ -521,6 +521,7 @@ def _create_person_base(base_dir: str, nickname: str, domain: str, port: int, 'discoverable': True, 'indexable': False, 'memorial': False, + 'hideFollows': False, 'name': person_name, 'outbox': person_id + '/outbox', 'preferredUsername': person_name, @@ -850,6 +851,10 @@ def person_upgrade_actor(base_dir: str, person_json: {}, person_json['memorial'] = False update_actor = True + if not person_json.get('hideFollows'): + person_json['hideFollows'] = False + update_actor = True + if not person_json.get('indexable'): person_json['indexable'] = False update_actor = True diff --git a/translations/ar.json b/translations/ar.json index edd5e5b08..b46981e33 100644 --- a/translations/ar.json +++ b/translations/ar.json @@ -641,5 +641,6 @@ "offline": "غير متصل على الانترنت", "Mutuals": "التعاضد", "Public replies default to unlisted scope": "الردود العامة افتراضية للنطاق غير المدرج", - "About the author": "عن المؤلف" + "About the author": "عن المؤلف", + "Do not show follows on your profile": "لا تظهر المتابعات في ملفك الشخصي" } diff --git a/translations/bn.json b/translations/bn.json index 5031f0bf9..ffdf14a5e 100644 --- a/translations/bn.json +++ b/translations/bn.json @@ -641,5 +641,6 @@ "offline": "অফলাইন", "Mutuals": "পারস্পরিক", "Public replies default to unlisted scope": "অতালিকাভুক্ত সুযোগে সর্বজনীন উত্তর ডিফল্ট", - "About the author": "লেখক সম্পর্কে" + "About the author": "লেখক সম্পর্কে", + "Do not show follows on your profile": "আপনার প্রোফাইলে অনুসরণ দেখাবেন না" } diff --git a/translations/ca.json b/translations/ca.json index ddacbc135..6698ea1e7 100644 --- a/translations/ca.json +++ b/translations/ca.json @@ -641,5 +641,6 @@ "offline": "fora de línia", "Mutuals": "Mútues", "Public replies default to unlisted scope": "Les respostes públiques són per defecte a l'abast no llistat", - "About the author": "Sobre l’autor" + "About the author": "Sobre l’autor", + "Do not show follows on your profile": "No mostris els seguidors al teu perfil" } diff --git a/translations/cy.json b/translations/cy.json index 74ef04f2f..51aefb06e 100644 --- a/translations/cy.json +++ b/translations/cy.json @@ -641,5 +641,6 @@ "offline": "all-lein", "Mutuals": "Cydfuddiol", "Public replies default to unlisted scope": "Ymatebion cyhoeddus rhagosodedig i gwmpas heb ei restru", - "About the author": "Am yr awdur" + "About the author": "Am yr awdur", + "Do not show follows on your profile": "Peidiwch â dangos dilyniannau ar eich proffil" } diff --git a/translations/de.json b/translations/de.json index b9f16111c..de39918f0 100644 --- a/translations/de.json +++ b/translations/de.json @@ -641,5 +641,6 @@ "offline": "offline", "Mutuals": "Gegenseitigkeitsgesellschaften", "Public replies default to unlisted scope": "Öffentliche Antworten werden standardmäßig auf den nicht aufgeführten Bereich übertragen", - "About the author": "Über den Autor" + "About the author": "Über den Autor", + "Do not show follows on your profile": "Zeigen Sie keine Follower in Ihrem Profil an" } diff --git a/translations/el.json b/translations/el.json index a504f8c7e..1780f885b 100644 --- a/translations/el.json +++ b/translations/el.json @@ -641,5 +641,6 @@ "offline": "εκτός σύνδεσης", "Mutuals": "Αμοιβαία", "Public replies default to unlisted scope": "Οι δημόσιες απαντήσεις από προεπιλογή στο μη καταχωρισμένο εύρος", - "About the author": "Σχετικά με τον Συγγραφέα" + "About the author": "Σχετικά με τον Συγγραφέα", + "Do not show follows on your profile": "Μην εμφανίζονται οι ακόλουθοι στο προφίλ σας" } diff --git a/translations/en.json b/translations/en.json index fd1a1f9b6..202bd2641 100644 --- a/translations/en.json +++ b/translations/en.json @@ -641,5 +641,6 @@ "offline": "offline", "Mutuals": "Mutuals", "Public replies default to unlisted scope": "Public replies default to unlisted scope", - "About the author": "About the author" + "About the author": "About the author", + "Do not show follows on your profile": "Do not show follows on your profile" } diff --git a/translations/es.json b/translations/es.json index 0f22f40e9..a63410dea 100644 --- a/translations/es.json +++ b/translations/es.json @@ -641,5 +641,6 @@ "offline": "desconectada", "Mutuals": "Mutuales", "Public replies default to unlisted scope": "Las respuestas públicas tienen por defecto un alcance no listado", - "About the author": "Sobre el Autor" + "About the author": "Sobre el Autor", + "Do not show follows on your profile": "No mostrar seguidores en tu perfil" } diff --git a/translations/fa.json b/translations/fa.json index 3623c9e21..8536b843a 100644 --- a/translations/fa.json +++ b/translations/fa.json @@ -641,5 +641,6 @@ "offline": "آفلاین", "Mutuals": "متقابل", "Public replies default to unlisted scope": "پاسخ‌های عمومی به‌طور پیش‌فرض به محدوده فهرست نشده است", - "About the author": "درباره نویسنده" + "About the author": "درباره نویسنده", + "Do not show follows on your profile": "فالوورها را در نمایه خود نشان ندهید" } diff --git a/translations/fr.json b/translations/fr.json index 4deb69be8..82ff5697d 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -641,5 +641,6 @@ "offline": "hors ligne", "Mutuals": "Mutuelles", "Public replies default to unlisted scope": "Les réponses publiques ont par défaut une portée non répertoriée", - "About the author": "A propos de l'auteur" + "About the author": "A propos de l'auteur", + "Do not show follows on your profile": "Ne pas afficher les suivis sur votre profil" } diff --git a/translations/ga.json b/translations/ga.json index f55c61b64..c8b7cfbef 100644 --- a/translations/ga.json +++ b/translations/ga.json @@ -641,5 +641,6 @@ "offline": "as líne", "Mutuals": "Comhpháirteacha", "Public replies default to unlisted scope": "Freagraí poiblí réamhshocraithe ar scóip neamhliostaithe", - "About the author": "Faoin tÚdar" + "About the author": "Faoin tÚdar", + "Do not show follows on your profile": "Ná taispeáin na nithe seo a leanas ar do phróifíl" } diff --git a/translations/he.json b/translations/he.json index fe933625d..8ecf20519 100644 --- a/translations/he.json +++ b/translations/he.json @@ -641,5 +641,6 @@ "offline": "במצב לא מקוון", "Mutuals": "הדדיות", "Public replies default to unlisted scope": "תשובות ציבוריות כברירת מחדל להיקף לא רשום", - "About the author": "על הסופר" + "About the author": "על הסופר", + "Do not show follows on your profile": "אל תראה עוקבים בפרופיל שלך" } diff --git a/translations/hi.json b/translations/hi.json index ac830458f..a6bf9afd7 100644 --- a/translations/hi.json +++ b/translations/hi.json @@ -641,5 +641,6 @@ "offline": "ऑफलाइन", "Mutuals": "पारस्परिक", "Public replies default to unlisted scope": "सार्वजनिक उत्तर डिफ़ॉल्ट रूप से असूचीबद्ध दायरे में आते हैं", - "About the author": "लेखक के बारे में" + "About the author": "लेखक के बारे में", + "Do not show follows on your profile": "अपनी प्रोफ़ाइल पर फ़ॉलो न दिखाएं" } diff --git a/translations/it.json b/translations/it.json index 7947c7dab..8f55e1cd4 100644 --- a/translations/it.json +++ b/translations/it.json @@ -641,5 +641,6 @@ "offline": "disconnessa", "Mutuals": "Mutui", "Public replies default to unlisted scope": "Per impostazione predefinita, le risposte pubbliche hanno un ambito non elencato", - "About the author": "Circa l'autore" + "About the author": "Circa l'autore", + "Do not show follows on your profile": "Non mostrare follower sul tuo profilo" } diff --git a/translations/ja.json b/translations/ja.json index 217f9a9c4..c74a98ff2 100644 --- a/translations/ja.json +++ b/translations/ja.json @@ -641,5 +641,6 @@ "offline": "オフライン", "Mutuals": "相互作用", "Public replies default to unlisted scope": "パブリック返信はデフォルトで非公開スコープになります", - "About the author": "著者について" + "About the author": "著者について", + "Do not show follows on your profile": "プロフィールにフォローを表示しない" } diff --git a/translations/ko.json b/translations/ko.json index 652827be0..710d7ccfc 100644 --- a/translations/ko.json +++ b/translations/ko.json @@ -641,5 +641,6 @@ "offline": "오프라인", "Mutuals": "상호", "Public replies default to unlisted scope": "공개 답글은 기본적으로 비공개 범위로 설정됩니다.", - "About the author": "저자에 대해" + "About the author": "저자에 대해", + "Do not show follows on your profile": "프로필에 팔로우를 표시하지 않습니다." } diff --git a/translations/ku.json b/translations/ku.json index 10464537c..6b0e988b7 100644 --- a/translations/ku.json +++ b/translations/ku.json @@ -641,5 +641,6 @@ "offline": "offline", "Mutuals": "Mutuals", "Public replies default to unlisted scope": "Bersivên gelemperî ji bo çarçoveyek nelîstekirî xwerû dide", - "About the author": "Di derbarê nivîskarê de" + "About the author": "Di derbarê nivîskarê de", + "Do not show follows on your profile": "Li ser profîla xwe şopandinê nîşan nedin" } diff --git a/translations/nl.json b/translations/nl.json index a68907cd6..57e28e312 100644 --- a/translations/nl.json +++ b/translations/nl.json @@ -641,5 +641,6 @@ "offline": "offline", "Mutuals": "Mutualiteiten", "Public replies default to unlisted scope": "Openbare antwoorden hebben standaard een niet-vermeld bereik", - "About the author": "Over de auteur" + "About the author": "Over de auteur", + "Do not show follows on your profile": "Laat geen volgers zien op je profiel" } diff --git a/translations/oc.json b/translations/oc.json index b8e6f0501..fc6a2a481 100644 --- a/translations/oc.json +++ b/translations/oc.json @@ -637,5 +637,6 @@ "offline": "offline", "Mutuals": "Mutuals", "Public replies default to unlisted scope": "Public replies default to unlisted scope", - "About the author": "About the author" + "About the author": "About the author", + "Do not show follows on your profile": "Do not show follows on your profile" } diff --git a/translations/pl.json b/translations/pl.json index 8838d64da..77a2fa6fc 100644 --- a/translations/pl.json +++ b/translations/pl.json @@ -641,5 +641,6 @@ "offline": "nieaktywny", "Mutuals": "Wzajemne relacje", "Public replies default to unlisted scope": "Odpowiedzi publiczne domyślnie mają zakres niepubliczny", - "About the author": "O autorze" + "About the author": "O autorze", + "Do not show follows on your profile": "Nie pokazuj obserwujących w swoim profilu" } diff --git a/translations/pt.json b/translations/pt.json index 82216d9c4..f363b078f 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -641,5 +641,6 @@ "offline": "desligada", "Mutuals": "Mútuas", "Public replies default to unlisted scope": "As respostas públicas são padronizadas para escopo não listado", - "About the author": "Sobre o autor" + "About the author": "Sobre o autor", + "Do not show follows on your profile": "Não mostre seguidores em seu perfil" } diff --git a/translations/ru.json b/translations/ru.json index 20b44102e..7b8ab3dbb 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -641,5 +641,6 @@ "offline": "не в сети", "Mutuals": "Взаимные отношения", "Public replies default to unlisted scope": "Публичные ответы по умолчанию имеют скрытую область действия.", - "About the author": "Об авторе" + "About the author": "Об авторе", + "Do not show follows on your profile": "Не показывать подписчиков в своем профиле" } diff --git a/translations/sw.json b/translations/sw.json index 50e7a97c7..2be49c975 100644 --- a/translations/sw.json +++ b/translations/sw.json @@ -641,5 +641,6 @@ "offline": "nje ya mtandao", "Mutuals": "Kuheshimiana", "Public replies default to unlisted scope": "Majibu ya umma kwa chaguomsingi kwa upeo ambao haujaorodheshwa", - "About the author": "Kuhusu mwandishi" + "About the author": "Kuhusu mwandishi", + "Do not show follows on your profile": "Usionyeshe wafuasi kwenye wasifu wako" } diff --git a/translations/tr.json b/translations/tr.json index 8c533a4d9..e52dc24e0 100644 --- a/translations/tr.json +++ b/translations/tr.json @@ -641,5 +641,6 @@ "offline": "çevrimdışı", "Mutuals": "Karşılıklar", "Public replies default to unlisted scope": "Genel yanıtlar varsayılan olarak liste dışı kapsama alınır", - "About the author": "Yazar hakkında" + "About the author": "Yazar hakkında", + "Do not show follows on your profile": "Takip edilenleri profilinizde gösterme" } diff --git a/translations/uk.json b/translations/uk.json index 333dc190f..59a652429 100644 --- a/translations/uk.json +++ b/translations/uk.json @@ -641,5 +641,6 @@ "offline": "офлайн", "Mutuals": "Мутуали", "Public replies default to unlisted scope": "Загальнодоступні відповіді за умовчанням мають приватний обсяг", - "About the author": "Про автора" + "About the author": "Про автора", + "Do not show follows on your profile": "Не показувати підписки у вашому профілі" } diff --git a/translations/yi.json b/translations/yi.json index a4bd037c0..31de3c6b8 100644 --- a/translations/yi.json +++ b/translations/yi.json @@ -641,5 +641,6 @@ "offline": "אָפפלינע", "Mutuals": "קעגנצייַטיק", "Public replies default to unlisted scope": "ציבור ענטפֿערס פעליקייַט צו אַנליסטעד פאַרנעם", - "About the author": "וועגן דעם מחבר" + "About the author": "וועגן דעם מחבר", + "Do not show follows on your profile": "דו זאלסט נישט ווייַזן די פאלגענדע אויף דיין פּראָפיל" } diff --git a/translations/zh.json b/translations/zh.json index e7b1f0656..047a65a11 100644 --- a/translations/zh.json +++ b/translations/zh.json @@ -641,5 +641,6 @@ "offline": "离线", "Mutuals": "互助基金", "Public replies default to unlisted scope": "公开回复默认为不公开范围", - "About the author": "关于作者" + "About the author": "关于作者", + "Do not show follows on your profile": "不要在您的个人资料上显示关注者" } diff --git a/utils.py b/utils.py index 2d472f911..02929b788 100644 --- a/utils.py +++ b/utils.py @@ -4173,6 +4173,25 @@ def load_bold_reading(base_dir: str) -> {}: return bold_reading +def load_hide_follows(base_dir: str) -> {}: + """Returns a dictionary containing the hide follows status for each account + """ + hide_follows = {} + for _, dirs, _ in os.walk(base_dir + '/accounts'): + for acct in dirs: + if '@' not in acct: + continue + if acct.startswith('inbox@') or acct.startswith('Actor@'): + continue + hide_follows_filename = \ + base_dir + '/accounts/' + acct + '/.hideFollows' + if os.path.isfile(hide_follows_filename): + nickname = acct.split('@')[0] + hide_follows[nickname] = True + break + return hide_follows + + def get_account_timezone(base_dir: str, nickname: str, domain: str) -> str: """Returns the timezone for the given account """ diff --git a/webapp_profile.py b/webapp_profile.py index 2f1d947cd..d52606059 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -1632,6 +1632,11 @@ def _html_profile_following(translate: {}, base_dir: str, http_prefix: str, translate['Page up'] + '">\n' + \ ' \n' + if not following_json: + following_json = { + 'orderedItems': [] + } + for following_actor in following_json['orderedItems']: # is this a dormant followed account? dormant = False @@ -2623,7 +2628,8 @@ def _html_edit_profile_options(is_admin: bool, reverse_sequence: [], show_vote_posts: bool, show_replies_followers: bool, - show_replies_mutuals: bool) -> str: + show_replies_mutuals: bool, + hide_follows: bool) -> str: """option checkboxes section of edit profile screen """ edit_profile_form = '
\n' @@ -2685,6 +2691,9 @@ def _html_edit_profile_options(is_admin: bool, edit_profile_form += \ edit_check_box(show_replies_mutuals_str, 'repliesFromMutualsOnly', show_replies_mutuals) + hide_follows_str = translate['Do not show follows on your profile'] + edit_profile_form += \ + edit_check_box(hide_follows_str, 'hideFollows', hide_follows) edit_profile_form += '
\n' return edit_profile_form @@ -3070,6 +3079,11 @@ def html_edit_profile(server, translate: {}, if os.path.isfile(account_dir + '/.repliesFromMutualsOnly'): show_replies_mutuals = True + # don't show follows on profile + hide_follows = False + if os.path.isfile(account_dir + '/.hideFollows'): + hide_follows = True + # Option checkboxes edit_profile_form += \ _html_edit_profile_options(is_admin, manually_approves_followers, @@ -3082,7 +3096,7 @@ def html_edit_profile(server, translate: {}, nickname, min_images_for_accounts, reverse_sequence, show_vote_posts, show_replies_followers, - show_replies_mutuals) + show_replies_mutuals, hide_follows) # Contact information edit_profile_form += \