From 49f767348174ccda16ba5bd2772f7bb46458fb25 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 20 Jun 2023 11:42:25 +0100 Subject: [PATCH] Option to only receive replies from followers --- daemon.py | 28 ++++++++++++++++++++++++++++ inbox.py | 35 +++++++++++++++++++++++++++++++++++ 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/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 | 15 +++++++++++++-- 29 files changed, 128 insertions(+), 28 deletions(-) diff --git a/daemon.py b/daemon.py index a63a8155b..d612cf440 100644 --- a/daemon.py +++ b/daemon.py @@ -7638,6 +7638,34 @@ class PubServer(BaseHTTPRequestHandler): print('EX: unable to write noVotes file ' + show_vote_file) + # show replies only from followers checkbox + show_replies_followers = False + if fields.get('repliesFromFollowersOnly'): + if fields['repliesFromFollowersOnly'] == 'on': + show_replies_followers = True + account_dir = acct_dir(self.server.base_dir, + nickname, self.server.domain) + show_replies_followers_file = \ + account_dir + '/.repliesFromFollowersOnly' + if os.path.isfile(show_replies_followers_file): + if not show_replies_followers: + try: + os.remove(show_replies_followers_file) + except OSError: + print('EX: unable to remove ' + + 'repliesFromFollowersOnly file ' + + show_replies_followers_file) + else: + if show_replies_followers: + try: + with open(show_replies_followers_file, 'w+', + encoding='utf-8') as fp_replies: + fp_replies.write('\n') + except OSError: + print('EX: unable to write ' + + 'repliesFromFollowersOnly file ' + + show_replies_followers_file) + # notify about new Likes if on_final_welcome_screen: # default setting from welcome screen diff --git a/inbox.py b/inbox.py index c2db90d02..2ad5534a3 100644 --- a/inbox.py +++ b/inbox.py @@ -621,6 +621,32 @@ def inbox_permitted_message(domain: str, message_json: {}, return True +def _deny_non_follower(base_dir: str, nickname: str, domain: str, + reply_nickname: str, reply_domain: str, + sending_actor: str): + """Returns true if replying to an account which is not a follower. + This only applies if 'Only replies from followers' is selected on + the edit profile secreen + """ + # Is this a reply to something written from this account? + if reply_nickname != nickname or reply_domain != domain: + return False + + # has this account specified to only receive replies from followers? + account_dir = acct_dir(base_dir, nickname, domain) + if not os.path.isfile(account_dir + '/.repliesFromFollowersOnly'): + return False + + # is the sending actor a follower? + follower_nickname = get_nickname_from_actor(sending_actor) + follower_domain, _ = get_domain_from_actor(sending_actor) + if not is_follower_of_person(base_dir, nickname, domain, + follower_nickname, follower_domain): + return True + + return False + + def save_post_to_inbox_queue(base_dir: str, http_prefix: str, nickname: str, domain: str, post_json_object: {}, @@ -727,6 +753,15 @@ def save_post_to_inbox_queue(base_dir: str, http_prefix: str, ' to a blocked account: ' + reply_nickname + '@' + reply_domain) return None + if _deny_non_follower(base_dir, nickname, domain, + reply_nickname, reply_domain, + actor): + if debug: + print('WARN: post contains reply from ' + + str(actor) + + ' who is not a follower of ' + + nickname + '@' + domain) + return None # filter on the content of the post if content_str: diff --git a/translations/ar.json b/translations/ar.json index b8b1c9c81..56ae3f49a 100644 --- a/translations/ar.json +++ b/translations/ar.json @@ -623,5 +623,6 @@ "Transcript": "نص", "Show vote posts": "إظهار مشاركات التصويت", "Featured hashtags": "علامات التجزئة المميزة", - "Proxy": "الوكيل" + "Proxy": "الوكيل", + "Only allow replies from followers": "السماح فقط بالردود من المتابعين" } diff --git a/translations/bn.json b/translations/bn.json index c5fb729c8..9632ab9ea 100644 --- a/translations/bn.json +++ b/translations/bn.json @@ -623,5 +623,6 @@ "Transcript": "প্রতিলিপি", "Show vote posts": "ভোট পোস্ট দেখান", "Featured hashtags": "বৈশিষ্ট্যযুক্ত হ্যাশট্যাগ", - "Proxy": "প্রক্সি" + "Proxy": "প্রক্সি", + "Only allow replies from followers": "শুধুমাত্র অনুসরণকারীদের কাছ থেকে উত্তরের অনুমতি দিন" } diff --git a/translations/ca.json b/translations/ca.json index ddda30d66..1dfc9e6c8 100644 --- a/translations/ca.json +++ b/translations/ca.json @@ -623,5 +623,6 @@ "Transcript": "Transcripció", "Show vote posts": "Mostra les publicacions de vot", "Featured hashtags": "Hashtags destacats", - "Proxy": "Proxy" + "Proxy": "Proxy", + "Only allow replies from followers": "Només permet respostes dels seguidors" } diff --git a/translations/cy.json b/translations/cy.json index b69e0209e..3bc78799a 100644 --- a/translations/cy.json +++ b/translations/cy.json @@ -623,5 +623,6 @@ "Transcript": "Trawsgrifiad", "Show vote posts": "Dangos postiadau pleidlais", "Featured hashtags": "Hashtags dan sylw", - "Proxy": "Dirprwy" + "Proxy": "Dirprwy", + "Only allow replies from followers": "Caniatewch atebion gan ddilynwyr yn unig" } diff --git a/translations/de.json b/translations/de.json index 917b4f800..40d4744ad 100644 --- a/translations/de.json +++ b/translations/de.json @@ -623,5 +623,6 @@ "Transcript": "Abschrift", "Show vote posts": "Abstimmungsbeiträge anzeigen", "Featured hashtags": "Ausgewählte Hashtags", - "Proxy": "Stellvertreterin" + "Proxy": "Stellvertreterin", + "Only allow replies from followers": "Erlauben Sie nur Antworten von Followern" } diff --git a/translations/el.json b/translations/el.json index 779c2520c..33a3a259b 100644 --- a/translations/el.json +++ b/translations/el.json @@ -623,5 +623,6 @@ "Transcript": "Αντίγραφο", "Show vote posts": "Εμφάνιση ψηφοφοριακών αναρτήσεων", "Featured hashtags": "Επιλεγμένα hashtag", - "Proxy": "Πληρεξούσιο" + "Proxy": "Πληρεξούσιο", + "Only allow replies from followers": "Επιτρέπονται μόνο οι απαντήσεις από τους ακόλουθους" } diff --git a/translations/en.json b/translations/en.json index ecf177281..a91a79887 100644 --- a/translations/en.json +++ b/translations/en.json @@ -623,5 +623,6 @@ "Transcript": "Transcript", "Show vote posts": "Show vote posts", "Featured hashtags": "Featured hashtags", - "Proxy": "Proxy" + "Proxy": "Proxy", + "Only allow replies from followers": "Only allow replies from followers" } diff --git a/translations/es.json b/translations/es.json index db3d40cd1..bc4123dcc 100644 --- a/translations/es.json +++ b/translations/es.json @@ -623,5 +623,6 @@ "Transcript": "Transcripción", "Show vote posts": "Mostrar publicaciones de votos", "Featured hashtags": "Hashtags destacados", - "Proxy": "Apoderada" + "Proxy": "Apoderada", + "Only allow replies from followers": "Permitir solo respuestas de seguidores" } diff --git a/translations/fa.json b/translations/fa.json index 52ecf1b61..2623ffe5c 100644 --- a/translations/fa.json +++ b/translations/fa.json @@ -623,5 +623,6 @@ "Transcript": "رونوشت", "Show vote posts": "نمایش پست های رای", "Featured hashtags": "هشتگ های ویژه", - "Proxy": "پروکسی" + "Proxy": "پروکسی", + "Only allow replies from followers": "فقط اجازه پاسخ از طرفداران را بدهید" } diff --git a/translations/fr.json b/translations/fr.json index b83ee8d9d..12c1e7913 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -623,5 +623,6 @@ "Transcript": "Transcription", "Show vote posts": "Afficher les messages de vote", "Featured hashtags": "Mots-clics en vedette", - "Proxy": "Procuration" + "Proxy": "Procuration", + "Only allow replies from followers": "Autoriser uniquement les réponses des abonnés" } diff --git a/translations/ga.json b/translations/ga.json index eb32f4d96..605cf95b3 100644 --- a/translations/ga.json +++ b/translations/ga.json @@ -623,5 +623,6 @@ "Transcript": "Athscríbhinn", "Show vote posts": "Taispeáin postálacha vótaí", "Featured hashtags": "Hashtags faoi thrácht", - "Proxy": "Seachfhreastalaí" + "Proxy": "Seachfhreastalaí", + "Only allow replies from followers": "Ná ceadaigh ach freagraí ó leantóirí" } diff --git a/translations/hi.json b/translations/hi.json index 309773a29..fe0851fdd 100644 --- a/translations/hi.json +++ b/translations/hi.json @@ -623,5 +623,6 @@ "Transcript": "प्रतिलिपि", "Show vote posts": "वोट पोस्ट दिखाएं", "Featured hashtags": "विशेष रुप से प्रदर्शित हैशटैग", - "Proxy": "प्रतिनिधि" + "Proxy": "प्रतिनिधि", + "Only allow replies from followers": "केवल अनुयायियों के उत्तरों की अनुमति दें" } diff --git a/translations/it.json b/translations/it.json index 6ddcf2339..867e0aa7e 100644 --- a/translations/it.json +++ b/translations/it.json @@ -623,5 +623,6 @@ "Transcript": "Trascrizione", "Show vote posts": "Mostra messaggi di voto", "Featured hashtags": "Hashtag in primo piano", - "Proxy": "Delega" + "Proxy": "Delega", + "Only allow replies from followers": "Consenti solo risposte dai follower" } diff --git a/translations/ja.json b/translations/ja.json index 450ac2394..eb0b715bb 100644 --- a/translations/ja.json +++ b/translations/ja.json @@ -623,5 +623,6 @@ "Transcript": "成績証明書", "Show vote posts": "投票投稿を表示", "Featured hashtags": "注目のハッシュタグ", - "Proxy": "プロキシー" + "Proxy": "プロキシー", + "Only allow replies from followers": "フォロワーからの返信のみを許可する" } diff --git a/translations/ko.json b/translations/ko.json index d0114db6a..2f20023c1 100644 --- a/translations/ko.json +++ b/translations/ko.json @@ -623,5 +623,6 @@ "Transcript": "성적 증명서", "Show vote posts": "투표 게시물 표시", "Featured hashtags": "추천 해시태그", - "Proxy": "대리" + "Proxy": "대리", + "Only allow replies from followers": "팔로어의 답글만 허용" } diff --git a/translations/ku.json b/translations/ku.json index e66fd5662..1192f96d9 100644 --- a/translations/ku.json +++ b/translations/ku.json @@ -623,5 +623,6 @@ "Transcript": "Transcript", "Show vote posts": "Mesajên dengdanê nîşan bide", "Featured hashtags": "Hashtagên taybetmendî", - "Proxy": "Proxy" + "Proxy": "Proxy", + "Only allow replies from followers": "Tenê destûr bidin bersivên ji şagirtan" } diff --git a/translations/nl.json b/translations/nl.json index 9283b4374..af3c34eaa 100644 --- a/translations/nl.json +++ b/translations/nl.json @@ -623,5 +623,6 @@ "Transcript": "Vertaling", "Show vote posts": "Toon stemberichten", "Featured hashtags": "Aanbevolen hashtags", - "Proxy": "Volmacht" + "Proxy": "Volmacht", + "Only allow replies from followers": "Sta alleen reacties van volgers toe" } diff --git a/translations/oc.json b/translations/oc.json index d7b2c5c19..0d703ed0d 100644 --- a/translations/oc.json +++ b/translations/oc.json @@ -619,5 +619,6 @@ "Transcript": "Transcript", "Show vote posts": "Show vote posts", "Featured hashtags": "Featured hashtags", - "Proxy": "Proxy" + "Proxy": "Proxy", + "Only allow replies from followers": "Only allow replies from followers" } diff --git a/translations/pl.json b/translations/pl.json index aafbeaf03..6926f014d 100644 --- a/translations/pl.json +++ b/translations/pl.json @@ -623,5 +623,6 @@ "Transcript": "Transkrypcja", "Show vote posts": "Pokaż posty z głosowaniem", "Featured hashtags": "Polecane hashtagi", - "Proxy": "Pełnomocnik" + "Proxy": "Pełnomocnik", + "Only allow replies from followers": "Zezwalaj tylko na odpowiedzi od obserwujących" } diff --git a/translations/pt.json b/translations/pt.json index 73e797ac0..c68b7146c 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -623,5 +623,6 @@ "Transcript": "Transcrição", "Show vote posts": "Mostrar postagens de votação", "Featured hashtags": "Hashtags em destaque", - "Proxy": "Proxy" + "Proxy": "Proxy", + "Only allow replies from followers": "Permitir apenas respostas de seguidores" } diff --git a/translations/ru.json b/translations/ru.json index 16c8ac36c..cc424eb96 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -623,5 +623,6 @@ "Transcript": "Стенограмма", "Show vote posts": "Показать сообщения для голосования", "Featured hashtags": "Избранные хэштеги", - "Proxy": "Прокси" + "Proxy": "Прокси", + "Only allow replies from followers": "Разрешить ответы только от подписчиков" } diff --git a/translations/sw.json b/translations/sw.json index 41cad4249..9732b4def 100644 --- a/translations/sw.json +++ b/translations/sw.json @@ -623,5 +623,6 @@ "Transcript": "Nakala", "Show vote posts": "Onyesha machapisho ya kura", "Featured hashtags": "Reli zilizoangaziwa", - "Proxy": "Wakala" + "Proxy": "Wakala", + "Only allow replies from followers": "Ruhusu tu majibu kutoka kwa wafuasi" } diff --git a/translations/tr.json b/translations/tr.json index d1478a4e6..1173b3f13 100644 --- a/translations/tr.json +++ b/translations/tr.json @@ -623,5 +623,6 @@ "Transcript": "Deşifre metni", "Show vote posts": "Oy gönderilerini göster", "Featured hashtags": "Öne çıkan etiketler", - "Proxy": "Vekil" + "Proxy": "Vekil", + "Only allow replies from followers": "Yalnızca takipçilerden gelen yanıtlara izin ver" } diff --git a/translations/uk.json b/translations/uk.json index 9f1f3887b..aebdc0600 100644 --- a/translations/uk.json +++ b/translations/uk.json @@ -623,5 +623,6 @@ "Transcript": "Стенограма", "Show vote posts": "Показати повідомлення про голосування", "Featured hashtags": "Рекомендовані хештеги", - "Proxy": "Проксі" + "Proxy": "Проксі", + "Only allow replies from followers": "Дозволити відповіді лише від підписників" } diff --git a/translations/yi.json b/translations/yi.json index 31aa6d57d..9a1cfe33f 100644 --- a/translations/yi.json +++ b/translations/yi.json @@ -623,5 +623,6 @@ "Transcript": "טראַנסקריפּט", "Show vote posts": "ווייַזן שטימען אַרטיקלען", "Featured hashtags": "פֿעיִקייטן פון hashtags", - "Proxy": "פראקסי" + "Proxy": "פראקסי", + "Only allow replies from followers": "נאָר לאָזן ענטפֿערס פון אנהענגערס" } diff --git a/translations/zh.json b/translations/zh.json index 160327d5f..d37157e58 100644 --- a/translations/zh.json +++ b/translations/zh.json @@ -623,5 +623,6 @@ "Transcript": "成绩单", "Show vote posts": "显示投票帖子", "Featured hashtags": "特色标签", - "Proxy": "代理人" + "Proxy": "代理人", + "Only allow replies from followers": "只允许关注者回复" } diff --git a/webapp_profile.py b/webapp_profile.py index 07772a90a..e981ee068 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -2443,7 +2443,8 @@ def _html_edit_profile_options(is_admin: bool, nickname: str, min_images_for_accounts: [], reverse_sequence: [], - show_vote_posts: bool) -> str: + show_vote_posts: bool, + show_replies_followers: bool) -> str: """option checkboxes section of edit profile screen """ edit_profile_form = '
\n' @@ -2497,6 +2498,10 @@ def _html_edit_profile_options(is_admin: bool, show_vote_posts_str = translate['Show vote posts'] edit_profile_form += \ edit_check_box(show_vote_posts_str, 'showVotes', show_vote_posts) + show_replies_followers_str = translate['Only allow replies from followers'] + edit_profile_form += \ + edit_check_box(show_replies_followers_str, 'repliesFromFollowersOnly', + show_replies_followers) edit_profile_form += '
\n' return edit_profile_form @@ -2869,6 +2874,11 @@ def html_edit_profile(server, translate: {}, if os.path.isfile(account_dir + '/.noVotes'): show_vote_posts = False + # only show replies from followers + show_replies_followers = False + if os.path.isfile(account_dir + '/.repliesFromFollowersOnly'): + show_replies_followers = False + # Option checkboxes edit_profile_form += \ _html_edit_profile_options(is_admin, manually_approves_followers, @@ -2879,7 +2889,8 @@ def html_edit_profile(server, translate: {}, hide_like_button, hide_reaction_button, translate, bold_reading, nickname, min_images_for_accounts, - reverse_sequence, show_vote_posts) + reverse_sequence, show_vote_posts, + show_replies_followers) # Contact information edit_profile_form += \