diff --git a/announce.py b/announce.py index 2fc3cb661..b39982701 100644 --- a/announce.py +++ b/announce.py @@ -9,6 +9,8 @@ __email__ = "bob@libreserver.org" __status__ = "Production" __module_group__ = "ActivityPub" +import os +from utils import text_in_file from utils import get_user_paths from utils import has_object_string_object from utils import has_group_type @@ -482,3 +484,55 @@ def outbox_undo_announce(recent_posts_cache: {}, actor_url, domain, debug) if debug: print('DEBUG: post undo announce via c2s - ' + post_filename) + + +def announce_seen(base_dir: str, nickname: str, domain: str, + message_json: {}) -> bool: + """have the given announce been seen? + """ + if not message_json.get('id'): + return False + if not isinstance(message_json['id'], str): + return False + if not message_json.get('object'): + return False + if not isinstance(message_json['object'], str): + return False + post_url = remove_id_ending(message_json['object']) + post_filename = locate_post(base_dir, nickname, domain, post_url) + if not post_filename: + return False + seen_filename = post_filename + '.seen' + if not os.path.isfile(seen_filename): + return False + announce_id = remove_id_ending(message_json['id']) + if text_in_file(announce_id, seen_filename): + return False + return True + + +def mark_announce_as_seen(base_dir: str, nickname: str, domain: str, + message_json: {}) -> None: + """Marks the given announce post as seen + """ + if not message_json.get('id'): + return + if not isinstance(message_json['id'], str): + return + if not message_json.get('object'): + return + if not isinstance(message_json['object'], str): + return + post_url = remove_id_ending(message_json['object']) + post_filename = locate_post(base_dir, nickname, domain, post_url) + if not post_filename: + return + seen_filename = post_filename + '.seen' + if os.path.isfile(seen_filename): + return + announce_id = remove_id_ending(message_json['id']) + try: + with open(seen_filename, 'w+', encoding='utf-8') as fp_seen: + fp_seen.write(announce_id) + except OSError: + print('EX: mark_announce_as_seen unable to write ' + seen_filename) diff --git a/daemon_post_profile.py b/daemon_post_profile.py index d2499256d..65174c3c7 100644 --- a/daemon_post_profile.py +++ b/daemon_post_profile.py @@ -839,6 +839,35 @@ def _profile_post_no_reply_boosts(base_dir: str, nickname: str, domain: str, no_reply_boosts_filename) +def _profile_post_no_seen_posts(base_dir: str, nickname: str, domain: str, + fields: {}) -> bool: + """ HTTP POST disallow seen posts in timelines + """ + no_seen_posts_filename = \ + acct_dir(base_dir, nickname, domain) + '/.noSeenPosts' + no_seen_posts = False + if fields.get('noSeenPosts'): + if fields['noSeenPosts'] == 'on': + no_seen_posts = True + if no_seen_posts: + if not os.path.isfile(no_seen_posts_filename): + try: + with open(no_seen_posts_filename, 'w+', + encoding='utf-8') as fp_seen: + fp_seen.write('\n') + except OSError: + print('EX: unable to write noSeenPosts ' + + no_seen_posts_filename) + if not no_seen_posts: + if os.path.isfile(no_seen_posts_filename): + try: + os.remove(no_seen_posts_filename) + except OSError: + print('EX: _profile_edit ' + + 'unable to delete ' + + no_seen_posts_filename) + + def _profile_post_hide_follows(base_dir: str, nickname: str, domain: str, actor_json: {}, fields: {}, self, actor_changed: bool, @@ -2991,6 +3020,8 @@ def profile_edit(self, calling_domain: str, cookie: str, _profile_post_block_military(nickname, fields, self) _profile_post_no_reply_boosts(base_dir, nickname, domain, fields) + _profile_post_no_seen_posts(base_dir, nickname, domain, + fields) notify_likes_filename = \ acct_dir(base_dir, nickname, domain) + '/.notifyLikes' diff --git a/translations/ar.json b/translations/ar.json index 37e02d505..91f8d3dc6 100644 --- a/translations/ar.json +++ b/translations/ar.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "أرسل هذه الرسالة المباشرة، نعم أم لا؟", "Abandoning new direct message": "التخلي عن الرسالة المباشرة الجديدة", "Press Enter to continue": "إضغط مفتاح الدخول للاستمرار", - "PGP Public Key": "مفتاح PGP العام" + "PGP Public Key": "مفتاح PGP العام", + "Don't show already seen posts": "لا تظهر المشاركات التي تمت مشاهدتها بالفعل" } diff --git a/translations/bn.json b/translations/bn.json index d36b484dc..14b2f6cc2 100644 --- a/translations/bn.json +++ b/translations/bn.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "এই সরাসরি বার্তা পাঠান, হ্যাঁ বা না?", "Abandoning new direct message": "নতুন সরাসরি বার্তা পরিত্যাগ", "Press Enter to continue": "চালিয়ে যেতে এন্টার টিপুন", - "PGP Public Key": "PGP পাবলিক কী" + "PGP Public Key": "PGP পাবলিক কী", + "Don't show already seen posts": "ইতিমধ্যে দেখা পোস্ট দেখাবেন না" } diff --git a/translations/ca.json b/translations/ca.json index ed5e1c184..1b15e90f2 100644 --- a/translations/ca.json +++ b/translations/ca.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "Enviar aquest missatge directe, sí o no?", "Abandoning new direct message": "S'abandona el nou missatge directe", "Press Enter to continue": "Premeu Intro per continuar", - "PGP Public Key": "Clau pública PGP" + "PGP Public Key": "Clau pública PGP", + "Don't show already seen posts": "No mostris les publicacions ja vistes" } diff --git a/translations/cy.json b/translations/cy.json index af79b6868..611690b8d 100644 --- a/translations/cy.json +++ b/translations/cy.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "Anfonwch y neges uniongyrchol hon, ie neu na?", "Abandoning new direct message": "Rhoi'r gorau i neges uniongyrchol newydd", "Press Enter to continue": "Pwyswch Enter i barhau", - "PGP Public Key": "Allwedd Gyhoeddus PGP" + "PGP Public Key": "Allwedd Gyhoeddus PGP", + "Don't show already seen posts": "Peidiwch â dangos postiadau a welwyd eisoes" } diff --git a/translations/de.json b/translations/de.json index 84a184b0a..84d81cf86 100644 --- a/translations/de.json +++ b/translations/de.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "Diese Direktnachricht senden, ja oder nein?", "Abandoning new direct message": "Neue Direktnachricht abbrechen", "Press Enter to continue": "Drücken Sie die Eingabetaste, um fortzufahren", - "PGP Public Key": "Öffentlicher PGP-Schlüssel" + "PGP Public Key": "Öffentlicher PGP-Schlüssel", + "Don't show already seen posts": "Bereits gesehene Beiträge nicht anzeigen" } diff --git a/translations/el.json b/translations/el.json index 3455b8f27..864c2a524 100644 --- a/translations/el.json +++ b/translations/el.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "Στείλτε αυτό το άμεσο μήνυμα, ναι ή όχι;", "Abandoning new direct message": "Εγκατάλειψη νέου άμεσου μηνύματος", "Press Enter to continue": "Πατήστε Enter για να συνεχίσετε", - "PGP Public Key": "Δημόσιο κλειδί PGP" + "PGP Public Key": "Δημόσιο κλειδί PGP", + "Don't show already seen posts": "Να μην εμφανίζονται οι αναρτήσεις που έχετε ήδη δει" } diff --git a/translations/en.json b/translations/en.json index bb10933dc..40718185b 100644 --- a/translations/en.json +++ b/translations/en.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "Send this direct message, yes or no?", "Abandoning new direct message": "Abandoning new direct message", "Press Enter to continue": "Press Enter to continue", - "PGP Public Key": "PGP Public Key" + "PGP Public Key": "PGP Public Key", + "Don't show already seen posts": "Don't show already seen posts" } diff --git a/translations/es.json b/translations/es.json index 7933861b1..986f3595a 100644 --- a/translations/es.json +++ b/translations/es.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "Envía este mensaje directo, ¿sí o no?", "Abandoning new direct message": "Abandonar nuevo mensaje directo", "Press Enter to continue": "Presione Entrar para continuar", - "PGP Public Key": "Clave pública PGP" + "PGP Public Key": "Clave pública PGP", + "Don't show already seen posts": "No mostrar publicaciones ya vistas" } diff --git a/translations/fa.json b/translations/fa.json index e39780205..08dd58371 100644 --- a/translations/fa.json +++ b/translations/fa.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "این پیام مستقیم را ارسال کنید، بله یا خیر؟", "Abandoning new direct message": "رها کردن پیام مستقیم جدید", "Press Enter to continue": "برای ادامه Enter را فشار دهید", - "PGP Public Key": "کلید عمومی PGP" + "PGP Public Key": "کلید عمومی PGP", + "Don't show already seen posts": "پست های قبلا دیده شده را نشان ندهید" } diff --git a/translations/fi.json b/translations/fi.json index 3c0c0da2d..2cb2acf5e 100644 --- a/translations/fi.json +++ b/translations/fi.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "Lähetä tämä suora viesti, kyllä vai ei?", "Abandoning new direct message": "Uuden suoran viestin hylkääminen", "Press Enter to continue": "Jatka painamalla Enter", - "PGP Public Key": "PGP julkinen avain" + "PGP Public Key": "PGP julkinen avain", + "Don't show already seen posts": "Älä näytä jo nähtyjä viestejä" } diff --git a/translations/fr.json b/translations/fr.json index e08f80841..a80b5a77c 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "Envoyer ce message direct, oui ou non ?", "Abandoning new direct message": "Abandonner un nouveau message direct", "Press Enter to continue": "Appuyez sur Entrée pour continuer", - "PGP Public Key": "Clé publique PGP" + "PGP Public Key": "Clé publique PGP", + "Don't show already seen posts": "Ne pas afficher les messages déjà vus" } diff --git a/translations/ga.json b/translations/ga.json index 68414f78c..38bc91ddd 100644 --- a/translations/ga.json +++ b/translations/ga.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "Seol an teachtaireacht dhíreach seo, tá nó níl?", "Abandoning new direct message": "Teachtaireacht dhíreach nua a thréigean", "Press Enter to continue": "Brúigh Enter chun leanúint ar aghaidh", - "PGP Public Key": "Eochair Phoiblí PGP" + "PGP Public Key": "Eochair Phoiblí PGP", + "Don't show already seen posts": "Ná taispeáin postálacha atá feicthe cheana féin" } diff --git a/translations/he.json b/translations/he.json index e3524f5bd..d4694bd12 100644 --- a/translations/he.json +++ b/translations/he.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "לשלוח הודעה ישירה זו, כן או לא?", "Abandoning new direct message": "נטישת הודעה ישירה חדשה", "Press Enter to continue": "לחץ על Enter כדי להמשיך", - "PGP Public Key": "מפתח PGP ציבורי" + "PGP Public Key": "מפתח PGP ציבורי", + "Don't show already seen posts": "אל תראה פוסטים שכבר נראו" } diff --git a/translations/hi.json b/translations/hi.json index d1d6049b1..c5f04c607 100644 --- a/translations/hi.json +++ b/translations/hi.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "यह सीधा संदेश भेजें, हाँ या नहीं?", "Abandoning new direct message": "नए प्रत्यक्ष संदेश का परित्याग", "Press Enter to continue": "जारी रखने के लिए Enter दबाएँ", - "PGP Public Key": "पीजीपी सार्वजनिक कुंजी" + "PGP Public Key": "पीजीपी सार्वजनिक कुंजी", + "Don't show already seen posts": "पहले से देखी गई पोस्ट न दिखाएं" } diff --git a/translations/it.json b/translations/it.json index 12fc7fe69..bfbeff209 100644 --- a/translations/it.json +++ b/translations/it.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "Invia questo messaggio diretto, sì o no?", "Abandoning new direct message": "Abbandonare il nuovo messaggio diretto", "Press Enter to continue": "Premere Invio per continuare", - "PGP Public Key": "Chiave pubblica PGP" + "PGP Public Key": "Chiave pubblica PGP", + "Don't show already seen posts": "Non mostrare i post già visti" } diff --git a/translations/ja.json b/translations/ja.json index f11ae21c5..00cdad9d3 100644 --- a/translations/ja.json +++ b/translations/ja.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "このダイレクト メッセージを送信します。はい、いいえ?", "Abandoning new direct message": "新しいダイレクトメッセージの放棄", "Press Enter to continue": "続行するには Enter キーを押してください", - "PGP Public Key": "PGP公開鍵" + "PGP Public Key": "PGP公開鍵", + "Don't show already seen posts": "すでに閲覧した投稿を表示しない" } diff --git a/translations/ko.json b/translations/ko.json index b7b4a846b..ef2b64062 100644 --- a/translations/ko.json +++ b/translations/ko.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "이 다이렉트 메시지를 보내세요, 예 아니면 아니오?", "Abandoning new direct message": "새 다이렉트 메시지 포기하기", "Press Enter to continue": "계속하려면 Enter를 누르세요.", - "PGP Public Key": "PGP 공개 키" + "PGP Public Key": "PGP 공개 키", + "Don't show already seen posts": "이미 본 게시물을 표시하지 않음" } diff --git a/translations/ku.json b/translations/ku.json index c66b0c684..426bfb54f 100644 --- a/translations/ku.json +++ b/translations/ku.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "Vê peyama rasterast bişînin, erê an na?", "Abandoning new direct message": "Rakirina peyama rasterast a nû", "Press Enter to continue": "Ji bo berdewamkirinê Enter bikirtînin", - "PGP Public Key": "Mifteya Giştî ya PGP" + "PGP Public Key": "Mifteya Giştî ya PGP", + "Don't show already seen posts": "Mesajên ku berê hatine dîtin nîşan nedin" } diff --git a/translations/nl.json b/translations/nl.json index ed7c61777..22c107632 100644 --- a/translations/nl.json +++ b/translations/nl.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "Dit directe bericht versturen, ja of nee?", "Abandoning new direct message": "Nieuw privéchat verlaten", "Press Enter to continue": "Druk op Enter om door te gaan", - "PGP Public Key": "PGP publieke sleutel" + "PGP Public Key": "PGP publieke sleutel", + "Don't show already seen posts": "Toon geen reeds bekeken berichten" } diff --git a/translations/oc.json b/translations/oc.json index b0dd00581..d45d3756e 100644 --- a/translations/oc.json +++ b/translations/oc.json @@ -689,5 +689,6 @@ "Send this direct message, yes or no?": "Send this direct message, yes or no?", "Abandoning new direct message": "Abandoning new direct message", "Press Enter to continue": "Press Enter to continue", - "PGP Public Key": "PGP Public Key" + "PGP Public Key": "PGP Public Key", + "Don't show already seen posts": "Don't show already seen posts" } diff --git a/translations/pl.json b/translations/pl.json index 8b143e950..0577da9a8 100644 --- a/translations/pl.json +++ b/translations/pl.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "Wysłać tę bezpośrednią wiadomość, tak czy nie?", "Abandoning new direct message": "Porzucenie nowej wiadomości bezpośredniej", "Press Enter to continue": "Naciśnij Enter, aby kontynuować", - "PGP Public Key": "Klucz publiczny PGP" + "PGP Public Key": "Klucz publiczny PGP", + "Don't show already seen posts": "Nie pokazuj już wyświetlonych postów" } diff --git a/translations/pt.json b/translations/pt.json index 4895697ea..018872c44 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "Envie esta mensagem direta, sim ou não?", "Abandoning new direct message": "Abandonando nova mensagem direta", "Press Enter to continue": "Pressione Enter para continuar", - "PGP Public Key": "Chave pública PGP" + "PGP Public Key": "Chave pública PGP", + "Don't show already seen posts": "Não mostrar posts já vistos" } diff --git a/translations/ru.json b/translations/ru.json index a185c6cf9..d9a18767b 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "Отправить это прямое сообщение, да или нет?", "Abandoning new direct message": "Отказ от нового прямого сообщения", "Press Enter to continue": "Нажмите Enter, чтобы продолжить", - "PGP Public Key": "Открытый ключ PGP" + "PGP Public Key": "Открытый ключ PGP", + "Don't show already seen posts": "Не показывать уже просмотренные публикации" } diff --git a/translations/sw.json b/translations/sw.json index 2391b3ea9..99217d75b 100644 --- a/translations/sw.json +++ b/translations/sw.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "Tuma ujumbe huu wa moja kwa moja, ndiyo au hapana?", "Abandoning new direct message": "Kuacha ujumbe mpya wa moja kwa moja", "Press Enter to continue": "Bonyeza Enter ili kuendelea", - "PGP Public Key": "Ufunguo wa Umma wa PGP" + "PGP Public Key": "Ufunguo wa Umma wa PGP", + "Don't show already seen posts": "Usionyeshe machapisho ambayo tayari yameonekana" } diff --git a/translations/tr.json b/translations/tr.json index e2baa2e58..462153a17 100644 --- a/translations/tr.json +++ b/translations/tr.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "Bu doğrudan mesajı gönder, evet mi hayır mı?", "Abandoning new direct message": "Yeni doğrudan mesajdan vazgeçiliyor", "Press Enter to continue": "Devam etmek için Enter'a basın", - "PGP Public Key": "PGP Genel Anahtarı" + "PGP Public Key": "PGP Genel Anahtarı", + "Don't show already seen posts": "Daha önce görülen gönderileri gösterme" } diff --git a/translations/uk.json b/translations/uk.json index 9f73a3809..76000cf0c 100644 --- a/translations/uk.json +++ b/translations/uk.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "Надіслати це пряме повідомлення, так чи ні?", "Abandoning new direct message": "Відмова від нового прямого повідомлення", "Press Enter to continue": "Натисніть Enter, щоб продовжити", - "PGP Public Key": "Відкритий ключ PGP" + "PGP Public Key": "Відкритий ключ PGP", + "Don't show already seen posts": "Не показувати вже переглянуті публікації" } diff --git a/translations/yi.json b/translations/yi.json index a09c0f0ea..4bf3f29c6 100644 --- a/translations/yi.json +++ b/translations/yi.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "שיקן דעם דירעקט אָנזאָג, יאָ אָדער ניט?", "Abandoning new direct message": "פארלאזן נייַ דירעקט אָנזאָג", "Press Enter to continue": "דרוק אַרייַן צו פאָרזעצן", - "PGP Public Key": "PGP ציבור שליסל" + "PGP Public Key": "PGP ציבור שליסל", + "Don't show already seen posts": "צי ניט ווייַזן שוין געזען אַרטיקלען" } diff --git a/translations/zh.json b/translations/zh.json index 89a2bdd9d..66ae99fc7 100644 --- a/translations/zh.json +++ b/translations/zh.json @@ -693,5 +693,6 @@ "Send this direct message, yes or no?": "发送此直接消息,是还是否?", "Abandoning new direct message": "放弃新的私信", "Press Enter to continue": "按 Enter 继续", - "PGP Public Key": "PGP 公钥" + "PGP Public Key": "PGP 公钥", + "Don't show already seen posts": "不显示已经看过的帖子" } diff --git a/utils.py b/utils.py index df7f74c6c..5885c2b59 100644 --- a/utils.py +++ b/utils.py @@ -2785,7 +2785,7 @@ def delete_post(base_dir: str, http_prefix: str, _remove_attachment(base_dir, http_prefix, domain, post_json_object) extensions = ( - 'votes', 'arrived', 'muted', 'tts', 'reject', 'mitm', 'edits' + 'votes', 'arrived', 'muted', 'tts', 'reject', 'mitm', 'edits', 'seen' ) for ext in extensions: ext_filename = post_filename + '.' + ext diff --git a/webapp_profile.py b/webapp_profile.py index 42cf7dffe..64add3f0b 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -2813,7 +2813,8 @@ def _html_edit_profile_options(is_admin: bool, show_replies_mutuals: bool, hide_follows: bool, premium: bool, - no_reply_boosts: bool) -> str: + no_reply_boosts: bool, + no_seen_posts: bool) -> str: """option checkboxes section of edit profile screen """ edit_profile_form = '