Option to not repeatedly see the same posts being announced

main
Bob Mottram 2024-07-16 15:51:04 +01:00
parent a89a3211a1
commit 98f09c85e9
33 changed files with 167 additions and 31 deletions

View File

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

View File

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

View File

@ -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": "لا تظهر المشاركات التي تمت مشاهدتها بالفعل"
}

View File

@ -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": "ইতিমধ্যে দেখা পোস্ট দেখাবেন না"
}

View File

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

View File

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

View File

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

View File

@ -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": "Να μην εμφανίζονται οι αναρτήσεις που έχετε ήδη δει"
}

View File

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

View File

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

View File

@ -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": "پست های قبلا دیده شده را نشان ندهید"
}

View File

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

View File

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

View File

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

View File

@ -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": "אל תראה פוסטים שכבר נראו"
}

View File

@ -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": "पहले से देखी गई पोस्ट न दिखाएं"
}

View File

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

View File

@ -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": "すでに閲覧した投稿を表示しない"
}

View File

@ -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": "이미 본 게시물을 표시하지 않음"
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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": "Не показывать уже просмотренные публикации"
}

View File

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

View File

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

View File

@ -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": "Не показувати вже переглянуті публікації"
}

View File

@ -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": "צי ניט ווייַזן שוין געזען אַרטיקלען"
}

View File

@ -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": "不显示已经看过的帖子"
}

View File

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

View File

@ -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 = ' <div class="container">\n'
@ -2903,6 +2904,10 @@ def _html_edit_profile_options(is_admin: bool,
edit_profile_form += \
edit_check_box(no_reply_boosts_str, 'noReplyBoosts', no_reply_boosts)
no_seen_posts_str = translate["Don't show already seen posts"]
edit_profile_form += \
edit_check_box(no_seen_posts_str, 'noSeenPosts', no_seen_posts)
edit_profile_form += ' </div>\n'
return edit_profile_form
@ -3324,6 +3329,12 @@ def html_edit_profile(server, translate: {},
if os.path.isfile(no_reply_boosts_filename):
no_reply_boosts = True
# are seen posts permitted in timelines?
no_seen_posts_filename = account_dir + '/.noSeenPosts'
no_seen_posts = False
if os.path.isfile(no_seen_posts_filename):
no_seen_posts = True
# Option checkboxes
edit_profile_form += \
_html_edit_profile_options(is_admin, manually_approves_followers,
@ -3337,7 +3348,8 @@ def html_edit_profile(server, translate: {},
reverse_sequence, show_quote_toots,
show_vote_posts, show_replies_followers,
show_replies_mutuals, hide_follows,
premium, no_reply_boosts)
premium, no_reply_boosts,
no_seen_posts)
# Contact information
edit_profile_form += \

View File

@ -40,6 +40,8 @@ from webapp_column_left import get_left_column_content
from webapp_column_right import get_right_column_content
from webapp_headerbuttons import header_buttons_timeline
from posts import is_moderator
from announce import mark_announce_as_seen
from announce import announce_seen
from announce import is_announce
from announce import is_self_announce
from question import is_html_question
@ -1018,6 +1020,11 @@ def html_timeline(default_timeline: str,
if nickname in min_images_for_accounts:
minimize_all_images = True
no_seen_posts_filename = account_dir + '/.noSeenPosts'
no_seen_posts = False
if os.path.isfile(no_seen_posts_filename):
no_seen_posts = True
# show each post in the timeline
tl_items_str = ''
for item in timeline_json['orderedItems']:
@ -1031,6 +1038,10 @@ def html_timeline(default_timeline: str,
continue
if is_self_announce(item):
continue
if no_seen_posts:
if announce_seen(base_dir, nickname, domain, item):
continue
mark_announce_as_seen(base_dir, nickname, domain, item)
# is this a poll/vote/question?
if not show_vote_posts:
if is_question(item):